Live data from Hacker News

Left to Right Programming

graic.net

1–10 of 372 posts

Re: Left to Right Programming

#2
I'm curious on how much of this is basically overcome by the new tools? As much as vibe coding annoys me, I can't argue against how good autocomplete from these LLMs can be.

Re: Left to Right Programming

#3
> This is much more pleasent. Since the program is always in a somehwat valid state as you type it, your editor is able to guide you towards the Pit of Success.

Although the subtitle was “programs should be valid as they are typed”, it’s weakened to “somewhat valid” at this point. And yes, it is valid enough that tooling can help, a lot of the time (but not all) at full capability. But there’s also interesting discussion to be had about environments where programs are valid as they are typed. Syntactically, especially, which requires (necessary but not sufficient) either eschewing delimition, or only inserting opening and closing delimiters together.

Re: Left to Right Programming

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

That would be nice if devs always wrote code sequentially, i.e. left to right, one character at a time, one line at a time. But the reality is that we often jump around, filling in some things while leaving other things unfinished until we get back to them. Sometimes I'll write code that operates on a variable, then a minute later go back and declare that variable (perhaps assigning it a test value).

Re: Left to Right Programming

#6
post #2

I'm curious on how much of this is basically overcome by the new tools? As much as vibe coding annoys me, I can't argue against how good autocomplete from these LLMs can be.

Very human of us to spend billions of dollars and tons of electricity to bang our programming languages into shape since sane syntax is slightly uncomfortable the first 10 minutes you work with it.

I believe there are some strongly typed stack based languages where you really always do have something very close to a syntactically correct program as you type. But now that LLMs exist to paper over our awful intuitions, we're stuck with bad syntax like python forever.

Re: Left to Right Programming

#7
> If you aren’t familiar with Rust syntax, |argument| result is an anonymous function equivalent to function myfunction(argument) { return result; }.

> Here, your program is constructed left to right. The first time you type line is the declaration of the variable. As soon as you type line., your editor is able to suggest available methods.

Yeah, having LSP autocomplete here does feel nice.

But it also makes the code harder to scan than Python. Quick readability at a glance seems like the bigger win than just better autocomplete.

Re: Left to Right Programming

#8
I miss the F# pipe operator (https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...) in other languages. It's so natural to think of function transform pipelines. In other languages you have to keep going to the left and prepend function names, and to the right to add additional args, parens etc ...

Re: Left to Right Programming

#9

  len(list(filter(lambda line: all([abs(x) >= 1 and abs(x)  0 for x in line]) or all([x 
This really isn’t fair on Python. Python isn’t very much not designed for this style of functional programming. Plus you haven’t broken lines where you could. Rewrite it as a list comprehension and add line breaks, and turn the inner list comprehensions into generator expressions (`all([…])` → `all(…)`), and change `abs(x) >= 1 and abs(x) much better, though it still has the jumping around noted, and I do prefer the functional programming approach. I’m just saying the presentation isn’t fair on Python.

  len([line for line in diffs
       if all(1  0 for x in line) or all(x 
(Aside: change the first line to `sum(1 for line in diffs` and drop the final `]`, and it will probably perform better.)

I also want to note, in the JS… Math.abs(x) instead of x.abs() (as seen in Rust).

And, because nerd sniping, two Rust implementations, one a direct port of the JS:

  diffs.iter().filter(|line| {
      line.iter().all(|x| x.abs() >= 1 && x.abs()  0) || line.iter().all(|x| x 
(`x.abs() >= 1 && x.abs() And one optimised to only do a single pass:

  diffs.iter().filter(|line| {
      let mut iter = line.iter();
      let range = match iter.next() {
          Some(-3..=-1) => -3..=-1,
          Some(1..=3) => 1..=3,
          Some(_) => return false,
          None => return true,
      };
      iter.all(|x| range.contains(x))
  }).count()

Re: Left to Right Programming

#10
post #8

I miss the F# pipe operator ( https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref... ) in other languages. It's so natural to think of function transform pipelines. In other languages you have to keep going to the left and prepend function names, and to the right to add additional args, parens etc ...

You'll be able to use it in PHP 8.5 :-)

https://stitcher.io/blog/pipe-operator-in-php-85

Post reply on HN