Having assignments return a value is right up there as well.
Comment on Whitespace
GissaMittJobb@lemmy.ml 9 months ago
Having an asterisk both be the type indicator and the dereference operator is one of the great programming language design blunders of our time, along with allowing nulls for any type in so many languages.
Blackmist@feddit.uk 9 months ago
GissaMittJobb@lemmy.ml 9 months ago
Because of the possibility of accidentally performing an assignment in a conditional expression?
If yes, I agree that it’s not great.
Blackmist@feddit.uk 9 months ago
Yeah, exactly that.
darkpanda@lemmy.ca 9 months ago
I also sometimes wish that the syntax in
if
statements was inverted, where()
was optional and{}
was required.CodexArcanum@lemmy.world 9 months ago
Rust makes this choice and it is way better.
victorz@lemmy.world 9 months ago
Based
clay_pidgin@sh.itjust.works 9 months ago
Cab you give me an example? I’m not sure I follow. Might be language specific?
noli@programming.dev 9 months ago
if(condition) statement; Is valid in typical C-style syntax.
if condition { … }
Is invalid in typical C-style syntax
clay_pidgin@sh.itjust.works 9 months ago
Gotcha, thanks.
darkpanda@lemmy.ca 9 months ago
The code in the image is C or C++ or similar. In those languages and languages derived from them, curly braces are optional but the parentheses are required. It should be the other way around to avoid logic errors like this:
Based on the indentation you’d think that
doSomethingElse
was only meant to run if theelse if
condition was true, but because of the lack of braces and theprintf
it actually happens regardless of either of theif
conditions. This can sometimes lead to logic errors and it doesn’t hold up to a principle of durability under edit — that is, inserting some code into theif
statement changes the outcome entirely because it changes the code path entirely, so the code is in a sense fragile to edits. If the curly braces were required instead of optional, this wouldn’t happen.I have all of my linters set up to flag a lack of curly braces in these languages as an error because of this. It’s a topic that sometimes causes some debate, ‘cause some people will vociferously defend their right to not have the braces there for one liners and more compact code, but if have found that in general having the, be required consistently has led to fewer issues than having arguments about their absence, but to each their own. I know many big projects that have the opposite stance or have other guidelines, but I just make ‘em required on my own projects or projects that I’m in charge of and be done with it.
clay_pidgin@sh.itjust.works 9 months ago
That makes perfect sense, thank you.