Programming

Originally posted by Sirp
That's okay: a year later Java still sucks :-)

When I programmed in Java, it just made it incredibly irritating to do all the things you typically want to do in a program. Say you want to store a whole heap of integers, in a long list, populating the list and then perhaps performing operations on it.
I'm kind of a newbie when it comes to java, but I'm not too bad. From what I've heard C/C++ is much better, and beats java in the long run, I think you make java a bit to hard though in your array example. What's wrong with this code:
Code:
int[] a = {1, 2, 3, 4, 5};
System.out.println(a[1]);

It does the same thing, only using the data type int instead of the class Integer. If you dynamically want to add numbers to an int array, the code isn't worse than this:
Code:
int[] b = new int[4];
for (int i = 0;i<b.length;i++){
    b[i]=(i+1)*2;
}
System.out.println(b[1]);
You seem to be an experienced programmer, so you probably have good reasons to not liking java, I just thought it sounded worse than it is when you described it.:)
 
funxus,

The problem with using arrays the way you show is that resizing them (1) takes a for loop, which is horrible to do just to add an item to the end of an array - the code I wrote didn't look nice, but is far better than actually having a (!) loop construct for such simple operations (2) is an O(n) time operation, which is unacceptable in any container. (In simple terms: it's slow).

The entire reason why there's a vector class in C++ is because having to do this all the time is horrid, not to mention terribly inefficient.

Suppose we were writing a program that received incoming network packets. Every time we received a network packet we would log the length of the packet and add the length to the end of the array.

Suppose over the life of the program it received 1,000,000 packets and so had an array of 1,000,000 integers. Given your implementation, it'd have to allocate one million arrays, and copy around half a TRILLION integers around.

The implementation I gave, using ArrayList, would probably make around 30 allocations [1], and copy around maybe 3 million integers.

You could argue that your implementation is easier if you'd like (although I'd disagree, casts are bad, but I'd take one over an error-prone loop), but it's certainly not better with how unscalable it is.

-Sirp.

[1] Actually it's likely Java would have to make a heap allocation every time you called new Integer, so that'd probably be still a million allocations. But they'd be smaller. The C++ implementation, on my compiler and library implementation, makes just 21 allocations, and 1.04 million integer copies.
 
I would certainly NOT recommend books by Sams publishing on C++. Get a real book, like The C++ Primer by Lippman, or The C++ Programming Language by Stroustrup.
I can only say "Too true, Too true". It may be something I dont like about tutorial-style teaching, but claiming that you will be taught C++ in 21 days by copying code out of a book is a whole heap of *10#.

Tell me, is the Stroustrup book too complicated? I have heard heaps of conflicting reviews on amazon.com. Some go to the extent of saying "it is good for beginners", then others say "not for beginners". But then, the same was said for the Kernighan and Ritchie C book. Which says something about amazon.com's reviews...

So, would the Stroustup book be good as a first (real) C++ book? I have already read a simple introduction to C++ (in the form of the appendicies in the back of a sams book - pretty much the only good thing I found in the book)
 
I like Stroustrup, but it is intimidating for beginners.

You might like to try Accelerated C++ by Lippman *if* you feel you know C well. Accelerated C++ will teach you C++ fast, if you know at least one other language fairly well.

How'd I learn C++? Initially off some web site :-)

I later learnt it better with Stroustrup.

-Sirp.
 
Originally posted by MajorGeneral2
Thanks, everyone. Essentially, my purpose is to make games. My main question is "What is a good Freeware language and where can I get it?" C++ is out, because, IIRC, it costs money, I can't find a good site offering Pascal, and other languages either cost money to get the compiler, or don't offer the functions I need. But, then, perhaps the difficulty just comes out of a bad search engine. ;)

C++ doesn't cost anything. You can get a very good and free compiler from either Borland(www.borland.com) or GNU (www.gnu.org). Plus there are several good editors out there.

If you want a good language set search for "DJGPP". For an editor search "Rhide"...

IIRC, Gnu also has a compiler for Windows.


Edit: Didn't realize Lovro's post
 
And I just love to nitpick: I am sure that one can get a C++ grammar for free by just googling, if all you want is "the language"... ;)
 
Back
Top Bottom