Author |
Message |
Jason Novice

Age:41 Gender: Joined: Feb 05 2004 Posts: 57 Offline
|
Posted: Tue Feb 10, 2004 9:28 pm Post maybe stupid Post subject: Taking the plunge? Java to C++ |
 |
|
|
|
First of all, I apologize if this is in the wrong forum. I wasn't quite sure where else to put it. That being said, it's high time I moved on to learning the language that everybody and their brother's brother is using to code their apps with these days. I feel as though I'm very comfortable in Java, and I'm ready to take the plunge into C++. My question is, where to start? Being that there are quite a few resident developers in here with mucho experience in C++ I figured this would be a good place to ask. I don't need to start out with one of those tutorials directed at someone who's never programmed a day in their life. However, I also don't want to start with something that's over my head. So what do you think? Are there any reccomendations as far as docs I should read? I don't mind spending oodles of time reading this and that as long as I'm going to learn something. I've searched around and found lots of C++ tutorials here and there, but I'm not sure of which to actually sit down and go through. And I can't seem to find any tutorials tailored to someone who already knows Java and wants to move over into C++.
Long story short, help me out oh wonderful gurus! :]
|
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:42 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Tue Feb 10, 2004 11:57 pm Post maybe stupid Post subject: |
 |
|
|
|
Since you already know a language, it isn't too hard to move over to another one. My recommendation: Get a good IDE (Visual Studios from Microsoft or if you don't have access to that, something free like Dev-C or Borland C++ Builder) in which you can use debuggers with. Helps a lot.
Start with some basic programs that you know work. Such as a bot for SubSpace. Load it up, and compile it without any changes. Look at how some of the parts work (such as the !help command), and try changing a bit. It shouldn't look too much different than how Java works for you. After a bit of playing with just simple parts, try figuring out how all of the dlls or the exe works.
Read some tutorials. As I don't/havn't in a while, I cannot recommend much more than what googling for c++ tutorial would return.
|
|
Back to top |
|
 |
Jason Novice

Age:41 Gender: Joined: Feb 05 2004 Posts: 57 Offline
|
Posted: Wed Feb 11, 2004 2:05 am Post maybe stupid Post subject: |
 |
|
|
|
Thanks for the info. I didn't think this was Trash Talk worthy? No big deal though, they're your forums so you can move shit wherever you please.
That episode of The Simpsons is fucking great, by the way. :]
|
|
Back to top |
|
 |
50% Packetloss Server Help Squatter

Age:40 Gender: Joined: Sep 09 2003 Posts: 561 Location: Santa Clarita, California Offline
|
Posted: Wed Feb 11, 2004 2:07 am Post maybe stupid Post subject: |
 |
|
|
|
Pick up a good book. Find a book with the least amout of decorations on the front cover, take a look to see if it looks solid and then buy it. Online tutorials are nice, but a book is worth the money and will be handy for a reference.
|
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:42 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Wed Feb 11, 2004 10:17 am Post maybe stupid Post subject: |
 |
|
|
|
Jason wrote: | I didn't think this was Trash Talk worthy? |
Everything is Trash Talk worthy. I just try to keep the other forums more subspace related, while all the non-subspace stuff usually ends up here.
For books, I'd recommend some of the O'Reilly stuff, as I've heard they are good. Go to a bookstore and check them out, but check online prices before you buy. I forget the name of the official Microsoft ones (published by Microsoft Press atleast), but those have always been good in the past.
Just make sure you do not get books based on Windows programming only, or ones based on MFC, as they won't teach you much about C, or atleast very well.
If you'd like some samples of books, I could offer you a couple of pdf's of pages of some. Like maybe 100meg worth?
|
|
Back to top |
|
 |
Gravitron VIE Vet

Age:43 Gender: Joined: Aug 02 2002 Posts: 993 Location: Israel Offline
|
Posted: Wed Feb 11, 2004 2:32 pm Post maybe stupid Post subject: |
 |
|
|
|
If you wish I could fix you up with a nice small book - converted html that'll teach you most of the basics in C++.
|
|
Back to top |
|
 |
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: Wed Feb 11, 2004 4:09 pm Post maybe stupid Post subject: |
 |
|
|
|
i have done this as well, though i didn't do it with a clear nkowledge of either language.
A few pointers to get you started:
Pointers:
Almost everything in java is By Reference (IE pointer-like), which most of C and C++ by value unless otherwise notated with a pointer _________________ Signatures just seem so quaint.
A pdf doc i found somwhere...
c++ for java programmers.pdf - 374.21 KB
File downloaded or viewed 33 time(s)
|
|
Back to top |
|
 |
Jason Novice

Age:41 Gender: Joined: Feb 05 2004 Posts: 57 Offline
|
Posted: Wed Feb 11, 2004 4:12 pm Post maybe stupid Post subject: |
 |
|
|
|
MGB, thanks for the offer about the PDFs, but unfortunately I'm on dialup so 100megs is out of the question.
Gravitron, that sounds great! Whenever you get the chance, either PM me or send me an e-mail with more details.
Helicon, thanks!
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Wed Feb 11, 2004 5:14 pm Post maybe stupid Post subject: |
 |
|
|
|
http://www.cplusplus.com/doc/tutorial/
There's your basic C++ tutorial. Helicon's pdf, though, is really better if you're already comfortable with Java.
The only main difference between C++ and Java, as Helicon said something about, is memory management. Java will do everything for you there, but C++ you have to do everything yet it's much more flexible. The two major things to know are.
Declaring a variable with a * after the datatype declares that as a pointer. An & preceding a variable name returns the pointer to it's memory address. A * preceding a (pointer) variable name returns the value in that memory address.
A sample:
int value;
int *pointer = &value; //Now pointer is the memory address of value.
value = 15;
printf("Using value: %d\n", value); //printf() is like System.out.println() in Java.
printf("Using pointer: %d\n"", *pointer); //%d in printf tells the program to display the value after the comma as a decimal (replacing the %d) |
That should output:
"Using value: 15"
"Using pointer: 15"
OK, hope you understood that, I jumped around a little.
Your major resource here will be the MSDN library, which will either come with Visual Studio or you can get it on the web. I'd say first look up printf() in the library, as it's use is rather complex to most functions. _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
|
|
Back to top |
|
 |
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: Wed Feb 11, 2004 6:42 pm Post maybe stupid Post subject: |
 |
|
|
|
oh yes, and java has a garbage collector. Once your vars go out of scope, they are deleted automagically.
in c++ , you have to trash your objects manually with delete.
if anybody has 100 megs (or less) of good material, please let me in on it. I do this often, and literature is always welcome on my hard drive.
|
|
Back to top |
|
 |
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: Wed Feb 11, 2004 6:49 pm Post maybe stupid Post subject: |
 |
|
|
|
more junk:
this is not all 100% accurate, but it should help you find the floor to stand on
package == namespace
IE
System.out.println("test"); |
~equals
std::cout << "test" << std::endl; |
note that std::endl is the end of line character and that
std is a namespace:
std::cout == System.out
header files might be a bit tougher to explain.
anyone up to it?
Blurb:
The fact is that C++ is often more lenient in how you get something done, and how it looks in text.
Stick to as many of your java habits as you can as far as syntax is concerned. Purists may look down on you, but the fact is that 50% more people can read code that looks like java, even if it is C++
|
|
Back to top |
|
 |
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: Wed Feb 11, 2004 6:54 pm Post maybe stupid Post subject: |
 |
|
|
|
50% Packetloss wrote: | Pick up a good book. Find a book with the least amout of decorations on the front cover, take a look to see if it looks solid and then buy it. Online tutorials are nice, but a book is worth the money and will be handy for a reference. |
decorations... two words, squirrel and snake:
Practical C++
Learning C++
buy them used, or get them in pdf. They aer expensive, and they are worth it
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Wed Feb 11, 2004 8:40 pm Post maybe stupid Post subject: |
 |
|
|
|
Well namespaces and header files kind of combine to form packages.
In C++, to use built in functions, you include what are called 'header files'. It's like importing packages in Java. For example, printf() which I was talking about before is included in 'stdio.h'. You can include a file with: #include <headerfile>. For example, to include stdio.h, you'd use "#include <stdio.h>".
When you look up functions you want in the MSDN library (or any other one), it'll usually tell you which header file the function is included in.
Another word about dynamic memory:
Although C++ does make dynamic memory more complex, you have to use it a lot less. Classes in C++ are declared just like variables, without using the new operator.
|
|
Back to top |
|
 |
Jason Novice

Age:41 Gender: Joined: Feb 05 2004 Posts: 57 Offline
|
Posted: Thu Feb 12, 2004 12:27 am Post maybe stupid Post subject: |
 |
|
|
|
I absolutely fucking love garbage collection. Memory management is what's kept me from picking up C++ for so long, although it's probably not that difficult at all and I just haven't bothered reading up on it enough.
Thanks Helicon and Cyan. I really appreciate all the various tidbits of info. Now I just have to start writing some of those basic, boring and generally useless programs one writes whilst learning a language!
|
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Thu Feb 12, 2004 3:06 am Post maybe stupid Post subject: |
 |
|
|
|
i love c++, but ive begun to love java more because of the statements before, about how java handles memory much nicer, ie: garbage collection; it has a string class by default where in class we didnt need to write one up :X lol.. and in java we were taught how to make visual forms w/ it...
i know its possible w/ c++ but i guess im just biased on what i've been taught knowledge wise.. but in the long run c++, good stuff.. _________________ Performance is often the art of cheating carefully. - James Gosling
|
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Thu Feb 12, 2004 9:28 am Post maybe stupid Post subject: |
 |
|
|
|
C++ has garbage collectors too, they just aren't built in. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me
|
|
Back to top |
|
 |
50% Packetloss Server Help Squatter

Age:40 Gender: Joined: Sep 09 2003 Posts: 561 Location: Santa Clarita, California Offline
|
Posted: Thu Feb 12, 2004 2:27 pm Post maybe stupid Post subject: |
 |
|
|
|
just deallocate the memory you allocate. No need to have something do it for you, its simple
int *bob=new int;
delete bob;
|
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Thu Feb 12, 2004 3:59 pm Post maybe stupid Post subject: |
 |
|
|
|
yeah what about setting up a pointer to a variable; and if you delete the pointer and not the actual memory variable it was pointing too, it creates a memory leak that way?
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Thu Feb 12, 2004 5:02 pm Post maybe stupid Post subject: |
 |
|
|
|
It's really just bad programming habits that cause memory leaks. As 50% said, if you delete your allocations, you're fine.
I personally like C++'s pointers better than Java's because it gives you more flexibility. (I know, I'm weird )
|
|
Back to top |
|
 |
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: Thu Feb 12, 2004 5:15 pm Post maybe stupid Post subject: |
 |
|
|
|
Cyan~Fire wrote: | I personally like C++'s pointers better than Java's because it gives you more flexibility. (I know, I'm weird ) |
i like pointers, too
and i like linux
i guess i'm just a control freak
|
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Thu Feb 12, 2004 5:48 pm Post maybe stupid Post subject: |
 |
|
|
|
i love pointers also; makes life a lot easier just its a pain sometimes when ur brain dies on ya and you are thinking it made a copy instead of a pointer :/ lol.. yea im just strange like that.. cause yea
|
|
Back to top |
|
 |
ExplodyThingy Server Help Squatter
Age:38 Gender: Joined: Dec 15 2002 Posts: 528 Location: Washington DC Offline
|
Posted: Thu Feb 12, 2004 7:28 pm Post maybe stupid Post subject: |
 |
|
|
|
Java makes lazy coders, way too much possibility for failure. For example:
Bleh.toString().charAt(Bleh.toString().length()-1);
What if toString, charAt, or length() returned null? It would die, poor coding. In C, this is invalid  _________________ There are no stupid question, but there are many inquisitive idiots.
Loot
Dr Brain> I hate clean air and clean water. I'm a member of Evil Conservitive Industries
|
|
Back to top |
|
 |
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: Thu Feb 12, 2004 8:12 pm Post maybe stupid Post subject: |
 |
|
|
|
ExplodyThingy wrote: | Java makes lazy coders, way too much possibility for failure. For example:
Bleh.toString().charAt(Bleh.toString().length()-1);
What if toString, charAt, or length() returned null? It would die, poor coding. In C, this is invalid  |
there are great C programmers and great Java programmers.
This is the work of neither.
Unfortunate for your argument, the capacity to fuck up is so much more powerful in C and C++ than in java, that, despite the fact that java programmers may be "lazy" as you say, they tend to produce solutions faster with fewer damages.
And by the way, many great programmers don't confine themselves to one language!!!!
Languages aren't cults, they are tools!
|
|
Back to top |
|
 |
ExplodyThingy Server Help Squatter
Age:38 Gender: Joined: Dec 15 2002 Posts: 528 Location: Washington DC Offline
|
Posted: Thu Feb 12, 2004 8:48 pm Post maybe stupid Post subject: |
 |
|
|
|
Well, that was just an absurd example. Fro my experiences in the world, you can tell who learned to programe from what. For the most part:
Lazy methods are done by those who learned on Java. Absurd methods are done by those who learned on PERL. Unnecessarily streamlined methods are done by those who learned on low level languages. Fast but often unexportable methods are written by those who learned on C/C++.
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Thu Feb 12, 2004 10:05 pm Post maybe stupid Post subject: |
 |
|
|
|
Explody wrote: | Absurd methods are done by those who learned on PERL. |
So true.
Lol, but yeah, I always tell all my Java-freak friends that Java is for lazy people, and they don't understand. :'(
|
|
Back to top |
|
 |
|