| |
| Posted by H. S. Teoh in reply to Alexandru Ermicioi | PermalinkReply |
|
H. S. Teoh
Posted in reply to Alexandru Ermicioi
| On Mon, Aug 09, 2021 at 05:37:26PM +0000, Alexandru Ermicioi via Digitalmars-d wrote:
> On Monday, 9 August 2021 at 12:14:27 UTC, Dukc wrote:
> > I can see no other reasons for disallowing free functions or requiring curly braces for every singe `if` or `while` statement.
>
> Java is object oriented only language, hence it makes sense to not have free functions as in C++, and you actually do have free functions there. They are static methods.
I find this to be silly OO-extremism on Java's part. Static methods of a singleton class are basically free global functions. Why can't they just *be* global free functions?! But nooo, that would not jive with the OO agenda, so we have to wrap that in a singleton class just to do lip service to the OO dogma and pacify the OO police. We're eating the greasy unhealthy food of global free functions, but to pacify our OO conscience we order the diet coke of a singleton class's static methods.
Seriously, just call it what it is already.
> Braces are not required for control statements, but encouraged to avoid ambiguous then statements.
[...]
This one I actually agree with. (Even if I do find it annoying
sometimes.)
Ambiguous statements are actually worse than they appear at first glance, because of long-term maintainability issues. Consider this code where braces are omitted:
if (someCondition)
doSomething();
else
doSomethingElse();
finishUp();
Imagine if some time later somebody discovers a bug, and introduces this fix:
if (someCondition)
doSomething();
else
doSomethingElse();
return 1; // <--- bugfix
finishUp();
Had braces been required, the `return 1;` would have been introduced in the proper scope and there would have been no problem. But now this fix has introduced a new bug.
T
--
The volume of a pizza of thickness a and radius z can be described by the following formula: pi zz a. -- Wouter Verhelst
|