Live data from Hacker News

Left to Right Programming

graic.net

111–120 of 372 posts

Re: Left to Right Programming

#111

I had a similar thought a few years ago with an Advent of Code problem for which my solution in python might have been max(map(sum, input_list.split(None))) To decipher this the eye has to jump to the middle of the line, move rightwards, then to the left to see the "map" then move right again to see what we are mapping and then all the way to the beginning to find the "max". The author would probably suggest rust's s…

Honestly, I find using intermediate variables more readable than a long chain of function invocations where you have to keep track of intermediate results in your head:

    input_groups = input_list.split(None)
    group_sums = map(sum, input_groups)
    max_sum = max(group_sums)
This also gives you a slightly higher-level view on how the algorithm proceeds just by reading the variable names on the LHS.

Re: Left to Right Programming

#112

Earlier quoted context omitted.

> always creating an intermediary result-set You want the DB to first run SELECT * FROM , and then start operating on that?

Obviously not, and bringing this up as if it's a gotcha just shows you aren't keeping up with the conversation. Try less to correct people and more to understand people. It's about how humans think about it, not about how the computer executes it.

How else do you read what they wrote?

Re: Left to Right Programming

#113

One of the things I dislike about function notation is that in f(g(h())) execution order is right-to-left. I like OO partly because execution order is writing order ( h().g().f() ) In Clojure I love the threading macro which accomplishes the same: (-> (h) (g) (f))

In Haskell there's also dot (edit - my bad, not dot, pipe) syntax which allows composing functions left to right. I believe Nim also has it. Just as a few more examples.

f . g is still doing g first, then f, right? Haskell has pipelines in the Flow library.

https://hackage-content.haskell.org/package/flow-2.0.0.9/doc...

Re: Left to Right Programming

#114
post #83

I think the most absurd syntax goes to Python again. Python offers an "extended" form of list comprehensions that lets you combine iteration over nested data structures. The irony is that the extensions have a left-to-right order again, but because you have to awkwardly combine them with the rest of the clause that is still right-to-left, those comprehensions become completely unreadable unless you know exactly how t…

The proper way to parse or construct nested list comprehensions as explained in pep 202 is to think like you're using normal for:

for a in b:

  for c in a:

    use(a,b,c)

 
This would be

[use(a,b,c) for a in b for c in a]

Everything stays the same except the "use" part that goes in the front (the rule also includes the filters - if).

Re: Left to Right Programming

#115
In 1990s-born scripting languages, it makes sense that there are plenty design choices that don't mesh well with static-analysis-driven autocompletion, because that was not at all part of the requirements for these languages at the time they were designed!

Re: Left to Right Programming

#116
post #109

Author picked up a quite convenient example to show methods/lambda superiority. I prefer list/set/dict comprehensions any day. It's more general, doesn't require to know a myriad of different methods (which could not exists for all collections, PHP and JS are especially bad with this) and easily extendable to nested loops. Yes it could be `[for line in text.splitlines() if line: for word in line.split(): word.upper()…

I'm a big fan of Python syntax, but really comprehensions don't make any sense to me efficiency wise (even for readability). Python syntax would become perfect with filter() and map() :')

Re: Left to Right Programming

#118
post #106
post #39

SQL shows it's age by having exactly the same problem. Queries should start by the `FROM` clause, that way which entities are involved can be quickly resolved and a smart editor can aid you in writing a sensible query faster. The order should be FROM -> SELECT -> WHERE, since SELECT commonly gives names to columns, which WHERE will reference. You could even avoid crap like `SELECT * FROM table`, and just write `FROM…

My main caveat here, is that often the person starting a select knows what they want to select before they know where to select it from. To that end, having autocomplete for the sources of columns is far far more useful than autocomplete for columns from a source. I will also hazard a guess that the total number of columns most people would need autocomplete for are rather limited? Such that you can almost certainly…

Can you help me understand this situation? Almost always what I want to select is downstream of what I am selecting from, I can't write anything in SELECT until i understand the structure/columns available in FROM.

Re: Left to Right Programming

#119
> Programs should be valid as they are typed.

Not possible. There are more keystrokes that result in invalid programs (you are still writing the code!!) than keystrokes that result in a valid program.

More seriously, I do think that one consideration is that code is read more often that written, so fluidity in reading and comprehension seem more important to me than “a program should be valid after each keystroke.

Re: Left to Right Programming

#120
post #83

I think the most absurd syntax goes to Python again. Python offers an "extended" form of list comprehensions that lets you combine iteration over nested data structures. The irony is that the extensions have a left-to-right order again, but because you have to awkwardly combine them with the rest of the clause that is still right-to-left, those comprehensions become completely unreadable unless you know exactly how t…

I've taken to writing complex comprehensions like this over multiple lines (which I initially thought wasn't possible!). It's still a bit awkward, but the order of "fors" is the same as if one was writing nested for loops, which makes reasoning about it easier for me.
Post reply on HN