C++ sucks
Peter Korsten
EMAIL HIDDEN
Thu Nov 22 20:01:45 CET 2007
Martin Naef schreef:
> Peter Korsten wrote:
>> Yes, but here comes the next problem: speed. With C, specifically on
>> Unix, I can mmap() a file and it magically appears as a bit of memory,
>> without any effort from my side. Since you need to be jumping through
>> that memory, you'll be looking at pointers - a concept that Java lacks.
>> So I'd be looking at C, or C++.
>
> Let's just hope that data values are properly aligned, unless you're
> sure your code never runs on anything but x86 CPUs... But yes, it's a
> nice way of accessing files.
It's actually a Sun SPARC chip on Solaris. On my ageing workstation,
with a 500 MHz CPU, the program processes almost 5500 records (1.4 MB, I
think) in a fraction of a second.
>> In C++, you can't have an abstract base class (which for me means
>> without any private members), implement it in another class, and use
>> that implementation whilst pretending it's still the interface. In Java,
>
> Why not? The only place where you need to know what it is that you're
> instantiating is the new call. And that's easily hidden using a factory
> design pattern.
Still a kludge, if you ask me.
>> you can stick that interface in a template class, but my Sun Studio 11
>> compiler started complaining that it couldn't instantiate a
>> vector<PetersClass> because PetersClass was abstract.
>
> Ahh, I see - that's a pecularity of the standard template library in
> that case. What stops you from using a vector<PeterClass*> instead? This
> is probably going to be miles more efficient anyway, because a vector of
> large classes is rarely efficient. You might also be able to get
> around that problem by providing your own allocator class.
But I don't want to have to think about these things! :) Java *really*
is simpler. It just *works*. The run-time compiler is taking care of
optimising anyway, because it's better at it than I am.
> Oh, and BTW: You're using a feature (template classes) that Java lacks
> in the first place...
Whilst Java generics are not exactly the same as C++ templates, it's
quite easy to do something like this:
Map<K extends Enum<K>,V extends List<K>>
which is a one-to-one mapping of one-to-many mappings of a
yet-to-be-named Enum.
- Peter
More information about the music-bar
mailing list