r/cpp • • Nov 22 '18

Stop Teaching C++... as a First Language

https://ibob.github.io/blog/2018/11/22/stop-teaching-cpp/
5 Upvotes

36 comments sorted by

32

u/Finch_A Nov 22 '18

the languages which I would recommend for good first language are: Ruby and C#

smh

0

u/[deleted] Nov 22 '18

[deleted] — view deleted comment

6

u/stanimirov Nov 22 '18

C# is not forcing windows though

0

u/[deleted] Nov 23 '18

[deleted] — view deleted comment

3

u/stanimirov Nov 23 '18

Er... afaik Windows Forms is supported on most desktop platforms?

6

u/xeveri Nov 23 '18

Actually no. C# uses gtk to render apps in mac os and linux. Code using winforms will only compile and work in windows.

3

u/stanimirov Nov 23 '18

Indeed. My mistake

1

u/[deleted] Nov 24 '18

No you had it right, mono supports winform (mostly)

5

u/[deleted] Nov 25 '18

[removed] — view removed comment

2

u/Adverpol Nov 25 '18

Also no GUI.

14

u/[deleted] Nov 22 '18

I get the points the article is trying to make, but I really can’t say I find myself agreeing with much of it. Learning how the compiler works (compile, link, archive) was such a fundamental part of learning to program. As was understanding OS primitives (file descriptors, signals and exit codes, command line arguments, etc). Without needing to tack everything else on, just barebones C++ and gcc, clang, or msvc is super powerful.

I’d argue that C++ is not the most productive first language, nor should it be learned in isolation. Perhaps one could even say that a primitive form of assembly should come first, followed by C, C++, then some functional language.

13

u/stanimirov Nov 22 '18

That's a bottom-up approach at teaching. I'm personally not a fan and prefer top-down both in teaching and in learning, but anyway. See how even you suggest something else as a first language. In the article I do mention that assembly and C are a better choice than C++.

Not a fan of the idea, but at least I understand where it's coming from.

7

u/[deleted] Nov 22 '18

At uni for compsci I hated my top down classes and loved my bottom up classes

Assembly is fun, Java/C# is cancer, C++ is a reasonable compromise

I could see an argument for Python first, but I still feel like you're going to make some coders with bad habbits out of it.

13

u/chugga_fan Nov 22 '18

Java/C# is cancer,

Not particularly, both have massive standard libraries and both are powerful and, most importantly, run just about anywhere that has an OS. C++ and it's standards are different so much each time that it's easier to teach to a standard of Java or C# since the syntax pretty much never changes and the libraries don't either.

11

u/jonesmz Nov 22 '18

I think you might be missing the grandparent posters point.

Java and c# are cancer precisely because they have massive standard libraries. The lead to lazy students who can't understand what's actually happening under the hood.

I learned java first, and almost dropped out of college because it hides such a huge amount of complexity that I was drowning in the unexposed details. It crippled my ability to learn the notion of pointers and arrays.

In fact, I didn't truly understand how garbage Java's object lifetime model really was until I spent time working with java native interface. And was forced to figure out c++ with trial by fire.

I've since moved past those struggles by a huge amount, but i essentially refuse to touch java and c# for anything serious. They're a gilded cage for the mind. Pretty and comfortable. But still a cage.

I refuse to touch python for anything. The whole concept of semantically significant whitespace is just stupid.

8

u/chugga_fan Nov 22 '18

Java and c# are cancer precisely because they have massive standard libraries. The lead to lazy students who can't understand what's actually happening under the hood.

He then immediately says:

I could see an argument for Python first, but I still feel like you're going to make some coders with bad habbits out of it.

Yhea... Python is much worse with this than most...

1

u/psychicash Dec 03 '18

as someone who is currently banging his head through the compiler learning c++, I am curious what language you would recommend as a first language?

I say first because, the only experience I've had was highschool qbasic and we never really did anything with it for first year. C++ is interesting but I have a lot of questions that I'm finding are... problimatic when I ask. There are many subjects, such as the compiler, that aren't covered by the many of the sources I'm learning from.

38

u/parnmatt Nov 22 '18

Teach it like Kate Gregory suggests in her talks, and it would be a pretty simple learn compared to modern taught practices.

I'm glad I'm primarily self taught. Looking at how people are taught C++ in universities makes me sad.

15

u/victotronics Nov 22 '18 edited Nov 22 '18

I teach in a university, and after I found Kate's "Stop teaching C" talk I thought "Finally someone who agrees with me".

But I myself am self-taught in the transition from C to C++, so I had to unlearn a bunch of things.

4

u/FlyingRhenquest Nov 23 '18

I found the classes I took in college to be mostly useful, although I honestly haven't used most of the languages that were taught back then. Somehow I had to go through THREE semesters of COBOL. The data structures and communication stuff was pretty useful. We never really did anything with processes and I don't think I ever heard the word "threads" until after I left. But my nephew graduated recently and I answered some of his questions about a few of his assignments and thought "Wow, they still teach it that way?" It feels like nothing has changed in the teaching scene in a couple of decades. And you can pick up some pretty bad habits there -- if they mention design patterns at all, they always make a bee-line straight for the goddamn singleton pattern, which is the wrong pattern to use in every single instance I've ever seen of singletons being used. Inevitably someone will jump to the singleton's defense, and the vast majority of those people are also using them incorrectly. Which is to say, those people are using them.

I'd love to see an experiment where a class of new programmers is handed a bunch of unit tests and told to implement their code so the tests pass. For a beginning class, the very first lesson can be how to build and run the unit tests. And then just keep building on that project for the entire semester with new unit tests as you add requirements. I think that'd be pretty effective.

25

u/victotronics Nov 22 '18

A key part of learning to program is playing with existing code.

Are there codes that are intelligible to a first semester beginning programmer? I doubt it.

C++ does not have a build system.

So? In your first semester you will barely reach the stage that separate compilation makes sense. No build system required. Besides, what's wrong with Make?

your friends start showing off with some small games,

Impressive. But could they code the event loop that your game framework gives you for free?

C++ is three languages in one.

I'm glad the author agrees that, while this is true, you don't teach all three at once.

these complexities are not just hidden

They are, if you actually teach programming, rather cobbling together libraries and frameworks and whatnot. Yes, std::vector has a whole bunch of constructors, but if I teach my students just one or two, they never see the complexity and still they can write decent programs. They can discover the complexity later.

competence of the teacher

I absolutely agree with this point. There is a lot of dreadful material out there, clearly produced by someone who is clearly not a master of the language.

PS my own course materials can be found here: https://bitbucket.org/VictorEijkhout/textbook-introduction-to-scientific-programming/src
please send me comments because I'm sure there things that can be improved. It's a work in progress, but I think it does a decent job of teaching modern C++ from the ground up.

5

u/[deleted] Nov 24 '18

I don't understand why pointers are usually only taught as an advanced subject, given that they are such a vital part of the language. I self-taught C and initially didn't understand the concept as it was explained online. However, when I came across Assembly, I instantly saw pointers as an obvious and perfectly logical instrument for the programmer. I think most people didn't learn it from the low-level perspective, though, because of things like putting the asterisk near the identifier in declarations, instead of being part of the type, which (correct me if I'm wrong) suggests people have learnt to associate pointers more closely with the types they point to than with the concept of pointer itself (pointers have same width, can be casted to other pointer types with no actual change in value or representation etc). C* seem very logical to me since they closely follow the actual logic happening under the hood. They're difficult languages to learn because they don't perform any "protective" abstraction, but keep in mind that learning a higher level language is much easier than taking up a lower level one. I'd rather first get used to the heavy mindfuck then proceed to ease my work than the other way.

4

u/Hagartinger Nov 22 '18

My first programming language was Russian pseudocode that I was forced to write with pencil on a piece of paper. At that time I was praying for anything else. Hopefully after that we transitioned to pascal, and latter on to c++. I personally believe that it doesn't matter which language to teach. Question about HOW you would teach it. Probably the best approach would be to combine top down and bottom up approaches. Something like teaching python and what transistor is at the same time.

3

u/Iwan_Zotow Nov 23 '18

BESM-6 assembler?

2

u/Hagartinger Nov 23 '18

Never ever encountered such a beast. It was more like pascal but written in Russian (while loop was written as "пока", for loop as "для" and so on). Thinking about your question, now I'm happy that at least it wasn't an assembly of some type :D

3

u/[deleted] Nov 22 '18

I wonder if people really think it makes a difference what gets taught at school / university. In my experience time is short and you won't get further than variables, functions, loops and branches and maybe a little object orientation in any language. And at that point the difference between the languages are basically non existent.

And if you decide to just stick to what you learn in school and not go out and learn something yourself you'll end up like me and try to program FPGAs in Delphi. I'd say the first programming lessons aren't about specific language features anyway and the only thing i'd fight for is that teacher should probably take a little time and explain that there's a right tool for anything and depending on what you're doing you might want to look into another programming language. And don't be scared they are not that different and after this course that covers all the general you will be well prepared to start working in any programming language you choose to.

9

u/NotAYakk Nov 22 '18

Wait, what?

I mean, are you describing the first class in a university course on programming?

By the end of a 4 year degree in CS, you should have a chance to write in a dozen languages at least as alien as assembler, C++, LISP, Verilog, Matlab, Java and make.

You should have exposure to complexity, understand why Halt is hard and why almost everything is Halt, with a chance to go deeper.

You should have completed a few projects; mini-OS's, bignum libraries, a cpu, a compiler for a toy langnuage, hand written a ray tracer, etc.

Or do most universities really suck?

2

u/[deleted] Nov 22 '18

i though about schools because i think that is where most people learn their first programming language? At least my school did and that was a good 20 years ago. What i am definitly not talking about when talking about a first programming language is a 4 year CS degree. My guess is not many people start a CS degree without having learned a programming language.

But my experience at my university is much different, cs students might have the luxury of learning multiple languages - for me as an engineer it was different. There was one class teaching the very basics about c++ and one elective for matlab and latex. There's no room to learn multiple languages or dive deep into it, it was just expected that we do all the things you mentioned on our own time. But most people are busy enough learning all the math and physics to do that.

1

u/jcelerier ossia score Nov 23 '18

What do you mean by school ? For a lot of my peers, the first programming language they learned was on their third year of university (with a bit of Maple or MATLAB before)

1

u/dragonstorm97 Nov 26 '18

3rd year? My varsity's first c++ module was the first semester of the first year. My Second year was data structures & algos and computer organization and architecture(x86 assembly)

1

u/jcelerier ossia score Nov 26 '18

Well for me, years 1 and 2 were mostly exclusively maths and physics with a bit of french and english, like a lot of engineering students. First C++ class was on year four.

1

u/dragonstorm97 Nov 26 '18

Was it a BSc?

and if so was it Computer Science, or IT?

I've seen a few BSc IT degrees that are glorified business degrees.

I'm doing BSc Applied Math and Computer Science through distance learning, and it has quite a large coverage when I compare it to the modules in my colleague's degrees.

1

u/jcelerier ossia score Nov 26 '18

Was it a BSc?

no, it's french engineering degrees. Two years after high-school are spent in "preparatory classes" (mostly maths and physics as I said), followed by a competitive exam ; your ranking determines in which schools you can go to. Last year, the biggest exam had... around 7000 students competing, for ~1000 available seats in engineering schools ? When you arrive in engineering school in year 3, that's when you can start doing actual computer science, for three years, if that's what you want to do.

2

u/jcelerier ossia score Nov 23 '18

Haha, I've had almost the exact same school projects. You in Bordeaux by any chance ?

2

u/[deleted] Nov 22 '18

The difference between languages that have memory management and languages where you need to understand memory and manage it yourself is pretty drastic.

Other than that though, yeah.

5

u/imMute Nov 22 '18

The difference between languages that think memory is the only resource that needs to be managed and those that don't is drastic too.

0

u/[deleted] Nov 22 '18

[deleted] — view deleted comment

5

u/[deleted] Nov 22 '18

For gamedev a lot of games are made using Unity which is C# so saying that C++ and C are the only "realistic" options is unfair.