3 ms·
> Same way you move on from single condition bracket-less ifs. This is one of those things that whether you drop it or not, you recognize the times it's caused
by kbenson 9y ago
> Same way you move on from single condition bracket-less ifs.
This is one of those things that whether you drop it or not, you recognize the times it's caused you severe pain because you didn't notice it was single line when adding a statement, such as a debugging one, and all of a sudden the conditional part isn't what you were expecting.
This is actually one of the things I love about Perl. Single line conditionals were changed so they both looked different, and they only allow a single statement. e.g.
if ( condition ) statement;
becomes
statement if condition;
Regular if blocks still work as expected, but there is no braceless version of regular if conditions. I understand many people find it jarring at first, but it does allow for clear and concise precondition and return early statements, especially when grouped together. e.g.
return undef if $param1 < 0;
return undef if $param1 > 100;
die "Not a number" if not looks_like_number($param1);
- collyw 9y agoThis can be horrible in JavaScript. It can make code really ugly. I have had to deal with code that looks like this recently: if (condition){ doSomething() doSomethingElse() } else doSomethingDifferent() doSomethingConfusing() // is this part of the else or not?? Perl got many things right. Its a shame it seems to have fallen away as a language.