Advertisement

anyone start with c++ as their first language?

Started by April 17, 2012 03:24 PM
49 comments, last by Stroppy Katamari 12 years, 5 months ago

If they're learning programming for the first time, then yes. Beginners learning Python or BASIC don't learn how the "print" command does what it does, either - they are simply told that "if you go print x, x will be printed to the screen.

&a[*b.*c]->*d is an example of a small piece of code that would take you probably 2 hours to explain to someone who's just starting C++. The same line of code in C# would be a[b.c].d (I think, I don't know as I'd never write that without parentheses. I think it's the address of the value stored in the d pointer of the value of the pointer stored in the a array with the index of the value of the c pointer member of the value of the b pointer. GOOD LUCK EXPLAINING THAT IN WEEK 3). While you might find it unreasonable to present that to someone starting C++, in my first C++ class the first 3 weeks were pretty much everyone in my class going, "well that didn't work. I will try it with a &. Then I will try with a *. Then I will try with a ->," because the concept of pointers and references is super confusing, and required very early in learning C++.[/quote]
You ignored the piece of my post with an example and first hand evidence.


Saying that you can learn one language easily after another because they have similar syntax is like saying flying a jet is similar to driving a car as long as they're both painted the same color.

[edit] And having seen the results of C# programmers actually believing the idea you propose here (i.e. that C++ has similar syntax so it must be easy to learn once you know C#), I can honestly say that this is utter insanity. C# (or Java) programmers coming to C++ without expecting to learn a totally new way of thinking generally write really, really, really, utterly horrible code.

I'd contend that flying a plane would, in fact, be easier to learn having learned to drive a car first. There is more to deal with and they are decidedly different, but a lot of concepts carry over. I don't think anybody is implying that C++ would be easy to learn having started with C#; the implication is that it would be easier than starting with C++ initially.

The point is most software engineering knowledge is language agnostic, so you should start teaching with the simplest language.
Saying that you can learn one language easily after another because they have similar syntax is like saying flying a jet is similar to driving a car as long as they're both painted the same color.


I think it varies from person to person and also depends on how much experience they have obtained with the language they started with. When I learned C++ I already had some experience with Java which made it a lot easier for me. For example, I was already familiar with the concept of classes, operators (+ - * / << >>), functions, inheritance, accessors/mutators and a gazillion other things these two languages have in common, and consequently I read my first C++ book a lot faster than if I had not known Java.

[edit] And having seen the results of C# programmers actually believing the idea you propose here (i.e. that C++ has similar syntax so it must be easy to learn once you know C#), I can honestly say that this is utter insanity. C# (or Java) programmers coming to C++ without expecting to learn a totally new way of thinking generally write really, really, really, utterly horrible code.


I never said it would be easy, I said he would have a good starting point (like I had myself, as I described above). Big difference. Besides that, based on the fact that you think C# and C++ are so fundamentally different that claiming it would be beneficial to know one of them when starting out with the other is "utter insanity", I take it your experience with programming languages in general is more or less limited to the C family (C, C++, C#, Java). Try looking up languages like ML or Haskell and I'm pretty sure it will become immediately clear to you that these language do indeed use a fundamentally different syntax than both C++ and C#.
Advertisement

[quote name='Oberon_Command' timestamp='1336504377' post='4938461']
If they're learning programming for the first time, then yes. Beginners learning Python or BASIC don't learn how the "print" command does what it does, either - they are simply told that "if you go print x, x will be printed to the screen.

&a[*b.*c]->*d is an example of a small piece of code that would take you probably 2 hours to explain to someone who's just starting C++. The same line of code in C# would be a[b.c].d (I think, I don't know as I'd never write that without parentheses. I think it's the address of the value stored in the d pointer of the value of the pointer stored in the a array with the index of the value of the c pointer member of the value of the b pointer. GOOD LUCK EXPLAINING THAT IN WEEK 3). While you might find it unreasonable to present that to someone starting C++, in my first C++ class the first 3 weeks were pretty much everyone in my class going, "well that didn't work. I will try it with a &. Then I will try with a *. Then I will try with a ->," because the concept of pointers and references is super confusing, and required very early in learning C++.[/quote]
You ignored the piece of my post with an example and first hand evidence.
[/quote]

That's largely because I don't see how your example is relevant to my point, which is that code that is boilerplate to the task at hand can be simply explained to the beginner as such until they have advanced enough to learn what it means. I would not say that the example you're citing qualifies as boilerplate. All I see is evidence that all of pointers, arrays, and structures/classes should not be taught too closely together. Your example seems to imply to me that pointers were taught earlier than week 3 in the course you took, which implies to me that your experience was not in a course for people who have never programmed before instead simply but for programmers new to C++. Was that the case, or was this truly an into. to programming course?

Nota bene that I'm not talking about teaching C++ to just anyone - I'm talking about teaching C++ to people who have never before seen a line of code in their lives, which I thought were the people this thread is about.

I'd contend that flying a plane would, in fact, be easier to learn having learned to drive a car first. There is more to deal with and they are decidedly different, but a lot of concepts carry over. I don't think anybody is implying that C++ would be easy to learn having started with C#; the implication is that it would be easier than starting with C++ initially.

The point is most software engineering knowledge is language agnostic, so you should start teaching with the simplest language.


Yes, there are some concepts that translate well. They are, however, to use your term, totally language agnostic. You can just as easily learn Python or Lisp and still understand basics like classes and general software design. Syntax is utterly irrelevant, as is the color of the vehicle you are trying to drive/fly.

I'm not saying that it's bad to learn a language before C++. I'm saying that you need to approach C++ as if it is much more than just "some other language of choice" with a different coat of paint. Otherwise you end up writing a lot of "new" invocations and don't even realize that there exists a "delete" and that, in C++, it is extremely important. More than that, you're likely to think that a bare "new" is OK in general, whereas good idiomatic C++ generally would prefer RAII and smart containers/pointers over ever invoking a "new" by itself. Hell, since I brought up RAII, name another language that is so reliant on that concept as C++. I'm certainly not aware of any. And yet RAII is central to C++ engineering and design.

All I'm arguing is that, if you approach C++ as a really fast car with a different color of paint, you're going to crash that jet an awfully large number of times. Certainly more times than if you come into it with the realization that you're handling a very different vehicle.


I think it varies from person to person and also depends on how much experience they have obtained with the language they started with. When I learned C++ I already had some experience with Java which made it a lot easier for me. For example, I was already familiar with the concept of classes, operators (+ - * / << >>), functions, inheritance, accessors/mutators and a gazillion other things these two languages have in common, and consequently I read my first C++ book a lot faster than if I had not known Java.


As above, I'm not saying at all that there's nothing to carry over. Just advising heavily against the perspective that syntax is the big thing to get over when coming to C++ for the first time.

Compared to the really important differences between C++ and basically any other language under the sun, I'd say the presence or absence of certain squiggly symbols is really pretty irrelevant.


I never said it would be easy, I said he would have a good starting point (like I had myself, as I described above). Big difference. Besides that, based on the fact that you think C# and C++ are so fundamentally different that claiming it would be beneficial to know one of them when starting out with the other is "utter insanity", I take it your experience with programming languages in general is more or less limited to the C family (C, C++, C#, Java). Try looking up languages like ML or Haskell and I'm pretty sure it will become immediately clear to you that these language do indeed use a fundamentally different syntax than both C++ and C#.


You seem to be a bit mistaken about the scope of my programming experience :-)

C# and Java, by the way, are not really what I would consider C-family languages. They use superficially similar syntax in a few notable areas, but they derive very little else from the true heritage of C. This isn't a history lecture thread so I won't bother digging into the genealogy; suffice it to say that Java was originally created with the express purpose of escaping the C legacy in a number of areas. The syntax resemblance to C and C++ (which, I would argue, is basically limited to curly braces and semicolons) was deliberately chosen to psychologically make it feel more familiar to programmers with a C background, but conceptually and semantically they are vastly different beasts. It is precisely this confusion with "oh hey they use the same squiggles" and the idea that "therefore they must be similar languages" that I consider so dangerous.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


Yes, there are some concepts that translate well. They are, however, to use your term, totally language agnostic. You can just as easily learn Python or Lisp and still understand basics like classes and general software design. Syntax is utterly irrelevant, as is the color of the vehicle you are trying to drive/fly.

I thought you were making the point that starting with C++ is better than starting with C#/Java/other. I see what you mean now though. The syntax is definitely a very small part compared to the language agnostic stuff. I'd liken it more to maybe a car and a jet with the same driver's seat. A lot of stuff works differently, but you'd feel a little more comfortable transitioning. maybe...
C++ is quite a heavy language to start off with, there is nothing like diving off at the deep end! rolleyes.gif

I would certainly start with something easier first. I find that object-oriented languages like C# or Java are quite good starting points. But don't forget that choice of language should depend greatly upon what you are trying to achieve. There is no point in learning C++ if you just want to create flash games. And if using a game engine like Unity (for example) then you may be better off learning C# or JavaScript.

On the other hand, if you want to create your own game engine then C++ is a pretty good candidate. With C++ you might even want to consider integrating the fantastic Google V8 engine and then write your game scripts using JavaScript.

C#, Java and JavaScript have various syntax similarities with C++ and they are all frequently referred to as C-like languages.
Rotorz Limited (http://www.rotorz.com)

Check out our latest game Munchy Bunny!
Editor Tool: Rotorz Tile System (for Unity 3D)
Advertisement
As above, I'm not saying at all that there's nothing to carry over. Just advising heavily against the perspective that syntax is the big thing to get over when coming to C++ for the first time.


I think you are underestimating the importance of syntax. Not only does it define the concrete building blocks of the language, it is also the first thing newcomers have to learn in order to actually use the language (which -in extension to my original post- is also why learning C# in advance to learning C++ would contribute to a better starting point).

That said, I know from my own experience that it's sometimes difficult to view a programming language (or the entire concept of programming for that matter) through the eyes of a newcomer like the OP. For example, try thinking about the difference between two calling conventions like fastcall and stdcall. This is pretty straightforward, right? Well, now imagine that you have a person utterly new to programming in front of you and try explaining it to him/her while keeping in mind that every single time you use a word or topic that he/she would not know as a newcomer (instruction pointer, register, parameter, memory address, stack, binary number ...) you would have to elaborate on this as well. I think this would be a good exercise for you as it would probably make you realize just how much knowledge you take for granted when you have been programming for several years.

Compared to the really important differences between C++ and basically any other language under the sun, I'd say the presence or absence of certain squiggly symbols is really pretty irrelevant.


What are these really important differences from a newcomer's perspective?

C# and Java, by the way, are not really what I would consider C-family languages. They use superficially similar syntax in a few notable areas, but they derive very little else from the true heritage of C. This isn't a history lecture thread so I won't bother digging into the genealogy; suffice it to say that Java was originally created with the express purpose of escaping the C legacy in a number of areas. The syntax resemblance to C and C++ (which, I would argue, is basically limited to curly braces and semicolons) was deliberately chosen to psychologically make it feel more familiar to programmers with a C background, but conceptually and semantically they are vastly different beasts. It is precisely this confusion with "oh hey they use the same squiggles" and the idea that "therefore they must be similar languages" that I consider so dangerous.


Well, in addition to curly braces and semicolons I just counted 44 operators in the C++ programming language. Out of these, 39 (88.64%) have the same meaning in Java and the remaining 5 of them are all related to pointers/memory access and does thus not exist in Java. In addition to that, all of the most basic keywords for conditional statements and general control flow (if, else, switch, return, case, for, while, continue, break, do ...) along with the names for primitive data types (char, short, int, long, float, double ...), and the keywords for exception handling (try, catch, throw) have essentially the same meaning in Java.

There is a reason I mention all this. First of all, I hope you will agree that C++ (originally called "C With Classes" by the way) belongs to the C family. I don't know if you are familiar with the scripting technology called Lua, but this library is written in what the developers call "Clean C" which means it can be build with both C and C++ compilers. I am pretty sure you wouldn't be able to do this had they not had a very tight connection between them. Now, as my little 'research' concluded Java (and presumably C# as well) obviously inherits much of its syntax from C++ which is why I place them in the same family, although I agree that compared to C++ the relation between Java/C# and C is more like the one between a son and his grandfather.

Nevertheless, this relation is based on the syntax. From a different and more historical perspective (specifically how machine code stored on punch-cards evolved to assembly language and later on to high level languages) I totally agree that both Java and C# belong in an utterly different family since they in contrast to C and C++ are interpreted languages.

I think you are underestimating the importance of syntax. Not only does it define the concrete building blocks of the language, it is also the first thing newcomers have to learn in order to actually use the language (which -in extension to my original post- is also why learning C# in advance to learning C++ would contribute to a better starting point).


Opening the door is the first thing you have to learn in order to actually drive a car. Does that make it important in the grand scheme of things, or just temporally prior to everything else?



That said, I know from my own experience that it's sometimes difficult to view a programming language (or the entire concept of programming for that matter) through the eyes of a newcomer like the OP. For example, try thinking about the difference between two calling conventions like fastcall and stdcall. This is pretty straightforward, right? Well, now imagine that you have a person utterly new to programming in front of you and try explaining it to him/her while keeping in mind that every single time you use a word or topic that he/she would not know as a newcomer (instruction pointer, register, parameter, memory address, stack, binary number ...) you would have to elaborate on this as well. I think this would be a good exercise for you as it would probably make you realize just how much knowledge you take for granted when you have been programming for several years.


If you're trying to explain the technical details of low-level calling conventions to a newbie programmer, you're a bad teacher. A good teacher would hide the details behind abstractions suitable to the level of understanding of the individual(s) in question, not delve into irrelevant trivia that is far beyond what a programmer at that level should need to care about.

I'm also curious about how much you actually know about me. You're making a lot of highly presumptuous and frankly condescending remarks (first about my breadth of experience, and now my ability to think like a beginner) with seemingly no basis whatsoever. I'm sorry if I struck a nerve by having the gall to disagree with you, but seriously, I'd appreciate it if you quit treating me like a whiny child just because I hold a differing opinion.



What are these really important differences from a newcomer's perspective?


Linguistic semantics. Undefined behavior. Memory management. Exception safety. Common idioms and techniques for solving problems. There are any number of areas in which someone well-versed in Language Foo can arrive at C++ and have a lot of dangerous habits that don't work in the realm of C++. I'd go so far as to suggest that anyone who actually knows C++ to a reasonable level should have no problem finding problem areas that could trip up someone who is accustomed to other languages and their ways of programming.

I think you can pick any two imperative languages (excluding C++) and the differences between them will be less severe than the difference between any given language and C++.



Well, in addition to curly braces and semicolons I just counted 44 operators in the C++ programming language. Out of these, 39 (88.64%) have the same meaning in Java and the remaining 5 of them are all related to pointers/memory access and does thus not exist in Java. In addition to that, all of the most basic keywords for conditional statements and general control flow (if, else, switch, return, case, for, while, continue, break, do ...) along with the names for primitive data types (char, short, int, long, float, double ...), and the keywords for exception handling (try, catch, throw) have essentially the same meaning in Java.


So they have similar syntax. Which I already expressly said. Your point?


There is a reason I mention all this. First of all, I hope you will agree that C++ (originally called "C With Classes" by the way) belongs to the C family.


I thoroughly disagree.

I question how much serious software you've written in idiomatic C and idiomatic C++ if you think they are even remotely the same language family anymore. Yes, you can write many things in C++ which are legal C, but so what?

a = 1 + 3;

Quick! What language is that?

It easily could be one of over a dozen - ranging from very low-level compiled native languages to highly interpreted scripting languages. Just because you can use the same squiggles in one program in one language and then use them again in a different program in a different language does not mean the languages have anything substantial in common.



I don't know if you are familiar with the scripting technology called Lua, but this library is written in what the developers call "Clean C" which means it can be build with both C and C++ compilers. I am pretty sure you wouldn't be able to do this had they not had a very tight connection between them.


Allow me to introduce you to the concept of the multilingual Quine. Google around for more of them, they're really quite cool.

Spend an afternoon dismantling a couple of these - preferably ones that involve three or four languages. Hell, see if you can write a simple one of your own. And then come tell me that syntax has anything to do with how idiomatic code is written in different languages.



Now, as my little 'research' concluded Java (and presumably C# as well) obviously inherits much of its syntax from C++ which is why I place them in the same family, although I agree that compared to C++ the relation between Java/C# and C is more like the one between a son and his grandfather.


That's again akin to saying that Volkswagen Beetles and Fuji Apples are in the same family because they can be found in the similar colors. You're ascribing exceedingly too much importance to the squiggles.



Nevertheless, this relation is based on the syntax. From a different and more historical perspective (specifically how machine code stored on punch-cards evolved to assembly language and later on to high level languages) I totally agree that both Java and C# belong in an utterly different family since they in contrast to C and C++ are interpreted languages.


Neither Java nor C# is interpreted in the canonical sense of the term. Both are, by design, run on virtual machines, with options to compile to native code in certain circumstances.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

I started with C++, still a beginner, and I only recently began learning it "again". My code is messy, and lots of times things could've been done more effeciently from what I have done. With Python (Both the "new" and "old" standard), which I started reading about after discovering C++, was much more forgiving to me, and I did not have as much trouble solving problems in Python. Python helped me grasp subjects that seemed vague to me in C++. But I really enjoy C++, so I chose to continue studying it, and learn about programming concepts through C++ instead of Python, which was much fun as well.

Well, actually, I did mess with a bit of Visual BASIC before I started using C++, but I never really programmed anything in VB - I was a little kid amazed of the drag and drop feature.
I learned C++ and C first. But it isn't really the language that's the big issue in game development, its the game. You can probably make the same game in Obj-C, C++, or Java. "Learning" the semantics of a language and the syntax and all the keywords that "light up" isn't really the skill. If reading a book was all you needed, everyone would be programming. Its basically just taking what you know about the language, and using its ins and outs and features to accomplish your goal, which in games is usually a mathematical goal based on triangles, pixels, verts, etc. "Learning" the semantics of a language is not even half the battle in learning to use it effectively.

C dominates the world of linear procedural computing, which won't advance. The future lies in MASSIVE parallelism.

This topic is closed to new replies.

Advertisement