If, in removing some functionality, you can cut the number of bugs by
eye-popping amounts, I would consider it better.
I presume you're referring to manual memory management and pointer
arithmetic as the tools that Java lacks to make it "less functional".
No.
It's amazing to me that Java enthusiasts/apologists have so much
contempt for things they can't seem to master. Moreover, those same
things are the first thoughts that pop into their heads whenever
someone mentions C or C++.
What Java lacks that limits its utility with respect to C or C++ is
the ability to overlay a logical view of structured data at an
arbitrary memory location. This ability is the single feature of C
and C++ which makes them strictly more powerful than Java.
[C and C++ union types are not types in their own right but merely
convenience syntax for overlaying views of multiple data structures at
the same location.]
Java doesn't have any equivalent. The often recommended nio.Buffer,
ByteBuffer, MappedByteBuffer, etc. are severely limited and offer only
some of the functionality of a union type.
First, there is no way *reliably* to obtain an arbitrary location
mapping on memory. Not all systems will support such mappings and
even if a particular platform does support it (e.g., Linux's /dev/mem,
/proc/<ID>/mem, etc.) there may be in place security protocols in the
JVM and/or host system which will prevent it.
Second, Java provides no way to determine the offset of a particular
data field within an object. The physical layout of an object in
memory is implementation dependent ... only the JVM knows how to find
an object's data fields. So even if you could get a reliable location
mapping, you still could not overlay ByteBuffer views of different
objects on it. Working within Java, you can achieve unions of only
the primitive types.
[Of course, you can achieve a union using JNI, but then you're
cheating by going outside the language ... not to mention that you'll
end up coding in the very language that Java was supposed to have
improved upon.]
In contrast, both C and C++ do guarantee the order of data fields in a
struct. Field alignment padding is implementation dependent, but
virtually all compilers allow unaligned/unpadded structs if desired.
Both C and C++ provide the standard macro offsetof() for determining
the offset of a data field from the beginning of the structure. Thus
you could directly access a byte buffer containing an instance of a
struct without overlaying a view of the struct on the buffer.
Moreover, C#, which lots of people accuse of being a clone of Java,
also has the ability to overlay data structures on memory.
Not necessarily. I may not easily be able to express exactly how long I
want this Java object to last, but it's not a feature I use very often
when I have that capability.
So what? C++ has this feature called a "library" that, among other
things, allows you to use functions that you didn't write.
Among the many "libraries" that are available for C++ there are ...
OMG! Garbage Collectors ?!? Not refcounting hacks ... real
collectors from names you might actually recognize - that is if you
know anything at all about GC.
Guess what? C and C++ programmers don't have to manually manage
memory unless they want to. True, GC is not a *standard* library ...
yet ... but, you see, there is this thing called the World Wide Web
and it has a thing called "Google" that finds non-standard libraries
for you.
Searching Google with "C++ garbage collector" you will immediately
locate the best known and very well respected Boehm-Demers-Weiser
collector.
http://www.hpl.hp.com/personal/Hans_Boehm/gc/
Searching Google with "C memory management library" you will find
others, some of which are just as good as BDW.
The world doesn't need a One True Programming Languageâ„¢ which solves any
problem under the sun -- what you get when you try that is an unholy
kludge of a language which has surprisingly little compiler
interoperability, is truly understood by almost nobody, and which
requires style guidelines to limit you to a strict subset of the
language to be usable in production code.
This is bullshit.
There are languages that offer power fully equivalent to C++ but which
are cleaner, safer and easier to use. Some of them are OO, some are
functional. Almost all have built-in GC.
Java is not among them.
Instead, it is better to have multiple languages which work very well
for their design goals and are reasonably interoperable between each
other.
Finally a reasonable statement that I can agree with.
For example, you can call C code from pretty much any language,
and some dynamic languages even have modules to allow you to dynamically
call C code ("ctypes").
Haven't you been arguing all along that nobody should be using C?
FWIW: I don't give a rat what language anybody chooses to use. What I
do care about is that comparisons made between languages be fair and
include ALL the relevant information so that people unfamiliar with
them are not drawing erroneous conclusions from unsupported claims.
George