| ▲ | gcanyon a day ago |
| Can anyone give a good reason why supporting syntax like: y = 2 * x
- 3
is worth it? |
|
| ▲ | whateveracct a day ago | parent | next [-] |
| in Haskell, supporting that is how you get neat composition such as applicative style formatted like this: f
<$> x
<*> y
<*> z
|
|
| ▲ | marcosdumay a day ago | parent | prev | next [-] |
| 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. |
|
| ▲ | zephen a day ago | parent | prev | next [-] |
| 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"
|
|
| ▲ | duped a day ago | parent | prev | next [-] |
| if object.method()
|| other_object.field.condition()
|| (foo > bar && baz < qux)
|
|
| ▲ | justsomehnguy a day ago | parent | prev | next [-] |
| 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
|
|
| ▲ | szmarczak a day ago | parent | prev [-] |
| 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. |
| |
| ▲ | bmandale a day ago | parent | next [-] | | Clearer for the computer, but not for the human. Many errors, some severe, have been caused by a human only looking at the indentation and not realizing the braces don't match. | | |
| ▲ | Blikkentrekker a day ago | parent | next [-] | | That's just because most languages go by braces and have optional intendation that is just ignored by the compiler. I'd reckon that in a language where stuff is done by indentation but optional braces exist that are just ignored so many errors would also have been caused by braces being misplaced by the programmer to queue other programmers who thought some scope happened as a consequence but the compiler disagreed due to the indentation, which by the way was caused by tabs and spaces being mixed in the code and it not properly showing up for another programmer with tab with set differently. | | |
| ▲ | bmandale a day ago | parent [-] | | > tabs and spaces being mixed in the code Python banned this in python3. Problem solved. |
| |
| ▲ | szmarczak a day ago | parent | prev | next [-] | | > human only looking at the indentation and not realizing the braces don't match. If it ever gets to that point, a refactor is obligatory. Don't give the human tools to make easy mistakes. Any grammar can be abused, so blame the human for not writing clean code. | | |
| ▲ | TheOtherHobbes a day ago | parent [-] | | Javascript's delimeter soup ((){([]{})}); can become near impossible to parse barebrained, especially when mixed with indents and semicolons. Semicolons are just noise. They're absolutely redundant. Some brackets are necessary, but whitespace/indent languages make it clear there's a lot of redundancy there too. The goal is to minimise errors and cognitive load. The fewer characters the better. | | |
| ▲ | szmarczak a day ago | parent [-] | | > whitespace/indent languages make it clear there's a lot of redundancy there too. The only purpose for whitespace indentation is to make the code easier on the eyes. A space shouldn't have an impact in terms of execution, that would be too hazardous. It's too easy to randomly insert a space rather than a character. | | |
| ▲ | xigoi 17 hours ago | parent [-] | | > It's too easy to randomly insert a space rather than a character. What are you doing with your code? I never find myself just randomly inserting characters. | | |
| ▲ | szmarczak 14 hours ago | parent [-] | | > I never find myself just randomly inserting characters. Hasn't it ever occured to you trying to insert a space at your mouse but your cursor wasn't there? People sometimes forget to click (or think the cursor is already there), myself included. Characters are easier to spot because they are not invisible and random letters cause compile errors. If it has never occurred to you, then good for you. However I do not see what the benefit of not using closing brackets would be. | | |
| ▲ | xigoi 14 hours ago | parent [-] | | I don’t use the mouse when editing code, so this particular mistake does not happen to me. > I do not see what the benefit of not using closing brackets would be. Less visual noise. And the ability to use braces for other syntax. |
|
|
|
|
| |
| ▲ | szmarczak a day ago | parent | prev [-] | | > and not realizing the braces don't match. Make your IDE highlight the current section or display a hint showing starting bracket. For example, C++ devs do #endif // #if ... Too many brackets? Refactor - problem solved. |
| |
| ▲ | silon42 19 hours ago | parent | prev [-] | | IMO, that is the only acceptable situation where semicolons can be removed from the language... if you need to add indentation rules, you've failed. |
|