Java pet peeve #3
Feb. 26th, 2005 09:56 pmPet peeve #3 about Java: the lack of destructors.
What I would like to happen:
What I have to do in Java:
and if I'm wearing my lucky rabbit's foot, the moon is blue, and a black cat is following me, then finalize() might just get called when the Predator gets killed. In fact I'm lucky (it seems) if finalize() gets called at all. Hmm. So much for my bright idea for debugging.
In case you're wondering, pet peeves #1 and #2 in Java are the inability to switch() on a String, and the lack of enums in any sane form.
What I would like to happen:
public Predator()
{
System.out.println("Say hello to " + this);
}
public ~Predator()
{
System.out.println("Someone killed " + this);
}What I have to do in Java:
public Predator()
{
System.out.println("Say hello to " + this);
}
public void finalize()
{
System.out.println("Someone killed " + this);
}and if I'm wearing my lucky rabbit's foot, the moon is blue, and a black cat is following me, then finalize() might just get called when the Predator gets killed. In fact I'm lucky (it seems) if finalize() gets called at all. Hmm. So much for my bright idea for debugging.
In case you're wondering, pet peeves #1 and #2 in Java are the inability to switch() on a String, and the lack of enums in any sane form.
no subject
Date: 2005-02-26 11:26 pm (UTC)And why would you switch on strings to begin with? :-D Actually, I understand the reason for the pet peeve, it's just that last time I needed that functionality, if..else if did the job.
no subject
Date: 2005-02-26 11:36 pm (UTC)I prefer switching on strings instead of if..else as I find it cleaner and easier to read. When you get down to it, most stuff like switch is just there to be nice to the programmer. Plus I come from a VB background, and VB has this nice trick of making String a native data type (as opposed to a class in Java, or some glorified byte array in C), and so means you can use Strings just about anywhere you can use numbers. There's also a dedicated concatenation operator, which is nice (and really confused me first time I tried C with MFC's CString - '&' is concatenation in VB and address-of in C) and needed as you can do some funky stuff if you use '+' instead. Basically, "3" + "4" is not the same as "3" & "4", as VB does on-the-fly type conversion too well at times.
no subject
Date: 2005-02-27 03:40 am (UTC)“glorified byte array in C” — that’s what makes me most sick about C after the glorified pointer-fiddling.
no subject
Date: 2005-02-27 09:04 am (UTC)no subject
Date: 2005-02-27 03:06 pm (UTC)Needing half the time a pointer and half the time a true variable is my problem really :P
no subject
Date: 2005-02-27 04:44 pm (UTC)If I have a main function that calls other functions, main has the object and all other functions have the pointer.
If I have no functional main (i.e. a WinMain, with a message loop), then make a global pointer, malloc it before DialogBox(), and free it right after.
:-)