Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Wed Dec 11, 2013 11:35 pm UTC

GCC has been calmer today.
All is well.*

heatsink wrote:As to the latter question, the problem is that templates are untyped (i.e., any type is permissible as any template argument), so there is no way to summarize why an error occurred.

Honestly, I have this problem in code too, not just error messages.
Nested STL data structures just give me headaches.

*excluding the random segfaults. That sucked.
Image

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Thu Dec 12, 2013 3:24 am UTC

I want a replacement for SQL. It should be more like a scripting language, and top down. Something like this:

Code: Select all

set(a, b, c) Query = MySchema.Table1 (a, b, c) : a == 5; //sets are variables containing data sets

//A copy/alias of a column
Query.Foo = a;

//an inline function defining a column, a is still a valid identifier
Query.Greatest  = {
   if (a > b)
      this = a;
   else
      this = b;
}
//aggregate initialized to 0, called for every row
Query.RowCount = 0 : foreach() {
   this += 1;
}
//also should be able to use built in aggregate functions Query.RowCount = count()

//aggregate initialized to 0 on first non-null value of c, called for every non-null value of c, of course you could probably still define a built in sum function
Query.Total(c) = 0 : foreach(c) {
   this += c;
}

Query.TotalLessThan10(c) = 0 : foreach(c<10) { //aggregate initialized to 0 on first non-null value of c < 10, called for every non-null value of C < 10
   this += c;
}


//now let's get our results, up to this point there should be absolutely no work done:

select Query.GroupBy(Greatest) (RowCount, Total);


This is equivalent to the following:

Code: Select all

SELECT Greatest,
   COUNT(*) RowCount,
   SUM(c) AS Greatest,
   SUM(CASE WHEN C < 10 THEN C END) AS GreatestLessThan10
FROM (
   SELECT CASE WHEN a > b THEN a ELSE b END AS Greatest, c
   FROM MySchema.Table1
   WHERE a = 5

) AS Query


This case is trivial, but when you have large queries, SQL gets fucking messy. By defining the underlying data for your result set first you make on-the-fly error checking/code completion much easier. By allowing columns to reference earlier columns, you don't have to do several nested derived tables or a lot of copy/paste code. Should be dynamically/duck typed to allow you to conditionally select from different tables.

I would like it to be file-based instead of part of the database schema, allow include files and inline functions taking/returning values or data sets, etc. Instead of altering the database one procedure at a time, a set of scripts would be defined as an application. When you have copied all the files for your deploy, you run a command on the server to reload the application.
Summum ius, summa iniuria.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Thu Dec 12, 2013 2:41 pm UTC

Concepts lite was removed from C++1y? Because that is a pretty good success.

There where failures before that, admittedly. So I guess they "tried and failed" to generate better error messages.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Dec 12, 2013 7:03 pm UTC

OK, quick survey. Hopefully this question isn't too vague.

Suppose you have a C API function that writes a set of things to an array passed in as a parameter. It does the pretty typical thing where you pass in the array, the size, and a pointer that receives the number of bytes that are needed to store all the elements (in case your array wasn't big enough). It is possible to pass in NULL for the array to just get the needed size. So you'd use such function along the lines of:

Code: Select all

size_t bytes_needed;
Thing * things = NULL;
get_things(NULL, 0, &bytes_needed);
things = malloc(bytes_needed);
get_things(things, bytes_needed, &bytes_needed);


Now the question: suppose this is a public API but there's no source. Generated documentation is provided. How important is it to mention explicitly that the "pass NULL and 0 to get the total size needed" idiom is supported, or would that just be expected?

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Thu Dec 12, 2013 7:08 pm UTC

Personally, I would check the header for comments first, then check documentation if there are no comments, then if I still couldn't find anything for sure I would test it. Granted it is probably faster to just test it, but I definitely don't assume anyone uses a specific convention when coding in C.
Summum ius, summa iniuria.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Thu Dec 12, 2013 10:30 pm UTC

I also think it's very important; if the header or documentation don't mention that I'd assume that the function doesn't provide this functionality.

-----

Yeah, I added module support to my programming language project so I can finally start doing something useful. I decided to use ?x for lambda binding and not Haskells \x because I think ? looks a bit nicer.

Code: Select all

global projectEuler1 = intFold 1000 Int 0
   ?z:Int => ?k:Int =>
      z + if (intMod k 3) == 0 || (intMod k 5) == 0
         then k else 0;

Any comments on the syntax? Does it look nice or ugly? I'm not sure whether => is a good choice to delimit argument types from expressions. I'm considering replacing that with :: but that introduces so many colons into the code.

In this code Int, intFold and intMod are not language constructs but are imported from the standard library. intFold has signature Int -> Type T -> T initial -> (T value -> Int num -> T) -> T, i.e. it is polymorphic in type T. At the moment the polymorphic type has to be passed explicitly to the function, which is redundant and ugly. I will add type inference for type parameters later. The required unificator code is already working but I didn't merge it into the compiler yet.

intMod will be replaced by infix % once I have type-based function/operator overloading working.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Thu Dec 12, 2013 10:58 pm UTC

EvanED wrote:Now the question: suppose this is a public API but there's no source. Generated documentation is provided. How important is it to mention explicitly that the "pass NULL and 0 to get the total size needed" idiom is supported, or would that just be expected?

I am not a C programmer, but I wouldn't pass a null pointer to an API function unless there was something explicitly telling me I could.
Image

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Fri Dec 13, 2013 6:18 am UTC

Thesh wrote:I want a replacement for SQL. It should be more like a scripting language, and top down. Something like this:

Code: Select all

set(a, b, c) Query = MySchema.Table1 (a, b, c) : a == 5; //sets are variables containing data sets

//A copy/alias of a column
Query.Foo = a;

//an inline function defining a column, a is still a valid identifier
Query.Greatest  = {
   if (a > b)
      this = a;
   else
      this = b;
}
//aggregate initialized to 0, called for every row
Query.RowCount = 0 : foreach() {
   this += 1;
}
//also should be able to use built in aggregate functions Query.RowCount = count()

//aggregate initialized to 0 on first non-null value of c, called for every non-null value of c, of course you could probably still define a built in sum function
Query.Total(c) = 0 : foreach(c) {
   this += c;
}

Query.TotalLessThan10(c) = 0 : foreach(c<10) { //aggregate initialized to 0 on first non-null value of c < 10, called for every non-null value of C < 10
   this += c;
}


//now let's get our results, up to this point there should be absolutely no work done:

select Query.GroupBy(Greatest) (RowCount, Total);


This is equivalent to the following:

Code: Select all

SELECT Greatest,
   COUNT(*) RowCount,
   SUM(c) AS Greatest,
   SUM(CASE WHEN C < 10 THEN C END) AS GreatestLessThan10
FROM (
   SELECT CASE WHEN a > b THEN a ELSE b END AS Greatest, c
   FROM MySchema.Table1
   WHERE a = 5

) AS Query


This case is trivial, but when you have large queries, SQL gets fucking messy. By defining the underlying data for your result set first you make on-the-fly error checking/code completion much easier. By allowing columns to reference earlier columns, you don't have to do several nested derived tables or a lot of copy/paste code. Should be dynamically/duck typed to allow you to conditionally select from different tables.

I would like it to be file-based instead of part of the database schema, allow include files and inline functions taking/returning values or data sets, etc. Instead of altering the database one procedure at a time, a set of scripts would be defined as an application. When you have copied all the files for your deploy, you run a command on the server to reload the application.


You are describing a document-based data store like CouchDB. This is essentially how querying such stores works for anything beyond simple key->value lookups - you write a script which emits the results you want.

There are upsides and downsides to this. The upside is that you get a much more programmatic rather than expression-based query system. The downside is that you basically no longer get the benefits of a query planner.

If you are getting to the point where a programmatic system is more valuable to you than a query planner, perhaps it's time to reconsider using a relational database to do your calculations for you.
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Fri Dec 13, 2013 6:34 am UTC

Aaeriele wrote:You are describing a document-based data store like CouchDB. This is essentially how querying such stores works for anything beyond simple key->value lookups - you write a script which emits the results you want.

There are upsides and downsides to this. The upside is that you get a much more programmatic rather than expression-based query system. The downside is that you basically no longer get the benefits of a query planner.


This would still be for relational data, and still would be used with ACID compliant RDBMS, all you are changing is how you write the query. It's still a declarative language; all of the statements except for the very last are simply defining the query itself and not actually querying anything. You would get all the benefits of the query planner, just something easier to read (well, for complex queries) and more flexible.

One of the main reasons I came up with this is actually because of the inefficiencies of SQL; you can't dynamically build a query in a clean way (you have to build the statement as a string and call exec; blech). It's a common problem; how to have multiple queries depending on different parameter. Let's say you want to search by phone number or address or last name - you can either have a separate query for each combination of options, get lists of IDs for data into a temp table and then join to the temp table, or have a bunch of crap in the where clause (which the DBMS will likely choose to use and cache a generic execution plan). The first is going to perform best, but is copy-paste hell, the second is going to perform okay, and the third is going to perform horribly. With a language built around constructing queries as a series of statements, then you can build your query, much like you would if you did exec, but without all the horribleness.

Also, if I did build it, I would also add in a way to do parent-child relationships. Something along these lines:

Code: Select all

Query.Children = MySchema.Table2(b,c,d) : a = Query.a;


Instead of constructing as a giant table, you can choose a more accurate representation of the relationship with no duplicate data or extra queries.
Summum ius, summa iniuria.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Dec 13, 2013 10:38 am UTC

Getting caught out by sign extension sucks.
I hate that char isn't defined to be signed or unsigned.
Image

Dr. Willpower
Posts: 197
Joined: Wed May 28, 2008 3:55 pm UTC

Re: Coding: Fleeting Thoughts

Postby Dr. Willpower » Fri Dec 13, 2013 9:17 pm UTC

Thesh wrote:This would still be for relational data,...


I find this idea really fascinating. All you'd have to do is write a parser that would compile the code into SQL statements. It definitely seems doable at least.
Image
Hat me, bro

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Dec 13, 2013 10:08 pm UTC

I did not know that the std::ifstream would treat 0xA1 as an EOF marker on Windows.
That's two hours I'm not getting back.
Image

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Sat Dec 14, 2013 2:10 am UTC

Dr. Willpower wrote:
Thesh wrote:This would still be for relational data,...


I find this idea really fascinating. All you'd have to do is write a parser that would compile the code into SQL statements. It definitely seems doable at least.


It would be a good proof of concept, but I would love to eventually build it as an extension to PostgreSQL. Unfortunately, I don't have experience in writing interpreters or languages, so the latter part would take me some time to learn first.

I do have a name, however, which is the most important part: QBL (Query Building Language) - Pronounced Cue Ball

EDIT:
After thinking about it for a while, I have come up with join syntax:

Code: Select all

Query = (t1=MySchema.Table1) + (t2=MySchema.Table2) := t1.a = t2.a //INNER JOIN
Query = (t1=MySchema.Table1) + (t2=MySchema.Table2) :> t1.a = t2.a //LEFT OUTER JOIN
Query = (t1=MySchema.Table1) + (t2=MySchema.Table2) :< t1.a = t2.a //RIGHT OUTER JOIN
Query = (t1=MySchema.Table1) + (t2=MySchema.Table2) :<> t1.a = t2.a //FULL OUTER JOIN
Query = (t1=MySchema.Table1) ? (t2=MySchema.Table2) := t1.a = t2.a //SEMI JOIN
Query = (t1=MySchema.Table1) ! (t2=MySchema.Table2) := t1.a = t2.a //ANTI JOIN
//While I'm at it:
Query = MySchema.Table1 ++ MySchema.Table2 //UNION
Query = MySchema.Table1 ?? MySchema.Table2 //INTERSECT
Query = MySchema.Table1 !! MySchema.Table2 //EXCEPT


Example:

Code: Select all

CustomerOrders = (o=Store.Orders) + (l=Store.LineItems) := o.OrderID = l.OrderID;
select CustomerOrders(o.OrderID, o.OrderDate, od.SKU, od.Price, od.Quantity) : o.CustomerID = 7;


Alternative:

Code: Select all

select ((o=Store.Orders) + (l=Store.LineItems) := o.OrderID = l.OrderID)
    (o.OrderID, o.OrderDate, od.SKU, od.Price, od.Quantity)
    : o.CustomerID = 7;


Equivalent SQL;

Code: Select all

SELECT o.OrderID, o.OrderDate, od.SKU, od.Price, od.Quantity
FROM Orders o
INNER JOIN LineItems l ON o.OrderID = l.OrderiD
WHERE o.CustomerID = 7;
Summum ius, summa iniuria.

User avatar
PM 2Ring
Posts: 3713
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Sat Dec 14, 2013 7:59 am UTC

Thesh,

I know Python 2 pretty well, but I know next to nothing about SQL. Are either of these related to what you want to do?
https://code.google.com/p/python-sql/
http://www.sqlalchemy.org/

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Sat Dec 14, 2013 3:58 pm UTC

ORMs are a tool on the application side that are built so you don't have to write SQL. What I want is an alternative to SQL that runs on the database server. So you know where I'm coming from, currently my job consists entirely of writing very long, complex database scripts that run directly on SQL Server.
Summum ius, summa iniuria.

User avatar
Sandry
My cheese is pants?
Posts: 1893
Joined: Sun May 13, 2007 3:36 am UTC
Location: Boston area
Contact:

Re: Coding: Fleeting Thoughts

Postby Sandry » Mon Dec 16, 2013 2:55 am UTC

I cannot believe the amount of time I'm spending on the incredibly stupid game of "Find the Null Pointer Exception."

I can't believe I'm trying to solve this problem by stuffing my puzzle house full of teddy bears. I am excruciatingly disappointed that this did not solve my problem.

Perhaps I should have stopped working on this a few hours ago. >_<

Edit: I gave up and just moved the if clause with my win condition ahead of the method call causing the error. Laziness. I haz it. Still leaving the house stuffed with teddy bears, though. Best game ever. :P
He does not spout ever more, new stupidities. He "diversifies his wrongness portfolio."
(My pronouns are She/Her/Hers)

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Mon Dec 16, 2013 3:02 am UTC

I find most of the time you spend debugging is on small things. I just spent about 20 minutes trying to figure out what was wrong with my code; I had "a[256] = { /*stuff*/ };". Well, it turns out I accidentally deleted two lines, 16 elements, from the array. GCC should spit out a warning if you do "a[8] = {1,2,3,4,5,6};"
Summum ius, summa iniuria.

drowdemon
Posts: 3
Joined: Mon Dec 09, 2013 11:45 pm UTC

Re: Coding: Fleeting Thoughts

Postby drowdemon » Mon Dec 16, 2013 3:10 am UTC

Agreed. The worst was when I spent a few hours figuring out that I managed to type a '6' instead of a '9.'

How many years do you will it take for there to be a system that can scan your code and warn you if something looks sufficiently out of place? As in, you use '9's everywhere except for one place. Or the size of your array is 20 but you only loop till 19, and so on and so forth. It shouldn't be too impossible...

User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Mon Dec 16, 2013 3:19 am UTC

Thesh wrote:GCC should spit out a warning if you do "a[8] = {1,2,3,4,5,6};"

Looking at the docs, GCC has -Wmissing-field-initializers which handles this for structs:

Code: Select all

struct s {int a,b,c;};
struct s foo = {1,2}; // raises warning
this warning is included with -Wextra. However, there doesn't seem to be an equivalent for arrays...

I guess if you had an equivalent for arrays, it would cause annoyance with C-strings...

Code: Select all

char buffer[256] = ""; // Warning - incomplete initialiser???
Maybe you could have it be a separate warning for char/wchar_t arrays to other arrays, or something... but still.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Mon Dec 16, 2013 3:30 am UTC

I know I also do int arr[10] = {0}; a fair bit. Though that could be special-cased out I guess; I can't recall a time where I had more literal elements than 1 but less than the size of the array.

You could also do int arr[] = {...}; if you want a complete initialization, perhaps adding a STATIC_ASSERT that the number of elements is what you expect. More verbose if you include the assertion, but if you really want the error checking, that'll get it for you.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Mon Dec 16, 2013 3:41 am UTC

I guess string literals and {0} could both be made as exceptions.
Summum ius, summa iniuria.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Mon Dec 16, 2013 4:26 am UTC

I do int arr[]={...}; static_assert( lengthof(arr)==256, "missimg element from arr!");, or the equivalent.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Diadem
Posts: 5654
Joined: Wed Jun 11, 2008 11:03 am UTC
Location: The Netherlands

Re: Coding: Fleeting Thoughts

Postby Diadem » Wed Dec 18, 2013 9:12 am UTC

At work there is this 1600 line method sitting in our code, being all "Puny human, I'm the god of all functions, refactor me, if you dare", and I kind of have to admit that I don't dare. How the hell do you even begin refactoring something like that?

I kind of wonder where it came from. Surely no mortal could have created that. Perhaps it always was there?
It's one of those irregular verbs, isn't it? I have an independent mind, you are an eccentric, he is round the twist
- Bernard Woolley in Yes, Prime Minister

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Wed Dec 18, 2013 9:22 am UTC

What does it do?
Sometimes long functions make sense but 1600 lines is a bit too long :shock:

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Dec 18, 2013 11:41 am UTC

You start with lambdas. A block of flow control free code can be surrounded with [&](){code}(); with few side effects.

Then make the capture list explicit. Then convert to arguments. Then move to its own function.

It is not perfect, but is incremental.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Xanthir
My HERO!!!
Posts: 5413
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Wed Dec 18, 2013 11:42 pm UTC

Incremental *and* effective. Moving things to functions is good practice anyway, and it gradually shrinks the core function, folding large chunks of code into well-named single-line descriptions of what they do. As this progresses, it becomes easier to hold the function in your head, and thus *real* refactoring becomes easier.

I do this with my specs all the time, too. English is very amenable to this kind of thing if you're doing technical writing.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

heatsink
Posts: 86
Joined: Fri Jun 30, 2006 8:58 am UTC

Re: Coding: Fleeting Thoughts

Postby heatsink » Thu Dec 19, 2013 12:52 pm UTC

Decomposing the code into functions is a way to start, but before that, you'll want to reverse engineer a specification for some part of the code. The process is helpful for identifying what groups of code should be moved into functions.

It's a weird feeling when you need to write function, so you assemble a term that has the right type, and it does what it's supposed to, but you don't know how the code works.

User avatar
Diadem
Posts: 5654
Joined: Wed Jun 11, 2008 11:03 am UTC
Location: The Netherlands

Re: Coding: Fleeting Thoughts

Postby Diadem » Thu Dec 19, 2013 1:29 pm UTC

Yeah I know separating the code into functions is the way forward. It's a hard and slow process though, and 1600 lines is just daunting. It's not like that's the only messy part of the code either.
It's one of those irregular verbs, isn't it? I have an independent mind, you are an eccentric, he is round the twist
- Bernard Woolley in Yes, Prime Minister

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Thu Dec 19, 2013 2:54 pm UTC

Sure you need to guess what chuncks to wrap up. But the process above is non destructive: the code remains unchanged. And you learn what the dependencies and outputs of each chunk are by doing it. If you have live parsing, use it: otherwise set up a script to recompile the code in a tight loop and show you the first few errors in a visible window.

The restriction to flow control free makes your decision more constrained. You can, with work, get around it: return flow control instructions from the lambda, then use them outside. But the first step will, in my experience, really help to get things under control.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Thu Dec 19, 2013 9:44 pm UTC

Yay, found a new bug in Visual Studio's Regex Engine:

Code: Select all

test
t.test


Find <t> replace with u, result will be:

Code: Select all

test
u.test


This is the correct behavior. Now, repeat the test but instead highlight the text and use the option to only look in the selection, result will be:

Code: Select all

tesu
u.tesu
Summum ius, summa iniuria.

lgw
Posts: 437
Joined: Mon Apr 12, 2010 10:52 pm UTC

Re: Coding: Fleeting Thoughts

Postby lgw » Fri Dec 20, 2013 12:10 am UTC

Diadem wrote:Yeah I know separating the code into functions is the way forward. It's a hard and slow process though, and 1600 lines is just daunting. It's not like that's the only messy part of the code either.


I hate to break it to you, but that's standard fare for legacy code, especially Java for some reason. The last code base I had to live with was crawling with 10000 line classes. Rumor has it that the money-processing logic at PayPal is all in a single class that has become so big that finding an editor that can open it without crashing is a challenge, and there was at least one formally funded project to fix that that failed.

My own rant:

Today I'm posting to avoid facing maintaining code where the original developer thought it clever to use "l" as a variable name all over the place, and the jerk doesn't even have the decency to be doing it as deliberate job-security obfuscation - no, he honestly sees no problem with the practice. Well, at least he's not also in the habit of using "o". Yet. And all the comments throughout the codebase are content-free clutter auto-generated by some editor macro. At least when there are no comments you know where you stand, and over time you know any comment is your own analysis, but this is just distracting as I keep expecting the comment to explain something. :evil:
"In no set of physics laws do you get two cats." - doogly

User avatar
b.i.o
Green is the loneliest number
Posts: 2519
Joined: Fri Jul 27, 2007 4:38 pm UTC
Location: Hong Kong

Re: Coding: Fleeting Thoughts

Postby b.i.o » Fri Dec 20, 2013 11:34 am UTC

lgw wrote:Rumor has it that the money-processing logic at PayPal is all in a single class that has become so big that finding an editor that can open it without crashing is a challenge, and there was at least one formally funded project to fix that that failed.

I find this pretty hard to believe...I have files with ~10M lines open in vim on a semi-regular basis. It's certainly slow and unpleasant, but not impossible. If true, maybe it was quite a while ago and on much older hardware?

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Fri Dec 20, 2013 4:09 pm UTC

It is Java code. What are the odds that by "editor" they mean "ide written in Java"? ;)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

chris857
Posts: 100
Joined: Thu Dec 02, 2010 5:04 pm UTC

Re: Coding: Fleeting Thoughts

Postby chris857 » Mon Dec 30, 2013 3:46 am UTC

Diadem wrote:At work there is this 1600 line method sitting in our code, being all "Puny human, I'm the god of all functions, refactor me, if you dare", and I kind of have to admit that I don't dare. How the hell do you even begin refactoring something like that?

I kind of wonder where it came from. Surely no mortal could have created that. Perhaps it always was there?


At the company I recently interned at, there was a 3000 line C++ method. I think it was called RunPrivate(). It did some IR computation (part of a thermal modeling program). All you could hope for is to refactor small portions. I tracked down at least one bug while I was there, and added a least one feature.

troyp
Posts: 557
Joined: Thu May 22, 2008 9:20 pm UTC
Location: Lismore, NSW

Re: Coding: Fleeting Thoughts

Postby troyp » Mon Dec 30, 2013 9:41 am UTC

People who code with a dark theme, do you like light on dark for other things?

For code, I'm comfortable with light or dark themes, although I prefer the latter. For reading prose, though, I have a distinct aversion to light-on-dark text. I find it harder to read.

I'm not sure why there's such a difference. (Syntax highlighting is an obvious hypothesis, but I still like dark themes in a monochrome terminal so that can't be it). Maybe dark themes lend themselves to a less linear interaction with the text? Or maybe my experience of light-on-dark prose has been forever tainted by horrible '90s websites?

Ubik
Posts: 1016
Joined: Thu Oct 18, 2007 3:43 pm UTC

Re: Coding: Fleeting Thoughts

Postby Ubik » Mon Dec 30, 2013 10:51 am UTC

It might be related to the amount of stuff on screen at once. With prose, the text forms a roughly rectangular block of relatively bright light on otherwise dark background, but in the case of code there's usually a lot more empty around it, so it's less bright on average.

With monochrome terminal the brightness and contrast were probably somewhat adjusted for the use, as opposed to the full-color web use where that part has been given to the content creators. And yes, I think all the cases of those #f00/#0f0/#00f on #000 pages with otherwise bad typography too probably have ruined the idea of light text on dark background for you. Less contrast (so that neither the dark or the light color would stay at the extreme end of brightness scale) could do wonders to readability.

User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Mon Dec 30, 2013 11:19 am UTC

I'm weird for this... A light-background terminal just looks wrong to me, I can't use it, but I prefer using a light background in my text editor, a dark background just doesn't do it for me. The end result being that if I'm coding in Sublime it's dark-on-light, but if I'm coding in vim it's light-on-dark, and both of those look "right" to me...

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Dec 30, 2013 12:15 pm UTC

troyp wrote:For code, I'm comfortable with light or dark themes, although I prefer the latter. For reading prose, though, I have a distinct aversion to light-on-dark text. I find it harder to read.

I remember seeing a study that basically concluded "Dark-on-Light is strictly better for reading", but I cannot remember where.

At my last job, I used Dark-on-Light, I find VB harder to read using Light-on-Dark; too much text. Similarly, HTML and XML are even worse with Light-on-Dark.
For C-like languages, I prefer Light-on-Dark (which is what I use when programming at home).

In all cases, I don't like strong contrasts and always tone down the lightness/darkness of the background when I can.

troyp wrote:Or maybe my experience of light-on-dark prose has been forever tainted by horrible '90s websites?

On the other hand, my first experience with computers was MS-DOS.
Image

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Mon Dec 30, 2013 2:29 pm UTC

I love light-on-dark for everything. I even use the dark reddit theme.

If only I could theme the whole internets.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Mon Dec 30, 2013 4:56 pm UTC

I have no problem with a light background in a terminal in general, but I like to code at night with the lights off so I make my terminal near-black and use vim with desert theme, since it seems to be easiest on my eyes. Visual Studio at work, I leave the colors the default.
Summum ius, summa iniuria.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 7 guests