Live data from Hacker News

Left to Right Programming

graic.net

281–290 of 372 posts

Re: Left to Right Programming

#281

Don’t know why python gets so much love. It’s a painful language as soon as more than one person is involved. What the author describes is just the tip of the iceberg

One perspective: I built a business on python. It’s an accessible and powerful tool.

Re: Left to Right Programming

#282
I agree with the main ideas of this article. Context-first left-to-right seems like it would be easier for LLMs to write and autocomplete well too.

This line, though, seems like it's using the wrong tools for the job:

  len(list(filter(lambda line: all([abs(x) >= 1 and abs(x)  0 for x in line]) or all([x 
To me it's crying out for the lines to be NumPy arrays:

  sum(1 for line in diffs
      if ((np.abs(line) >= 1) & (np.abs(line)  0).all() or (line 
There's no need to construct the list in memory if you're just counting, and dealing with whole lines at once is much nicer than going element by element. On top of that, this version is much more left-to-right.

Re: Left to Right Programming

#283
post #219

Earlier quoted context omitted.

Failure to understand something is not a virtue. That it does get a lot of love strongly suggests that there are reasons for that. Of course it has flaws, but that alone doesn't tell us anything; only comparisons do. Create a comprehensive pro/con list and see how it fares. Then compare that to pro/con lists for other languages.

> That it does get a lot of love strongly suggests that there are reasons for that. Reasons, sure, but whether those reasons correlate with things that matter is a different question altogether. Python has a really strong on-ramp and, these days, lots of network effects that make it a common default choice, like Java but for individual projects. The rub is that those same properties—ones that make a language or codeb…

I'm not a hater, but also not the biggest fan of bash. What do you consider its pros and cons?

Pros: easy to interact with different tools, included in many Unix OSs, battle tested.

Cons: complex stuff gets messy, with weird syntax, hard to do logic, hard to escape everything correctly

Re: Left to Right Programming

#284
post #51

Earlier quoted context omitted.

I find myself writing a very simple style of python that avoids list comprehensions and so on when working in a shared code base. For a language where there is supposed to be only one way to do things, there are an awful lot of ways to do things. Don’t get me wrong, writing a list comprehension can be very satisfying and golf-y But if there should be one way to do things, they do not belong.

I find list and dict comprehensions are a lot less error prone and more robust than the “manual” alternatives. I would say unless you have a good reason to do so, features such as meta classes or monkey patching would be top of list to avoid in shared codebases.

> I find list and dict comprehensions are a lot less error prone and more robust than the “manual” alternatives.

I find them easier to understand and explain, too.

Re: Left to Right Programming

#285
post #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.

The problem with this approach for me is that I don't know which variables are important outside of this snippet or outside of the next line. Is input_groups something I should keep in my head or is it just an intermediate result that can be discarded from my attention right away? The pipe-like solutions are nice because they are self-contained and you know that you only care about the final result and can abstract away the implementation.

I prefer python comprehensions for the same reason. I can tell that they are about crating a list or a dict and I don't need to parse a bunch of operations in a loop to come to the same conclusion.

Re: Left to Right Programming

#286
post #279

Earlier quoted context omitted.

I agree, it's not too bad if you enable strict Pyright checking in CI, and you use `uv` and you don't care remotely about performance. That's quite a lot of ifs though. Tbh I haven't found anything significantly better for scripting though. Deno is pretty nice but Typescript really has just as many warts as Python. At least it isn't so dog slow.

I've pretty much embraced PowerShell for scripting. The language is warty as hell and seems to be entirely made of sharp edges but I've gotten used to it and it does have a lot of excellent ideas.

Yeah I'm toying with nushell which is like Powershell but with a less offensive syntax.

But when I say "scripting" I don't mean shell scripting. I mean stuff like complex custom build systems or data processing pipelines. I would never do those in any shell language.

Re: Left to Right Programming

#287
post #221

Earlier quoted context omitted.

This presupposes that the reader likes or even uses auto-complete. I do not, and there are many others like me.

And I'm sure there are people who program in Notepad or nano. If you want to develop software like it's the 80s again, go ahead, the rest of us appreciates at least basic IDE support.

I program in Vim, after having tried multiple IDEs and finding them all to be annoying. In the few places where they were helpful, they only highlighted what I disliked about either the language or a particular library.

Re: Left to Right Programming

#288

> the Python code in the previous example is still readable Yes, I agree with the author, list comprehensions are readible, and I'd add, practical. > it gets worse as the complexity of the logic increases len(list(filter(lambda line: all([abs(x) >= 1 and abs(x) 0 for x in line]) or all([x Ok, well this is something that someone would be unlikely to write... unless they wanted to make a contrived example to prove a po…

Why was this downvoted?

Re: Left to Right Programming

#289

Reading through this article only elicits a "WTF!?" from me. Your editor can’t help you out as you write it. You shouldn't need handholding when you're writing code. It seems like the whole premise of the author's argument is that you shouldn't learn anything about the language and programming should be reduced to choosing from an autocomplete menu and never thinking more than that. I've seen developers who (try to)…

> No wonder people claim typing speed doesn't matter - they can barely think ahead one token, nevermind a statement or function, much less the whole design! Ideally your typing speed should become the bottleneck and you should be able to code "blind", without looking at the screen but merely outputting the code in your mind into the machine as fast as humanly possible. Instead we have barely-"developers" constantly chasing that next tiny dopamine hit of picking from an autocomplete menu. WTF!?

If writing code is an automated process for you, you are also begging for AI to be replace you. Just a more advanced one than the code-monkey in the OP.

Re: Left to Right Programming

#290

Another point to this is that we should switch to writing the numbers in the right order too: 123 should be three-hundred-twenty-one. This way, as soon as you type "1", it is truly one, you add a "2" and you know that's adding twenty... IIRC Arabic gets this right! /s

You joke, but you highlight an important problem with the argument.

The idea is that we write `foo.bar`, where `foo` is in scope, exactly because `foo` is in scope. We don't write `bar from foo` or whatever, because it would be hard to reverse search the things that have `bar` in them.

But which is more likely: will `foo` be Liskov-substitutable for `bar`, or will other things that contain a `bar` have a `bar` of a Liskov-substitutable type?

Which is to say, the author is depending on a particularly idiosyncratic meaning of "valid".

That said, the problem the author describes at the beginning can be easily worked around, if you like this kind of workflow:

  words_on_lines = [st # 'str' is a plausible autocompletion
  words_on_lines = [str.sp # must be either 'split' or 'splitlines', unless 'str' is shadowed
  words_on_lines = [str.split(line) for # 'line in' can be suggested
  words_on_lines = [str.split(line) for line in text.splitlines()] # IDE can automatically check type and refactor the idiom
And it also isn't at all true that IDEs work left to right. They're constantly auto-typing the balancing close parentheses/braces/brackets for me and it's never clear to me what the intended flow is for moving past what was automatically typed, or whether manually typing that bracket explicitly (since I'm in my own "automatic typing") will double it up or not. There's nothing preventing the IDE from expecting you to type the clauses of the comprehension in a different order and I wouldn't at all be surprised to hear that someone has already implemented this.
Post reply on HN