by dale_glass · 4y ago · 0 comments
So for instance, Perl has a completely ordinary if statement:
if ($foo) {
say "Foo is enabled";
}
However, it also allows doing this: say "Processing file $filename" if ($debug);
Used judiciously, this can make code better because you avoid breaking up the flow with a bunch of braces. It's also easy to tack on to the end of an existing statement.The downside of course is the lack of predictability, such features can make code more confusing to read rather than clearer if abused. This kind of thing is just syntactic sugar and not inherently a bad thing. The issues that come up are mostly a result of some people trying to be too clever.
Which is exactly the problem. Yes, some people will use it judiciously.
Other people will just use it wherever possible. Yet others will mix it with the alternative style willy-nilly. Some won't use it at all. And as you so correctly point out, some people will try to be too clever with it.
The result is the exact opposite of what was originally intended by syntactic sugar: Instead of making code easier to read, it becomes harder.
The only way to , at least partially, prevent that, is for languages to be restrictive in their syntax. Yes, that may be more verbose at times. But I consider that a small price to pay for consistency.
Perl was intentionally (designed by linguist) to be like a "human" language, with all the small benefits and large problems that entails.