You are a stupid programmer, you can't have that

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Aug 9 23:09:30 UTC 2021


On Mon, Aug 09, 2021 at 10:32:01PM +0000, Alexandru Ermicioi via Digitalmars-d wrote:
> On Monday, 9 August 2021 at 18:00:23 UTC, H. S. Teoh wrote:
> > 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.
> 
> Well, if you're picky, then no, static methods are not free functions
> in global space, but rather can be considered as methods of object
> representing the class of objects (x.class). They though are usually
> used as free functions, and people don't fuss over whether they a free
> or part of a class.

Frankly, that's just calling a duck an aquatic chicken with webbed feet.
The class is a singleton (which kinda defeats the whole point of a
*class* -- at that point it might as well be just a namespace, as far as
effective semantics are), and the static method does not even take a
reference to said singleton class, it's completely standalone and
independent (aside from the FQN).  It basically behaves like a global
free function -- and is in fact the exact idiom Java uses when
interfacing with C functions.  The equivalence is practically 1-to-1.

It quacks like a duck and waddles like a duck -- it's a duck.  Calling
it an aquatic class method with webbed feet is really only good for
doing lip service to OO dogma. For all practical purposes, it's a free
function.


> I think java doesn't have any notion of a global space where you can
> put your funcs. There is just class and that is it.

Yes, and this is why such a non-OO hack was introduced in the first
place.  Since anything existing outside a class is taboo in OO dogma, in
order to rationalize away the non-OO-ness of a global free function we
wrap it in the robes of a class and crown it as a method of that class.
But the class is a singleton (and holds no state) and the method is
static (does not depend on the class instance at all), which makes it
painfully obvious that the entire intent is to rephrase "global free
function" in terms that are less offensive to OO dogma.

But regardless, this shoe-horning doesn't change the fact that it
essentially, for all practical purposes, behaves like a global free
function.


> To note, I'm not defending the choices made for java by it's dev team,
> just stated some facts, and personal views.
[...]

No offense taken.  I just find the OO extremism of Java to be laughable,
that's all.  Why not just admit that OO isn't the be-all and end-all of
programming, and call free global functions what they are.

This is why D's multi-paradigm approach makes so much more sense:
sometimes one paradigm doesn't fit the problem, why not acknowledge it
and allow a different paradigm to step in.  Not every problem is a nail
to which the OO hammer must be brought to bear.


T

-- 
Talk is cheap. Whining is actually free. -- Lars Wirzenius


More information about the Digitalmars-d mailing list