|
|
Or rather, a tale of two IDEs for two programming languages.
Yesterday I downloaded and installed Visual C++ 2010 Express. (Can you
guess which language that's for?) The installation takes /forever/. It's
one of those programs where you "download the installer" and get a 20KB
file that just runs the downloader for the /real/ installation program.
(Why the **** do people do that?!) Still, at least once it's installed,
it runs fairly fast.
In common with all known IDEs, hitting the "new project" button creates
a project with /way/ more useless boilerplate code than you will ever
need. I mean, it creates about half a dozen source files - two separate
C++ files, three header files, etc. Which is completely overkill just
for implementing Hello World. (It also sets the tab depth to something
like 18 spaces or something equally absurd.)
My C++ is very rusty. Hell, I wasn't even that good in the first place!
But deleting all the unwanted files and starting again from scratch, I
was able to implement Hello World from memory without needing to look
anything up. So that's a good start.
Now for my next trick, a Huffman encoder. In most languages it's
trivially easy to implement, and yet it uses a surprising amount of
language features. And, uh, yeah... I can't implement this. It's the
damnedest thing, I swear I already wrote this code once... but I can't
find it anywhere, so maybe I'm imagining it.
Anyway, C++ employs a manual memory management model. Surprisingly, if
you can get away with using only STL containers, you don't have to know
or care that this is the case. All that template magic neatly takes care
of the problem for you. And that's great.
I made all the usual beginner's stupid mistakes - e.g., passing data
structures by value, and then wondering why my alterations aren't
visible from outside the function. (Most OO languages default to passing
by reference. But then, most OO languages provide automatic memory
management too...)
The real sticking point was when I started trying to use abstract
classes. It seems that you cannot have a variable of an abstract class.
(Because creating that variable would require creating an instance of an
abstract class, which is illegal.) You can only have a variable that
/points to/ such a value. (Because then what it points to can actually
be some concrete subclass.)
That's all fine and logical and everything, but there's a nasty snag:
Now you have to care about memory management. And there's no way around it.
I was eventually able to get the program to produce the correct output.
However, it uses the dreaded "new" operator. In particular, it does
/not/ use the "delete" operator anywhere. In other words, it leaks. I
have literally no idea how to fix this. I can't think of any way of
doing it that won't result in double-freeing objects. That's mainly
because I can't put responsibility for object creation (and hence object
destruction) in the logical place. And /that/ is because I don't have
some of the necessary technical understanding.
I found a reasonable C++ introduction at cplusplus.com, but it doesn't
explain several technical points which I'm unclear on. Does anybody know
of a better resource? (Obviously, a Google search will turn up millions
of results. It's hard to know which ones are /good/ resources, however.)
Having spent a few hours on that, I decided to turn my attention to
Java. Now I've coded fairly extensively in Java in the past, but that
was about 10 years ago. (Jesus Christ I'm old now! >_< ) I still
remember most of the syntax, but I haven't actually tried to /compile/
any code for a very long time. I'm not sure if I'll remember how...
So I downloaded the NetBeans IDE for Java SE. Which immediately told me
that I have to install the Java SE JDK before running the installer.
Gee, thanks for that. :-P You couldn't have made that clearer from the
download page, no?
So, 80MB for NetBeans, another 80MB for the JDK itself, and finally I'm
in business. Now, I'm not saying NetBeans is /inefficient/, but
swallowing 200MB of RAM just because I double-clicked the icon to open
the IDE does seem /just a tad excessive/ to me. Initially I was just
trying to figure out how to work the thing, but as I started to learn my
way around and started trying to actually /do/ stuff, the IDE seemed
unacceptably unresponsive. (Quite apart from visually /looking/ like
something baked by an open source committee rather than being a polished
commercial product.)
Like VS, asking NetBeans for a basic project generates a plateful of
useless code that you then have to waste time deleting. (Apparently
there's an Ant script somewhere too... whatever the hell that is.) It
also sets the tab depth far, far too deep. But unlike VS, it also seems
to /insist/ on incorrectly putting the open bracket on the same line as
the declaration it begins. (This incorrect practise is also common in
C++, and yet I didn't seem to have this problem with VS.) It's easy
enough to manually fix, I suppose.
While VS does syntax highlighting and occasionally pops up a list of
method names or something (usually a few seconds too late to be useful,
or using out of date type information), NetBeans seems a little more
impressive. Oh, it still does syntax highlighting. (With some rather
unhelpful colour choices.) And it still pops up out-of-date method lists
that actually get in the way far more than they help. But it goes a few
steps further.
For example, Java is such a retarded language that the only way to copy
some stuff from one array to another is to manually write a loop. So I
wrote a loop. And a little box popped up saying "manual array copy
detected - replace with System.arraycopy()?" I clicked the button. All
the temporary variables vanished, and were replaced with the above
method call, with the correct source and destination, and even the
correct array indices. I'm impressed.
Or rather, I'm impressed at the IDE. Implementing array copying as a
static method on a general utility class? Yeah, /that/ sounds like
fantastic OO library design! :-P Really, Java? I mean, really? Still, at
least you don't need to use an abstract factory factory to use it. The
syntax is quite straight forward.
Also interesting is that when you call a method, it seems to take a
guess at what variables currently in scope are of the correct type, and
fills that in for you automatically. Handy when it works, mildly
irritating when it doesn't.
Needless to say, Hello World was no challenge at all. Implementing my
Huffman encoder was a little more tricky. When I ran it, I got a null
pointer exception. Amusingly [or not], it is apparently impossible to
make the IDE halt the program at the location where the exception is
thrown. Even in debug mode, it just runs the program, prints out the
exception, and then quits. No way of, you know, inspecting the program
state at the moment of the exception to actually see what the problem
is, or anything like that. In fact, come to mention it, I can't find any
way at all to single-step through the program. VS did all of this and
more. :-P
As always with these types of problems, I eventually discovered that I'd
forgotten to initialise something in the code. (An empty array is of
course /not/ the same thing as a null pointer...) Once I fixed that, it
all worked just fine. If I had had access to a debugger that would
actually tell me which field it was that was uninitialised, it would
have taken seconds to figure out the problem and fix it. It only took
half an hour because I had to sprinkle print() all over the place until
the problem became apparent.
So there we are. I doubt I'd remember much about the AWT (although,
didn't they deprecate that in favour of Swing?), but I can certainly
still write algorithmic code in Java without much ado. Maybe today I'll
try something more ambitious with it. If I can avoid throwing the IDE
out of a window.
(Is it just me? "Net Beans"? It's an IDE. What the /hell/ does that have
to do with networking? The "beans" part I kinda get; everything
Java-related has to be themed on coffee or coffee beans. But why "net"?)
Post a reply to this message
|
|