logoalt Hacker News

gcanyonyesterday at 9:38 PM6 repliesview on HN

Can anyone give a good reason why supporting syntax like:

    y = 2 * x
      - 3
is worth it?

Replies

whateveracctyesterday at 9:45 PM

in Haskell, supporting that is how you get neat composition

such as applicative style formatted like this:

        f
    <$> x
    <*> y
    <*> z
marcosdumayyesterday at 9:57 PM

By "is worth it" you mean it's worth the work?

Because it's very little extra work.

If you want to know if it's a good syntax, AFAIK it's the only way to do a semicolon-less language that doesn't break all the time.

dupedyesterday at 11:44 PM

    if object.method()
    || other_object.field.condition()
    || (foo > bar && baz < qux)
zephenyesterday at 10:15 PM

Obviously, that's a really short expression.

So, the question is, if you have a long expression, should you have to worry too much about either adding parentheses, or making sure that your line break occurs inside a pair of parentheses.

It boils down to preference, but a language feature that supports whatever preference you have might be nice.

  priority = "URGENT"  if hours < 2  else
             "HIGH"    if hours < 24 else
             "MEDIUM"  if hours < 72 else
             "LOW"
justsomehnguyyesterday at 10:03 PM

Mostly eye-candy, especially for some long one-liners.

In PowerShell you can do that by explicitly instructing what the next line is actually a continuation of the previous one:

    $y = 2 * $x `
       - 3
szmarczakyesterday at 9:47 PM

It's not. Your eyes can deceive you by guessing the correct indentation. Indentation should never be used for grammar separation. Explicit characters such as } ] ) are clearer and unambiguous.

show 2 replies