|
Why? In order to get experience with even more styles of WTF used in those different places?
|
|
|
|
|
So you're saying "better the crap you know"?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I'm guessing it's a regional issue.
What do you get when you cross a joke with a rhetorical question?
|
|
|
|
|
I guess stupidity is not regional, it's universal
|
|
|
|
|
To write that and then quote Clean Code is a special level of genius!
|
|
|
|
|
If a little of something is good, then a whole lot of it must be better, right?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Bernhard Hiller wrote: In the 13395 lines of code of the main window
Bernhard Hiller wrote: In the 13395 lines of code
Bernhard Hiller wrote: 13395
What?
|
|
|
|
|
That's clean code, isn't it?
|
|
|
|
|
I came across this java code. (I changed the class name to SingletonClass)
private static SingletonClass instance;
public SingletonClass()
{
SingletonClass.instance = this;
}
public static SingletonClass getInstance()
{
return instance;
}
|
|
|
|
|
Singleton... public constructor... I don't see anything wrong here
Oh... And I'm curious what you do when you don't call the constructor at least once
|
|
|
|
|
Which of course is used like this:
SingletonClass myVerySingletonClass = (new SingletonClass()).getInstance();
or even better:
SingletonClass anInstanceThatWeDontUse = new SingletoneClass();
SingletonClass useThisInstead = anInstanceThatWeDontUse.getInstance();
Good stuff!
On the other hand, I actually have written code similar to this, except I don't call it a singleton of course. Granted, it's smelly code.
Quiz: What might be the reason to provide a static method that returns an instance of the class, when you know that there will ever only be one instance?
Marc
|
|
|
|
|
SingletonClass useThisInstead = anInstanceThatWeDontUse.getInstance();
This would actually generate a compile error as it getInstance() is a static method
|
|
|
|
|
Nicholas Marty wrote: This would actually generate a compile error as it getInstance() is a static method
Marc
|
|
|
|
|
Actually, in Java you are allowed to call a static method from an instance...
One of many dumb things Java does.
|
|
|
|
|
Uh... Somehow I mistook the code for c#... Somehow skipped that in the original post
At least in c# it isn't possible to do that and I'd think even Java should at least give a compiler warning about that
|
|
|
|
|
If there'll only ever be one instance, that's your typical singleton, isn't it? I don't really understand your quiz question.
I've done load-on-demand singletons in the past which may be what the doofus in charge of this example was going for, I suppose.
|
|
|
|
|
That's just an example of the well-known Renewable Singleton Pattern. That comes in very handy when the old instance has worn out.
For a closer description, see
"Real World Software Development, Vol. II: Design Patterns", by W.T. and F. (2021)
|
|
|
|
|
Ah yes! Code Entropy!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
It makes sense. Every "real-world" (i.e. big) JAVA application reassures me that java is nondeterministic.
|
|
|
|
|
Public Sub New()
MyBase.New
End Sub
Sort of implied anyway - but the fun fact is that the class that has this constructor doesn't actually explicitly inherit anything...so Mybase is object .
(Fortunately the compiler just ignores this so no actual harm done)
|
|
|
|
|
|
Zen coding.
cheers
Chris Maunder
|
|
|
|
|
Duncan Edwards Jones wrote: Fortunately the compiler just ignores this so no actual harm done Which proves that we already have machine that outsmarts the men...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
When I see code like this, I sometimes suspect it may have been copied/pasted from a De-Compiler (such as IL Spy). I mean why on earth would someone go to the trouble of typing that?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|