Java or C++ (Benchmarking)

Jon Skeet skeet at pobox.com
Thu May 10 06:33:11 EDT 2001


phil hunt <philh at comuno.freeserve.co.uk> wrote:

> >> >for (Iterator it = collection.iterator();
> >> >     it.hasNext(); )
> >> >{
> >> >     ItemClass item = (ItemClass) it.next();
> >> >     item.doSomething();
> >> >}
> >> 
> >> Not in the general case, because item might not have a doSomething()
> >> method -- for example ItemClass could be a built-in class. 
> >
> >Not at all sure what you're getting at here.
> 
> E.g. if your collection is an array of Strings, you can only say
> item.doSomething() if the String class has a doSomething() method.
> Otherwise you must pass the item as a parameter to the method, e.g.
> 
>    doSomething(item)
> 
> but that won't work because you can't have a function in Java, it
> all has to pretend it is OO, even when it isn't, so you have to 
> make doSomething() a class method and say:
> 
>    SomeClass.doSomething(item)

That's what the cast is for. Replace "ItemClass" with "String" in the 
above and it would work fine.
  
> >Sure, so use the *slightly* more longwinded version as above. Yes, you
> >need braces to indicate the block. Is that really such a problem?
> 
> Not on its own, it's just a niggle (the fact that there is no way
> of fixing Java's overly verbose way of doing things (such as a
> #define perhaps), *is* a problem, IMO, becuse it shows the
> language is hard to extend to make it do what you want.

I guess it's a problem if you really want to extend the language. I've 
never had the desire to, particularly.
 
> >> I think Java would be better if it had a construct:
> >> 
> >>    iterate (ItemClass item in collection){
> >>       ...operate on item...
> >>    }
> >
> >Yes, quite possibly that would be an improvement. I don't think it would 
> >be a huge improvement, however, and I don't believe the lack of such a 
> >syntax is the huge problem you portray it as.
> 
> On it's own, I don't think it's a huge problem. The huge problems IMO are 
> that (1) my whole experience of programming is Java is like this, and
> (2) you can't fix it within the Java language.

It sounds like Java is entirely unsuitable for either your programming 
style or your problem domain then. However, many of us don't have 
problems like that at all.
 
> >> Yes, it always feels like I am fighting the language whenever I
> >> code in Java.
> >
> >No, fighting the Java way of doing things. 
> 
> That amounts to the same thing, IMO. Java has a "way of doing
> things", i.e. to use it essectively you have to bowe down to the
> Gospel According To Gosling about the One True Way to write code.
> That's why I call it a "bondage and discipline" language. Pascal
> is like this too. C and C++ don't have this philosophy, IMO.

No - which means people write code any which way, extend the language 
all over the place and end up with code which is very hard for other 
people to maintain after they've moved on.

I'm afraid I still don't see any of the problems you have with Java as 
being real problems - they may mean it's not an appropriate language for 
you, but then no language is the perfect one for every person, every 
coding style and every problem domain.

-- 
Jon Skeet - skeet at pobox.com
http://www.pobox.com/~skeet
If replying to the group, please don't mail me at the same time



More information about the Python-list mailing list