PDA

View Full Version : What is the best way to learn C++?



erorr404
04-27-2005, 10:29 AM
if you have no prior experience with programming and all you know is HTML, is it best to start learning C++ right away or learn something more basic first, like VB or C?
also, does anyone know any good books about it or online tutorials for beginners?

masterofpuppets
04-27-2005, 10:46 AM
Learn C++ first. Starting with something like VB is useless, since when you start C++ you will have to learn alot of stuff from scratch. Many people start with BASIC based languages because they are easy, but they only make it harder to learn more advanced languages later on by filling your head with BS.

eshbach
04-27-2005, 11:00 AM
i think a good approach would be to learn C++ and JAVA concurrently. a lot of the concepts are the same and they are a little easier to visualize and implement in java. then when you've got a concept down (say, polymorphism) you can easily go to C++ and do it the right way, heh...

Bloody_Sorcerer
04-27-2005, 11:11 AM
going from java to C++ is incredibly hard for such similar languages. which is the key problem; they're too similar. when i code in C++ (native to java), i have absolutely no idea when to use pointers or references, as an example. Personally, I prefer java; all the whining and crying about it being slow is a load of trash. It isn't :)

masterofpuppets
04-27-2005, 11:21 AM
Java IS slow compared to C/C++. It's also buggy as hell.

eshbach
04-27-2005, 11:25 AM
Java IS slow compared to C/C++. It's also buggy as hell.

Yep. I can write you a simple benchmark program in each language and you can run them and see how much slower it is.

and going java to c++ isn't that hard, but i think both at the same time is best. if you don't know when to use pointers or references, it's not the language differences giving you trouble, it's more of a fundamental programming facet you should really try to get familiar with.

cpuz
04-27-2005, 03:33 PM
My idea would be to go to C first, just to be familiar with the syntax.
After you know the main key words, switching to C++ will "just" consist in understanding object. This is a big deal in itself, so knwing C may save some time IMO.

saratoga
04-27-2005, 04:31 PM
Java IS slow compared to C/C++. It's also buggy as hell.

Well yeah I'd hope c is faster then Java, since ones portable assembly with a hint of sytax, and the other's running in a JVM.

I wouldn't say Java's buggy though. The platform is pretty solid, and its great for many tasks, particularly when performance is unimportant. Its also fairly quick for command line apps, and very easy to debug since its all GCed, which is why you see it used for a lot of server apps. Swing is slow as heck though, which is always annoying.

smokey
04-27-2005, 05:32 PM
As a case-in-point regarding the brain hemorage that is 'Java', look at the classic 'Hello World' app. The first program one learns in the language (usually) and it requires the creation of a class. The OOP model (generally speaking) is as applicable to real world problems as socialism. /rant

C++ is usually taught in Colleges and Universities using the same method as any other subject: we tell you how it is 'supposed' to be, and you learn it, whether it's really the standard, accepted method or not. I say, to learn a language, learn the semantics (syntax, vocabulary, etc.) then immerse yourself in it. Just like human languages, computer languages are often best learned if they are the only method available to express oneself. If you're a stickler for a particular language, this makes it hard to learn another (see the parallel to human language), but the end result is usually stunning.

Being as this is your first language, you may not have much to compare the methods and madness of structured programming to. Just try to hang in there through the theory and wrap your mind around the more advanced topics through code examples.

recons
04-27-2005, 06:31 PM
Lots of people say this, but it needs to be said because its true.

Dont worry about learning a language. Learn how to program. Learning proper commenting, and how code actually works, is far more important than learning syntax.
Example, dont learn how to create a for loop in C, learn what a loop is and how it works.

YoupY
04-28-2005, 10:33 AM
I'd start with learning Java first. Code wise it's very alike but Java is a little bit easier to learn cause you don't have to worry about pointers and memory addresses. There are some very good book out there for Java which also learn you the concept op Object Orientated programming right.

Having learned a lot of languages myself (Java and J2EE, C++, Delphi, php, prolog, lisp, asp, c# (and variants like j# en vb.net) normal visual basic) I noticed having the basic structueres learned by Java no programming language is difficult anymore, but every language has it specific libraries...

If you start a to learn a language pay a lot of attention to the structures, like loops (while, for and do while), if and else statemens include the switch and how to use variables and the scope of a var.

When you master these concepts then start learning the principals of OOP, classes, inheritance and polymorfism.

Only after that I'd recommend switching to C++ and get busy with pointers and memory addresses, if you master the things mentioned before you won't have to worry as much when debugging, cuase you grasp the other concepts...

YoupY
04-28-2005, 10:38 AM
Java IS slow compared to C/C++. It's also buggy as hell.

liitle bit :off:

Indeed, but there are native compilers for Java too. It's still a little bit slower, but not as bad as using the virtual machine :D

BTW Check this out: http://www.theregister.co.uk/2005/04/18/azul_kit_out/
I haven't seen something like WebSphere yet written in c++. I think it would hardly even be possible in c++ using a lot of different platforms interfacing with all kinds of backend systems...

saratoga
04-28-2005, 03:47 PM
As a case-in-point regarding the brain hemorage that is 'Java', look at the classic 'Hello World' app. The first program one learns in the language (usually) and it requires the creation of a class

Which is a good thing since Java is an object oriented language.


The OOP model (generally speaking) is as applicable to real world problems as socialism. /rant


What are you going to do? Design a complicated app (GUI, backend, etc) in pure c? I like c a lot, but jeez, right tool for the right job. Inhertence, polymorphism and encapsulation have a steeper learning curve then straight procedural code, but they're invalable tools for writing robust, maintainable and extensible code.

Anyway I started out in plain c. Its not a bad way to go. It also made learning assembly, unix programming and even java/c# pretty easy. It does do some really bizzare things, and to this day I still see c code from time to time that I honestly can't believe actually compiles. My second choice would be either Java or c# since they're modern OO languages that are widely used. Plus they use familar c syntax.

Bloody_Sorcerer
04-29-2005, 05:13 PM
if java is the wretched spawn of satan as you portray it, why did the college board decide to switch AP Computer Science from C++ to it? Also, explain why 1.5.0 is slow, or buggy (neither of which are true). This isn't 1995.

eshbach
04-30-2005, 10:26 AM
if java is the wretched spawn of satan as you portray it, why did the college board decide to switch AP Computer Science from C++ to it? Also, explain why 1.5.0 is slow, or buggy (neither of which are true). This isn't 1995.


They switched because it's easier to learn.

and i'll have identical programs written in Java and C++ by the end of the day, with built in timing function, so you can see how much slower java is.

eshbach
04-30-2005, 12:39 PM
OK, the programs are attached.

CPi.exe - C++ Pi Benchmark
JPi.class - Java Pi Benchmark
MJPi.exe - J# Pi Benchmark

The source code is nearly identical for each with only the required syntax changes being made.

Bloody_Sorcerer
04-30-2005, 01:28 PM
well, did i get schooled or what! java is a whopping -1.4 seconds slower than C++! oh wait, that would be 1.4 seconds faster. backfired, didn't it? (only changes made to this picture was cropping off my second monitor)

eshbach
04-30-2005, 02:54 PM
haha that's wild!

to be fair, i could have optimized the C++ code a LOT, but i wanted to make this a really easy comparison... hmm...

eshbach
04-30-2005, 03:41 PM
ok i recompiled the C++ code with borland rather than gcc, want to give it another try?

Bloody_Sorcerer
04-30-2005, 04:11 PM
hmm, difference of about a second. now CPi takes 42.093... darn compilers :)
basically, all this really goes to show here is that theres not really any speed differences between the 2 languages if you code efficiently :)
only real difference i can find is file size... the java .class is 2 kb and the CPi.exe is 293 kb... then again, that doesnt include all the java runtime stuff so it isnt really a fair comparison.

eshbach
04-30-2005, 05:38 PM
hmm, difference of about a second. now CPi takes 42.093... darn compilers :)
basically, all this really goes to show here is that theres not really any speed differences between the 2 languages if you code efficiently :)
only real difference i can find is file size... the java .class is 2 kb and the CPi.exe is 293 kb... then again, that doesnt include all the java runtime stuff so it isnt really a fair comparison.

i wish i could get my hands on the intel compiler...

yeohhs
05-05-2005, 03:37 AM
if you have no prior experience with programming and all you know is HTML, is it best to start learning C++ right away or learn something more basic first, like VB or C?
also, does anyone know any good books about it or online tutorials for beginners?

Here are some URLs to on-line books on computer programming.

Structure and Interpretation of Computer Programs
by Harold Abelson and Gerald Jay Sussman with Julie Sussman
http://mitpress.mit.edu/sicp/full-text/book/book.html

How to Design Programs
An Introduction to Computing and Programming
by Matthias Felleisen, Robert Bruce Findler, Matthew Flatt and Shriram Krishnamurthi
http://www.htdp.org/

Best Regards,
Yeoh
--

buff
05-12-2005, 09:06 PM
C is better then anything.....specially 'cause thats all I know...... :D
and as a friend once told me, "JAVA SUCKS!"