?

Log in

No account? Create an account
'Twas brillig, and the slithy toves did gyre and gimble in the wabe [entries|archive|friends|userinfo]
Thomas

[ website | Beware the Jabberwock... ]
[ deviantArt | the-boggyb ]
[ FanFiction | Torkell ]
[ Tumblr | torkellr ]

Links
[Random links| BBC news | Vulture Central | Slashdot | Dangerous Prototypes | LWN | Raspberry Pi]
[Fellow blogs| a Half Empty Glass | the Broken Cube | The Music Jungle | Please remove your feet | A letter from home]
[Other haunts| Un4seen Developments | Jazz 2 Online | EmuTalk.net | Feng's shui]

Java pet peeve #3 [Saturday 26th February 2005 at 9:56 pm]
Thomas

boggyb
[Feeling |busybusy]
[Playing |Generic background ~ Team17/Worms World Party (set on loop)]

Pet peeve #3 about Java: the lack of destructors.

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.
Link | Previous Entry | Share | Flag | Next Entry[ 6 pennies | Penny for your thoughts? ]

Comments:
[User Picture]From: olego
Saturday 26th February 2005 at 11:26 pm (UTC)
http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html

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.
(Reply) (Thread)
[User Picture]From: boggyb
Saturday 26th February 2005 at 11:36 pm (UTC)
Yep, but here we're still in the stone age with 1.4.2_06 as the version the lecturers a) expect us to use and b) have installed on all the Informatics boxen.

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.
(Reply) (Parent) (Thread)
[User Picture]From: ralesk
Sunday 27th February 2005 at 3:40 am (UTC)

“glorified byte array in C” — that’s what makes me most sick about C after the glorified pointer-fiddling.

(Reply) (Parent) (Thread)
[User Picture]From: olego
Sunday 27th February 2005 at 9:04 am (UTC)
Dude, give it up about the pointers ^_^. When have you ever needed ** (argv doesn't count), let alone ***?
(Reply) (Parent) (Thread)
[User Picture]From: ralesk
Sunday 27th February 2005 at 3:06 pm (UTC)

Needing half the time a pointer and half the time a true variable is my problem really :P

(Reply) (Parent) (Thread)
[User Picture]From: olego
Sunday 27th February 2005 at 4:44 pm (UTC)
Well, what I do is this:

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.

:-)
(Reply) (Parent) (Thread)