Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Human Thinking vs. Parser Thinking (2016) (dannysu.com)
27 points by userbinator on May 3, 2023 | hide | past | favorite | 7 comments


Reads as if the person surprised by "new" binding stronger than the dot is coming from something like php where you can put various kinds of string madness in place of the class name.

But even there, it could not be "instantiate whatever ClassName().something() returns", because php being php has no qualms having places in code where string literals, variables and properties are accepted, but no other expressions that would return a string.


I tend to use parenthesis by default even if they're not necessary, and I also prefer a space before the opening paren.

In F# you can use `f()` or `g ()`, but if you are chaining them, `f ().g ()` is not the same thing as `f().g()`, so you are forced to write `(f ()).g ()` if you use spacing.


> In F# you can use `f()` or `g ()`, but if you are chaining them, `f ().g ()` is not the same thing as `f().g()`, so you are forced to write `(f ()).g ()` if you use spacing.

Never encountered it, but after thinking it through, I think I see why it behaves differently. a standalone `()` is the unit value, while a `f()` is a function call. And `f ()` is passing the unit value into the function f.

And now I think I can't unsee that wart on f#. (I personally mostly use the `f()` style of function calls)


In Lisp, there is no distinction, and it's a huge advantage.


Yep I was just reading this thinking about how much trouble is caused by putting opening brackets and bracket-like things in the infix position. Doesn’t even have to be a lisp per se! Just denoting where expression bounds begin and end is a huge win. It’s almost always a lisp, but this is also a particular place where JSX does well. (Of course JSX is basically sexprs without saying so.)


The downside is that the entire depth of the "syntactical stack" has to be taken into consideration over the whole range of the expression's length. Those walls of openings and closings at the beginning and end... Those don't really serve any purpose besides creating pressure to come up with names for intermediates. When those names are good they are helpful, but that's not a given. Those named intermediates lurk in the scope because you never know if they might be use-and-forget or not (well, unless the code happens to be rust)

The strict flat-binding left to right chains of the dot and friends allow for a nicely streamlined "intra-expression scope" in the mind while reading. To me this feels like a lot of brain capacity getting freed for more important things. King of that hill is the "kotlin let" which allows just about everything to get converted into left-to-right. I miss that in every other language.


Really? Seems code review is a huge waste of time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: