deech said:
Hi all,
I am a C/C++ beginner. I have a strong background in computer science
and object-oriented programming (my degree was taught primarily in
Java and I've used Smalltalk professionally). For a while now I've
been out of the mainstream programming world pursuing functional
programming languages (initially Lisp, now mostly Haskell and Ocaml),
but I want to get back in.
Can anyone suggest a study path for someone with a strong conceptual
base, but lacking in actual coding experience?
Here is a suggestion that you won't see too often, but, in my opinion,
is the real way to master procedural languages like C, and subsequently
object-oriented languages like C++.
First, learn assembly. Assembly language is the ultimate procedural
(imperative) language. It is just a list of instructions that are
executed one after another to produce the desired result.
Write some programs in assembly. It isn't critical which assembly
language you choose, but x86 is probably the most documented, as well as
the most unnecessarily complex. If you can become reasonably proficient
in x86, you can handle any assembly language.
Assembly will teach you some very important fundamentals, if you really
practice it:
- What memory is, and how it is managed
- The separation of code and data
- What is going on "behind the scenes" with high-level languages
- How to optimize things
- That writing good comments is crucial to being able to maintain code
- That writing (and debugging) large programs in assembly is HARD
That last one is the crux. You'll start to notice patterns in assembly,
like, "Boy, I sure do use the combination of the TEST and JNZ
instructions a lot" ... and it might even make you think ... "It would
be nice if someone invented a high-level construct like an IF/ELSE
statement that neatly wrapped all of that up." And fairly quickly,
you'd see exactly where those C constructs came from. A few guys got
tired of doing things in assembly over and over, and invented C.
You'll then have no problem understanding C as a nearly 1-to-1
translation from assembly. That's exactly what it is. After managing
memory yourself in assembly, concepts like "malloc" and "free" in C will
be a piece of cake. And even more general things, like pointers (which
cause many a college freshman TONS of grief) will be trivial to
understand.
Making the leap from C to C++ is not much more difficult than the leap
from assembly to C. The same concept of invention applies: A few guys
got tired of writing the same types of things over and over in C (linked
lists, binary search algorithms, hash functions) and decided to package
it all up in a conceptually new language. Hence, C++ and the STL were
born.
I can't really give you a time frame for that progress, but I can say
that time spent at each "level" of understanding (assembly -> C -> C++)
is time well spent. Don't rush it.
Some will disagree with this approach, but they are simply wrong.
I've been using C since very shortly after it came into existince, and I
can tell you that by having learned it from the ground up -- as opposed
to starting with something very high-level like Java and working down to
assembly like most people do -- has put me far ahead of my peers. I'm
not gloating, it's just that I see my co-workers struggle every day with
things that seem obvious to me, because I have seen the man behind the
curtain, and they haven't.