r/programming • u/stanimirov • Nov 24 '18
Stop Teaching C++... as a First Language
https://ibob.github.io/blog/2018/11/22/stop-teaching-cpp/9
u/Visticous Nov 24 '18
Stop Using GitHub... As a Blog Platform
8
20
u/nikomo Nov 24 '18
Why? Static pages are great, and GitHub provides free hosting for them like a sucker.
0
Nov 24 '18
[deleted]
11
16
u/gwaredd Nov 24 '18
I think the premise needs revision, the most effective path to learning depends on context.
Are we talking about a child, a hobbyist, a student someone looking to become a professional programmer? What kind of background do they have already, what are their goals, how much time will be invested?
Without the context, opinion lacks perspective :)
The said, what does C++ offer? You are as close to the hardware as you can get (in any practical sense), you learn about the fundamentals of the machine (pointers, memory management, data representations, bit operations etc). These fundamentals put you in good stead when working with the abstractions of higher level languages. Actually, at a lower level even understanding about transistors, gates, adders etc is useful.
Is it the right starting point as a first language? Not for everyone certainly. However, knowing it has made me a better programmer.
Although, learning multiple languages really gave me the perspective. To paraphrase someone smarter than me ...
Language determines not only the way we think but also what we can think about.
17
u/matthieum Nov 24 '18
Although, learning multiple languages really gave me the perspective. To paraphrase someone smarter than me ... Language determines not only the way we think but also what we can think about.
I agree.
I don't subscribe to the idea that students should come out of school ready as "ready-made" software developers.
Instead, I'd rather students came out of school with a good grasp of the basics and a good overview of what's out there. Aim for shallow, but broad. In terms of computer science it means:
Understanding of the full stack: hardware architecture (CPU/memory), assembly, OS.
How native, jitted and interpreted languages are executed.
A taste of various programming paradigms, and their relative strengths and weaknesses: descriptive (SQL, Prolog), functional (Haskell), object-oriented (Small Talk), procedural (C, Pascal), concatenative (Forth), distributed (Erlang), dependently-typed (Idris), designed by contract (Eiffel vs Ada/SPARK), massively parallel (CUDA? Futhark?).
Will the student be able to do anything useful? They should be able to do toy programs.
Will they be readily employable? They'll need some further on-the-job training in the language of choice.
So, what good is it? They'll have a broad overview of what's out there, instead of thinking that programming == Java (or JavaScript). They'll know the world is big, and expanding. They'll be flexible, and able to pick up any new language/paradigm thrown at them quickly.
Of course, this may not be what the industry wants... but it's what the world needs.
6
u/sinedpick Nov 25 '18 edited Nov 25 '18
However, knowing it has made me a better programmer.
There is literally no way you can back this up, nor can you provide proof that learning a different language first would not have benefited you more (like, say, lisp). So why even say it in the first place?
Let me try: Learning BASIC first has made me a better programmer, because it let me focus on structuring my programs and converting brain-logic into code rather than worrying about strange syntax and type systems. See? That's just as invalid as what you said.
4
u/gwaredd Nov 25 '18 edited Nov 25 '18
I didn't say I learned C++ first (that actually was BASIC for the record) nor did I say I thought it was necessarily the right first language to learn of everyone.
But I stand by the assertion it has made me a better programmer. Also, your statement is neither invalid nor mutually exclusive from mine.
Learning Perl showed me what a dynamic language could do, learning Prolog declarative and Haskell the functional world view. All were important in some way towards my erudition.
Knowing, at a low level, the intricacies of what is going on "under the hood" of the code I write (regardless of whatever environment I am in) helps me write better code and make better technical decisions. That, I feel, is only something I could have got from C/C++ with the occasional bit of assembly.
Sure there are a few other languages that occupy the same space (D?) but C/C++ is by far the most widely used.
You can of course be a great programmer without ever having to know any of this. Most coding jobs in fact don't require this kind of depth. However, a discussion of what makes a good programmer is not particularly fruitful but I suspect breadth and depth of knowledge might come into it.
You can be a fantastic mechanic without ever needing to know about aerodynamics. If you want to be a Formula One engineer though, might be useful to learn.
2
u/trin456 Nov 24 '18
The said, what does C++ offer? You are as close to the hardware as you can get (in any practical sense),
With undefined behavior C/C++ is much more distant from the hardware than one would think.
For example signed overflow is well defined on the hardware with 2-complements, but in C++ the compiler freaks out.
Or null pointers that you cannot dereference. Calling a method is just a jmp with a this pointer in a register. That register could be 0 like any other register, but C++ does not like that at all. It would even be fine to write to a null pointer, catch the resulting signal in a signal handler, and continue as normal.
You could do these things in Pascal.
3
u/alexiooo98 Nov 24 '18
The point of c++ is that because it is so close to the hardware, it cant make certain promises. Signed integer overflow is indeed welk defined when using two's complement, it also is when using one's complement or sign and magnitude. C++ code without undefined or implementation defined behaviour can run on just about any chip that has a compiler.
Of course it doesn't like dereferencing nullpointers, you're asking the machine to fetch the data at memory address zero. That obviously isn't valid. Yes, you could do some checks, maybe even raise an exception, but that would only increase the distance to the hardware.
5
u/trin456 Nov 24 '18
The point of c++ is that because it is so close to the hardware, it cant make certain promises.
The hardware makes the promises. If someone only learns C++, they learn that there are no promises, when they could learn that the hardware uses 2-complement from other languages.
Of course it doesn't like dereferencing nullpointers, you're asking the machine to fetch the data at memory address zero. That obviously isn't valid.
But of course it is valid. Address zero is not special, it is an address like any other address. Only the kernel prevents one from one using the address for security reasons, but it does not have to.
C++ has its own memory model without considering hardware addresses. The compiler probably could define the null pointer to have address 123 if it feels funny
1
u/CptCap Nov 29 '18 edited Nov 29 '18
I agree that standard C++ has a problem with UB.
If someone only learns C++, they learn that there are no promises
I don't agree with this statement though.
Unlike Java or python, C++ is not a platform, as such it can't really make promises because it has to run bare metal on almost every imaginable hardware.
In almost all cases you know the platform (ie: toolchain + ISA) you'll be running on though. If you do you have your promises.
In some very rare cases the compiler will still screw you over and I would like UB to be replaced by implementation defined behavior whenever possible.
C++ has its own memory model without considering hardware addresses. The compiler probably could define the null pointer to have address 123 if it feels funny
nullptrdoesn't have to be zero. Reading address 0 is perfectly legal as long has it is in the range of memory address that your program has allocated1
u/jcelerier Nov 24 '18
So what wording do you propose for overflow, that takes into account both 2's complement, saturation, and gives a single semantic to
i+jwithout introducing additional costs (branches, exceptions, etc) and whatever the machine it runs on.2
1
u/Vhin Nov 24 '18
My first language was ARM. If we're just talking in terms of teaching low level operations, ARM (or any other Assembly language) is more than sufficient. I'd argue that it's significantly more suited to that task than C++, and that the lack of complexity would make it a better first language as well.
59
u/moschles Nov 24 '18
I love C++ and it is close to my heart.
But my rational mind knows that C++ is a cobbled-together monstrosity. In my more honest moments, I realize that my love for the language is based entirely on nostalgia.
28
u/James20k Nov 24 '18
The more C++ evolves the more it becomes somewhat of a disappointment to me (even though a lot of the new features are really neat), the problem is that many features have so many caveats that it becomes difficult to intuit what the correct thing to do is - and unfortunately the lack of emphasis on safety makes it difficult to use a lot of features correctly
EG value semantics are a minefield, getting the best performance often means writing APIs that can be used totally incorrectly and leave dangling pointers everywhere, unless you use it in exactly the way that it was originally intended. C++ offers few API safety guarantees, EG see string_view
Even base facets of the language are annoyingly broken as well, eg integer conversions and promotion rules in general are thoroughly broken, making writing code doing bitwise operations where signedness is important somewhat of a minefield, because c++ absolutely will promote your small integers to something else even though you really don't want that. C++ also lacks strong aliases, bitfields are bad, and std::byte isn't what you want here either, so solutions end up messy for something that c++ should ideally be quite good at
Lambdas are great in a lot of cases but its extremely easy to capture something by reference, let it go out of scope (eg return a lambda), and then call it, by mistake
C++ automatically generated constructor/move/copy/etc rules are... interesting at best, and make it tricky to understand what on earth you're meant to be doing, see this. There's also some fantastic rules in the spectrum of what happens with = default vs {} vs = default defined outside the class vs {} outside the class, if i remember correctly
Uniform initialization is the classic example as well of a c++ feature - good in some respects, but decidedly non uniform and complicates understanding how you're meant to initialise things, because there were already too many ways to do that
People often say "well, its unfixable now because C/backwards compatibility", but EG javascript has shown that you can rework language semantics quite majorly and get adoption with something like 'use strict' - keep old code the same, opt in to new code being correct. This also doesn't excuse why some new features are on fire
Don't get me wrong a lot of the new C++ stuff is great, but overall there seems to be a general lack of emphasis on safety, usability or consistency within the entire language which I don't think it can get away with for much longer, with high performance safe languages like rust coming about. It very much feels to me like c++ is only used simply because there is nothing better
tl;dr its alright
1
u/vytah Nov 25 '18
Even base facets of the language are annoyingly broken as well, eg integer conversions and promotion rules in general are thoroughly broken, making writing code doing bitwise operations where signedness is important somewhat of a minefield, because c++ absolutely will promote your small integers to something else even though you really don't want that.
I've learned recently that multiplying two unsigned shorts (even though unsigned numbers are supposed to overflow nicely) can be undefined behaviour:
27
2
u/pixelrevision Nov 24 '18
C++ has a lot of features that solve a lot of problems for people who have been programming C/C++ for years. Makes it really hard as an entry point for someone just being exposed to a programming language.
Features like classes, generics (templates) and lambdas are all subjects that can have a bottomless pit of theory and complexity behind them. Introducing them at the same point as malloc makes it really hard to know what to focus on and what is important to dig deeper on.
-16
u/shevegen Nov 24 '18
We can admit the truth - C++ failed to seriously evolve.
12
u/spreadLink Nov 24 '18
You can critize a lot about c++, but that it didn't evolve ain't one of those things.
If anything, you could argue it evolved too much
1
u/Saefroch Nov 24 '18
IDK about that. C++ doesn't evolve as a whole, it's more like the language grows new parts that seem evolved except they contort in fun ways to be backwards-compatible. For example: floats are
TotallyOrdered(yay concepts!) so that you can sort them, except that floats are not totally ordered and it's UB if you try to sort a container with NaNs in it.-2
18
9
u/michael0x2a Nov 24 '18
Whenever these sorts of discussions come up, I think it's pretty important to talk about exactly a) who exactly your target student audience is and b) what, fundamentally, you think is important for them to learn.
For the former, I think it's reasonable to assume here that the target audience is either a class of high school or college level students, people who are trying to self-teach themselves how to code, or possibly people who are attending some bootcamp. Not all students fall into this category, but this covers a pretty wide range, I think.
The latter, however, is where a lot of differences of opinion emerge from, I think.
For example, I personally believe that the first and foremost thing all introductory programming courses should teach is the idea of problem solving using code: about how to decompose problems into smaller parts, how to compose together the tools your programming language gives you, and how to make these two meet in the middle to create interesting things.
In some contexts, I also think the other primary goal should be to inspire excitement about computer science: get students who previously might not have cared about CS at all interested in the field. (And establishing a class that has a reputation for being exciting and fun is a great way of doing that).
Anything else is really of secondary important IMO. For example, I don't think it's really important to learn about hardware or about how the computer "really works" at these introductory stages: that kind of stuff should come later. And of course, you also want to minimize the time students have to spend learning about the idiosyncrasies of any given language. All languages have weird quirks, of course, but the fewer the better.
Given all of these considerations, I personally don't think C++ (or C, for that matter) fits the bill: they're just too fiddly compared to other languages that are available. That won't stop many students, of course -- a lot of us grew up on C++ or on objectively terrible languages like TI-BASIC (myself included) and ended up fine. But I do think the curriculum for any kind of class should be designed to target students who are on-the-fence about computer science, not at the students who are already motivated and would have ended up learning how to code whether or not they took a class on it.
I do think, however, that C and C++ are excellent second languages to learn. The next thing to do after learning about problem-solving is to dive into other aspects of computer science, such as the hardware-software interface. Learning C and C++ (and probably assembly) are great ways of doing just that.
However, other people might disagree with everything I just wrote above. They might decide that the most important thing is to focus on explaining how the computer "really works", or on emphasizing the importance of rigor and precision while coding, or on directly preparing students to take a job in the industry. People in the first group might start by teaching C, people in the second group might start by teaching some language that's easier to write proofs about (probably some variant of ML?), and people in the third group will probably teach whatever's trendy at the moment (currently JavaScript?).
And of course, I suspect many people haven't given this any thought at all: at best they think the role of an introductory programming course is just to teach programming, and so they default to suggesting either whatever language they learned first out of nostalgia or just whatever language looks reasonable without thinking about how to scale that approach when teaching many other students (who might have extremely different backgrounds or goals).
But in any case, my point is that it's important to start by clarifying these kinds of assumptions first: the choice of programming language is just one of the many downstream decision you end up making based on the pedagogical goals you set.
44
Nov 24 '18
the languages which I would recommend for good first language are: Ruby and C#
Yikes.
16
u/salgat Nov 24 '18
C# is a great language to start with. It removes a rather complex and large barrier to learning (explicit memory management), comes with a fantastic and very comprehensive library, while also retaining most of the programming language concepts present in C++. I say this as someone who started with Assembly and C in embedded development and worked my way up to languages like C# and Python as my career progressed.
8
Nov 24 '18
Also: C# has Unity. While that may seem dumb, a lot of people get into programming because they like games, and want to make something similar. Unity uses C# in ways that can be as simple or complex as you want, from basic scripting to large underlying systems.
-30
u/shevegen Nov 24 '18
Nothing wrong with Ruby.
I don't understand C# though; and I don't understand the comparison, either.
All "scripting" languages tend to be simpler than C/C++/C#/D/Rust/Java (the latter is not soooo hard but its addiction to verbosity makes it harder than it ought to be - how many write java without an IDE?).
35
u/kankyo Nov 24 '18
Plenty of things wrong with ruby.
5
Nov 24 '18
I think Ruby's a pretty good teaching language, honestly, although it wouldn't be my actual pick. It's similar to Python in that it's quick to get started accomplishing real things (which is good for motivating young students to stick with it), but it also provides a nice bridge between traditional imperative style and functional style when you want to start talking about that stuff. It uses lambdas everywhere and map, reduce, etc operations instead of loops, non-mutating methods by default. Anecdotally, people who only know Ruby take to Haskell/Elixir a lot faster than people who only know a mix of Python, C, and/or Java. That wouldn't be what makes my decision but it's something to note about a teaching language.
2
u/kankyo Nov 24 '18
Mutable strings though.
2
u/iconoclaus Nov 24 '18
That's going to be gone soon enough.
2
u/kankyo Nov 24 '18
Holy hell, won't that be a crazy breaking change?
2
u/iconoclaus Nov 25 '18
For a few years now, Ruby has had an optional interpretation directive that makes Strings immutable. And the linter that Rubyists use, Rubocop, has been preparing the community for it by enforcing a rule to use that directive. So effectively, lots of Rubyists have been using immutable Strings and their projects are ready. Rails is also already immutable string friendly now. I expect the people who are going to adopt Ruby 3 in a couple of years time won’t even notice.
1
1
1
u/dpash Nov 25 '18
Least of all was the lack of native threads, coupled with a global interpreter lock that made any deployment a massive pain to scale. Look at the pain Twitter went through ten years ago. We ended up running multiple processes just to get something resembling performance and Rails never recovered from that fiasco.
I believe you could get better performance from JRuby than Ruby itself.
1
u/sinedpick Nov 25 '18
Replying to shevegen doesn't give you permission to leave terrible comments. List reasons you feel Ruby isn't a good language for beginners.
1
4
Nov 24 '18
I write Java in vim. Javadoc is a thing and fortunately most APIs I need use it. However, most of my peers do use an IDE for auto completion and suggestions.
3
u/Sick_of_problems Nov 24 '18
You should really look into language servers. I have no experience with the java one(or java in general really) but it'll give you code actions, renaming, autocompletion, and other IDE features, right in vim.
1
Nov 24 '18
Nice! This looks like a smart solution that aims to be editor/IDE agnostic while providing support for many languages. I’ll definitely check this out! Thanks!
4
u/DrunkensteinsMonster Nov 24 '18
This is madness. I say this as a Java dev who loves vim, and uses it for everything else. There’s a reason IdeaVim exists
3
Nov 24 '18
IdeaVim is great when I have to collaborate on a project where I’m forced to use an IDE, but I still try avoiding IDEs wherever possible. I just feel more comfortable with my hands staying on the keyboard, not jumping back and forth to the mouse.
2
u/DrunkensteinsMonster Nov 24 '18
No reason to use a mouse if you’re in intelliJ. It’s not as smooth as in Vim but if you care enough you never really need to use the mouse. At least, everytime i thought i had to use it i found that i didn’t
A little inconvenience in learning new keybindings is a small price to pay for all the great features you get
1
Nov 24 '18
IntelliJ is very good about being simple enough where you don’t have to click through buttons and menus constantly. It’s very easy to use and stays out of the way. If I had to use an IDE for Java, that would probably be my first pick.
6
u/rovarma Nov 24 '18
C++ was my first language. Learned it by being told to fix a bug deep in the scripting system of the Unreal Engine, which we were porting to the original Xbox. Good times.
6
u/IndividualComplex Nov 24 '18
The College I work at teaches Visual basic as their intro to CS course. I'd rather they taught Python or C++.
2
Nov 24 '18
Python or C++.
That's quite the contrast. What are your reasons for each of those two?
1
u/jcelerier Nov 24 '18
Is it though ? Modern c++ code, with e.g. ranges, etc can be as high level as python. It's just a matter of using the proper libraries and not clinging to c with classes
1
u/IndividualComplex Nov 25 '18
I've used C++ pretty extensively. Like other people have said in this comment section, learning C++ gives you a good grasp on coding in general.
As for python, that was the first language I learned. I feel it was pretty easy to learn, without glossing over important stuff.
Granted, I'm a 3rd Year CS major...
11
Nov 24 '18 edited Nov 27 '18
I’m tired of this bullshit. There is not and never has been any evidence to support the “X is a bad language for beginners” claim. Dijkstra started it with his remarks about BASIC but a huge proportion of programmers between 30 and 40 caught the bug messing around with TI-8x and 9x BASIC. If you ask actual, working programmers, you’ll get answers all over the map; it has no long term effects except maybe discouraging people who have no interest or passion for programming, and just want learn to write code. And frankly, I don’t think the way the rest of learn should be changed for their benefit. You wouldn’t drop differential equations from the engineering curriculum just so a bunch of people who can’t do math can earn an engineer’s salary, would you?
4
Nov 24 '18 edited Nov 24 '18
Agreed, but for a reason not mentioned in the article. IMO most people learn programming best top-down, meaning throwing memory management at beginners just slows everything down and can cause them to ragequit. That being said you can teach a lot with just stack memory. I also think most introductory data structures and algorithms classes should be very high-level and language-agnostic, and hence not worry about memory management. IIRC CLRS backs me up here, saying early on that it will not concern itself with safely managing an object graph by hand and will effectively assume a managed environment (or at least one where memory leaks are fine)
Obviously sometimes you have a valid reason to teach bottom-up, e.g. if your course/major is computer engineering
3
u/kip9000 Nov 24 '18
First language you learn should get you to think about how to represent the problem you are trying to solve in a good way. Problem with C++ is that you quickly become embroiled in the complexities of the the eco system (header files, compilers, linkers, error messages that are non use friendly) and then the complexities of the language itself (because it was badly designed (not intentionally) for various reasons). Very quickly you will be fighting against the language rather than thinking about your problem or the solution. There are better designed modern imperative languages (D for example). But learning a modern functional language serves much better. This is coming from a 20+ years of experience with C++
3
u/GN8 Nov 24 '18
I'm a mostly self-taught programmer, and I feel lucky to have started with embedded programming. I stayed in the Arduino environment for a while,and kept building up based on things I needed to do. This mean tracking compiled machine code to efficiently bit-bang timed events. Then later, on the same project I realized the major pit-falls of C++ on embedded, as the virtual-function heavy library I wrote to be able to bounce back and forth between AVR and Windows for testing ended up ballooning my code size and memory usage (16 bit pointers are expensive on 16KB RAM devices). Learning close to the metal has helped me be able to visualize what higher-level languages are doing "under the hood" which I find really helpful in visualizing asynchronous events, exceptions, objects and references and inheritance, etc. Of course, I may just be crazy; I also now avoid anything that isn't C-style syntax
5
u/jephthai Nov 24 '18
which make it so much easier
This is the problem. So much pedagogy is trying to find a way to make programming easy. The student might start easy with some other language, but the hard moment will come. It's inevitable.
I don't like the concept of a future where a raft of developers never learned the hard stuff and just took an easy path to get a job somewhere. May as will weed out the bad ones the same way the sciences do it: by teaching hard chemistry and calculus courses right away to winnow the field.
I get the stem advocacy, trying to flush the world with eager new programmers, etc. But we can't lose sight of the inherent complexity of what's involved in coding. It should be taken seriously, and the educational path should not be prioritizing ease as the number one goal.
2
Nov 25 '18
I think there is point in throwing challenge at a time to developers...
Ofc, if we were for fundamentals we might as well start with maths and physics to get them to really understand semi-conductors...
6
6
u/wsppan Nov 24 '18
I personally think programming should be taught from the very beginning. Logic gates, binary numbering and boolean logic and how they are used to control computers to this day. Charles Petzold's book Code is an excellent exploration of these concepts. Then I would introduce assembly and how it's used to speak to a specific platform of computer. And then finally C. By then you are so amazed at the simplicity, power, and how cross platform your code is. At this point picking up any other C like language is a breeze.
0
Nov 24 '18
[deleted]
1
u/Novemberisms Nov 25 '18 edited Nov 25 '18
Just don't dig too deep into how transistors work. At a certain point, it becomes not-very-fun to learn, as the more you get into how transistors actually work, the less they appear to be "clean" little machines, and more like dirty, leaky little assholes that we somehow tricked into doing our bidding despite all odds.
All the neatness that programmers like disappears at a certain level and gets replaced by non-discrete math, differential equations, impurities, some basic quantum physics, and sadness.
I was in the microchip business before I switched to programming. I don't have fond memories of what I had to learn.
1
Nov 25 '18
“and sadness”. That was some awesome insight into your world thank you for sharing. I do find the transistors super fascinating though. I mean we create entire machines that are fucking 7 NANOmeters big like wtf how does that work that’s so cool. I want to be able for someone to plop down some silicon and gold and other metals in front of me and Then i would either be able to create and program a microchip or at least know the machines i need for it.
5
u/Nivekk_ Nov 24 '18 edited Nov 24 '18
Starting with an easy language is a pretty common mistake, and sets you up for a career banging your head on the table as you struggle to understand lower level languages after having enjoyed the cushy simplicity of say, Java.
Someday you will have to work with a lower level language than you started with (unless you started with assembly), and if you're so dependent on your package manager that you literally can't build software in an environment that doesn't have one, then sooner or later you are going to be screwed.
This is where, and I've seen this so many times before, you get a new person coming onto your team who is advocating for everyone to switch over to one and only sky-high language they've ever known, and is completely unable to acclimate to the team. That person may eventually scrape by, but the code they produce will be of the absolute lowest caliber.
-2
u/pcjftw Nov 24 '18
Sorry thats not my experience at all, I started with VB, now it's easier for me to list languages I don't know which are Idris, Prolog and APL
2
u/arylcyclohexylameme Nov 24 '18
I agree wholeheartedly tbh. It's too much to handle at once for a newcomer nowadays. That's not to say it's impossible, but it has a much higher barrier to entry than simpler alternatives that can teach 90% of the same concepts in 50% or less of the time.
0
Nov 25 '18
True, Oberon is a much better alternative. But definitely not the so called "higher" level languages, especially not a shit like Python. The OP is coming to a somewhat right conclusion, but from entirely wrong premises.
2
6
u/tonefart Nov 24 '18
It's fine. Just don't teach the ugly parts.
8
u/kankyo Nov 24 '18
Sooo... eh. What is left?
4
1
u/Holy_City Nov 24 '18
struct This { typename std::enable_if <!is_ugly<This>::value, void>::type { std::cout << "C++ is awesome!" << std::endl; } };0
1
1
4
u/TheCodexx Nov 24 '18
Why are you concerned with teaching package managers for a first language, though?
C++ makes a good first language because it lets you get down to the bare bones of what programming is. Python obscures too much. Java usually means wrestling with an IDE instead of writing code. Assembly is too arcane. Most other languages have idiosyncrasies that are important when described in relation to C++, but in vacuum you have to wonder why those things exist.
Has the author actually attempted to teach anybody, C++ or otherwise?
-1
3
u/sinedpick Nov 25 '18
Did anyone even read the article? The author handles the "But C++ was my first language and I turned out fine" case and yet that's still what everyone's saying.
I'm disappointed by the lack of commenters here to evaluate a situation from a viewpoint that isn't their own. There are many factors that make C++ an objectively bad first programming language aside from its disorganized and confusing feature set, the most important of which is compiler error messages. They are terrible.
C++ is a great second or third language, but can we please not teach beginners a language whose compilers output pages of garbage for one character typos?
-1
Nov 25 '18 edited Nov 25 '18
His viewpoint that beginners must start spitting out "usable" shit straight away is disgusting and does not even deserve any discussion. His view that beginners must be happy to use tons of opaque libraries and frameworks instead of building everything from scratch, from the first principles, is thoroughly disgusting. And he did not address any of the counter points really.
7
Nov 24 '18
Amen! C++ is a very flexible language, but you spend way tool much mental energy thinking about what the compiler is going to do with a particular construct instead of focusing on the application.
4
u/Lower_Cryptographer Nov 24 '18
Not really. Depends on the program I guess, but for schoolwork I never think about that. I just use it because it's faster than Java, so I can be a bit sloppy when it comes to the asymptotic complexity of some cold operations.
2
u/jephthai Nov 24 '18
That kind of awareness is invaluable and only gets more useful as you go. I don't think educational languages should have training wheels.
-12
u/shevegen Nov 24 '18
Yes, this form of micromanagement sucks a lot.
I have to spend my life time into appeasing compilers.
That is no fun.
Shame on you, C++.
0
1
u/MpVpRb Nov 24 '18
My first language was ALGOL, in 1972
Throughout the years, I've learned many more. Today, I mostly use C and C++
It's not about the language, it's about learning to think like a programmer
But, if I had to design a strategy today, it would probably be ..
Python first, it's modern, high level and a good introduction
Then C, and assembly, to teach what's really going on in the machine
Then C++, because it's a really useful extension of C
Then Javascript, because the market demands it
If the teacher is sadistic, Visual Basic, to show how awful programming languages can be
1
u/funbrigade Nov 25 '18
I vote go (sue me) for the following reasons:
Statically typed
Great package support
Fast-ish (not that this matters too much for beginners)
VERY LIMITED oop (and I think the authors would argue it isn't), but enough to teach abstraction concepts like interfaces and encapsulation
Distinction between pointer and non-pointer args to teach copy and move semantics
Really easy to install and setup env
Easy to run tests to experiment with behavior
I could see beginners getting frustrated over having to name things with a certain casing, but that's about it.
None of that necessarily translates to IRL engineering btw; I'm real tired of blindly casting interface{} (just give me generics ffs and I'll shut up I promise) and I have a C# background so unsafe casts like that would be an auto fail in a PR there.
1
u/yashboi123 Dec 20 '18
Personally I think python/html is a GREAT first language. Easy and accessible to code. JavaScript is also a good choice.
1
-10
u/DrecksVerwaltung Nov 24 '18
Most programming snobs who use C++ because it makes them feel don't even real know it either. As soon as they have to read someone elses garbage code with tripple pointers and overriden assignment operator they are gonna curse to the heavens.
And as soon as you see people implement custom memory allocators and similar garbage, you start realizing that C++ isn't even compitable with itself. It can be sort of fun to use C++'s monstrous features like the auto keyword, overwritten operators and other nonsense, but once someone else has to work on it, it all falls apart
-1
Nov 24 '18
Not to get into language wars, but C++ is only faster than Java for very simple programs, as most metrics are. For complex programs, Java is within a very few percentage points of C++'s performance, and often faster. However, having said that, with today's fast processors, language speed is rarely an issue -- witness Python's popularity, despite it's average of 35:1 to 45:1 slowness relative to C++. The faster Python implementations compile to C++ or Java bytecode -- with some small loss of Python-specific functionality.
Even C++'s original authors now admit that insisting on compatibility with C added too much complexity and prohibited many standard compiler/code optimizations.
In my opinion, considering differences in programmer productivity, C++ is usually not worth it. There are a few (mostly small embedded) applications, however, where the context precludes the use of Java.
6
-5
u/Gotebe Nov 24 '18
I’ve seen frustration and desperation even in seasoned professionals trying to incorporate some library with obscure build process in their code
So don't build it yourself, environment will thank you.
Get library headers in your include path, get its object file in your lib path, make!
Plus, in a given Linux distro, that's done for me by the distro maintainers.
-1
u/shevegen Nov 24 '18
Plus, in a given Linux distro, that's done for me by the distro maintainers.
As a general comment that is rubbish.
I have used numerous distributions over the years and I can happily tell that some distribution maintainers are clueless idiots who don't know what they are doing. Others are very good.
For example, having a sane compile chain. I have had ... I don't remember which distribution, but incompatibilities that I could not easily resolve, due to DSO objects, non-use of -fPIC and some strange symbols that are embedded into .so when they should not have been. I think it was either a ubuntu-derivative or some fedora-derivative.
Using slackware or a gentoo-based variant and I did not have this problem at all whatsoever. I still don't know what the other distributions did (I also used LFS/BLFS as reference and it worked for slackware and gentoo just fine, but not for the other two), but whatever the reasons, it was clear that the compile chain was not properly setup for all instances of programs that typically run on a "feature-rich" linux distribution.
Part of these problems have had indirectly to do with e. g. using the most recent glibc, but things such as -fPIC or missing symboles or libraries came from distribution maintainers simply being clueless. So ... no, the "that's done for me by the distro maintainers" just projects hope that is not warranted in all cases. And surprisingly enough, the big distributions often do a MUCH worse job than the smaller ones. I think this has a lot to do with the big distributions catering to Average Joe who won't need to compile, whereas the smaller distributions oftend tend to focus on people who are a bit more knowledgable than Average Joe when it comes to computer systems in general.
-8
u/shevegen Nov 24 '18
Well, let's see it from the other side.
I'll assume that the title refers to C as well, even though it does not; but we know that C and C++ are in some regards similar. C++ just more complex. Both are not easy languages.
I started, roughly, with perl, then php, then ruby. Now at this point, having used ruby for many years, I honestly have very little motivation to WANT to learn C/C++ and use it (though I actually have to for the latter). Things that are super-easy in ruby are needlessly cumbersome in C/C++. Even though C++ got better over the years, it still requires minute telling to the compiler what to do - lots of micromanagement work. The promise is ... more speed, but ruby is more than fast enough for literally everything I do. So I invest my life time here in order to work with inferior languages (compared to ruby) and it is no fun at all.
So when you come from this point of view, there is ONE very important question to be asked:
If you start with another, simpler language, why learn C or C++ altogether?
And I think this is a valid question for MANY other people too. And this is why C and C++ stagnate a lot. Sure, Go and Rust and Swift are alternatives to some extent, more competition coming along, but C and C++ simply don't have the strong appeal that they once have had, for new people coming about. JavaScript also plays some secondary role (JavaScript-first people rarely learn AND use C/C++ - remember that learning C and C++ alone doesn't help, people have to use it too, otherwise the usage rate will go down in the long run).
So while I would not recommend C++, I would actually recommend to start with C. You can pick up any of the better languages such as Ruby or Python in no time, but learning C after you have used the other two is just no fun at all. Yet C is still, in my opinion, the by far most important programming language. (C++ emerged out of C in many ways.)
4
u/stanimirov Nov 24 '18
I think this logic is flawed. You should learn C++ because you make use of its power. Not because you have to. If Ruby is fine for you, then, by all means, stick with Ruby.
Now don't fall into the other extreme: "If all you have is a hammer, every problem looks like a nail". Do learn other languages. See what they can offer. See whether you like that. Maybe you want. Some people hate Ruby. Some people hate C++. One is not objectively better than the other. It's a matter of context and taste. Educate yourself to have the taste and recognize the appropriate tool for the appropriate context.
And a lot of brilliant C++ programmers I know didn't start with C++ (actually a surprising amount of them started with ActionScript). They discovered C++ and knew it was for them based on the knowledge they had already acquired thanks to other languages.
0
Nov 24 '18
[deleted]
62
Nov 24 '18
Don't take this post seriously. C++ is a fine language to learn first. For some reason, programmers love busting their egos out to fight over which is the best first language, not sure why.
21
u/instanced_banana Nov 24 '18
You know what they say, there's those languages who people ramble upon and those who aren't used.
-12
u/kankyo Nov 24 '18
A quote by someone who made a shit language. Of course he'll justify it to himself that way. In actuality there are plenty of languages that are popular and not bad.
10
u/ForeverAlot Nov 24 '18
Can you name one?
-5
u/kankyo Nov 24 '18
Swift, D, Python, OCaml, Rust. Hell, compared to C++ I'd add Ruby, Pascal, Java, C#.
-11
-5
-5
Nov 24 '18
F#, Haskell,...
16
u/InsignificantIbex Nov 24 '18
For a peculiar definition of "popular"
-4
Nov 24 '18
If tens of thousands of people use a language then it's hardly unpopular.
→ More replies (1)-8
u/shevegen Nov 24 '18
Yeah but this is not true, since you have to assume that people are equally happy or equally unhappy with language XYZ. And this is not the case.
Some languages are a LOT more fun than others, so of course this can not be a correct claim. People complain about everything all the time, but even there they tend to complain more about languages that SUCK MORE.
10
u/James20k Nov 24 '18
Personally I'd say that C++ is one of the better languages to learn first - if you can get your head around the stack, the heap, references, values, semantics (move/value categories), pointers and smart pointers, then every other language is pretty much just some combination of these features, potentially with garbage collection
6
u/Glader_BoomaNation Nov 24 '18
TI-84 BASIC was my first language. Would I recommend it to anyone? No. I feel the same way about C++ for some of the same reasons.
4
Nov 24 '18
BASIC is many bad things, but Byzantine isn't one of them, at least. Teaching a language that you can actually know in and out is a great idea. It gives this feeling of things being logical and controllable, which is a fuel you need to go on learning, even if the feeling isn't always justified.
-1
-12
Nov 24 '18
C++ obscures how things work, it tells you "it's OK not to have discipline, to be incoherent, just massage things until they work, w/o understanding why they worked". It doesn't build an understanding of programming from basic principles, it obscures the basic principles to the point that unless you learn another language, you will never be able to discover them on your own.
So, what are the alternatives? Well, languages specifically designed to do just that: teach from basic principles, to make it easy to remove layers of obfuscation (which are sometimes a good things, if they reduce work needed to be done in practical situations), which take care to prevent unintended behavior.
The examples? The language developed in PLAI book (by Shriram Krishnamurthi) is a good one. Less so, but still OK: any Lisp, Prolog, Forth. To lesser extent, C, SmallTalk. Languages like C++, C#, Java, Python, SQL, JavaScript would be terrible for this. Not because they are terrible languages in general (although they might be), but because they make learning the necessary concepts unnecessarily hard (paradoxically though, they themselves may be easy to learn).
Learning to program through C++ is like learning linear algebra through Lie groups, and then working back from it to field axioms, defining rational numbers etc. Lie groups aren't bad / don't teach you anything wrong about algebra, they are just a wrong way to introduce someone with no background to the subject.
7
u/InsignificantIbex Nov 24 '18
This is nonsense. Smalltalk is removed from the fundamentals in both ways: it doesn't preserve how the hardware works, and it is a narrow language. Smalltalk knowledge doesn't translate to C++, Prolog, or Forth.
C++ by contrast is not, in either. There's a lot that's wrong with CPP, but not what you claim
1
Nov 25 '18
Yeah, and you couldn't bother to read what you are replying to: it literally says "To lesser extent, C, SmallTalk". Do you know what "lesser extent" means?
There's a lot that's wrong with CPP, but not what you claim
Any argument to support that?
C++ translates into how hardware works? Really? Hardware usually has a dozen or two of class constructors, a soup of templates and it always comes in two kinds: headers and sources, right? Where's the connection dude? What you just wrote makes absolutely no sense.
1
u/InsignificantIbex Nov 25 '18
Semantic grouping, my man. Like how of I write "people speak English in the UK, and to a lesser extent Kazakhstan and the USA", you might wonder what Kazakhstan is doing there.
There's a lot that's wrong with CPP, but not what you claim
Any argument to support that?
C++ translates into how hardware works? Really?
Yes, it does. That has a lot to do with the legacy of C, but regardless: C++ is in many ways closer to the nitty gritty than other high-level languages. In Haskell, functions are a primitive, as are lazy lists. Smalltalk has numbers reacting to messages in a VM.
C++ has "constructors", that is to say: functions that write values to memory locations. There is no magic here
6
u/diggr-roguelike2 Nov 24 '18
just massage things until they work, w/o understanding why they worked
Sounds like you're just a shit programmer, brah. Protip: most people know what they're doing, and if you're "massaging", then you're in the wrong place.
1
Nov 25 '18
Most people who write in C++ know what they are doing? Lol... I've seen far too many assignments to know that the most bizarre and atrocious code is written in C++ exactly because it's designed to be obscure and unpredictable in how its basic parts work.
I've also seen retards claiming the same thing you are claiming. Usually they aren't much better programmers than those students. But they massaged it enough to make their program compile!
People who are more careful about the subject usually try to write critical bits of their code in another language, something that's possible to verify better, to make understandable and durable, or at least, something where you can recover from failures cheaply. It used to be the case that you had to either sacrifice speed, or to use some garbage language, like C++ because of how compilers are built historically. But those days are going away. So, eventually, C++ will die off and be gone like a bad dream.
1
u/diggr-roguelike2 Nov 25 '18
The word 'C++' in your post is redundant. Most people who write in any programming language don't know what they are doing.
But they massaged it enough to make their program compile!
This is true of literally every programming language in the world. Python, C#, Java, Ruby, PHP, whatever. (Even CSS, lol.)
it's designed to be obscure and unpredictable in how its basic parts work
Factually wrong. C++ is the only language (along with C) that is specified extremely precisely according to spec. It's the only language that is 100% transparent and predictable.
The fact that you can't be bothered to do your homework or learn something isn't the fault of C++. It's just you being a shitty programmer.
write critical bits of their code in another language ... something that's possible to verify better
Are you insane? I'm positively sure you've never actually written anything more complex than a ERP CRUD app.
0
0
Nov 24 '18
[deleted]
4
u/meltingdiamond Nov 24 '18
Python is eating dessert first. I think it would be cruel to make the students think it will all be that nice.
0
u/CaptainAdjective Nov 24 '18
Python is like the second or third most popular programming language in the world. You can make an entire career eating nothing but dessert!
19
Nov 24 '18
Really, the language hardly matters. Learn how to program and think through problems. Learn the data structures and algorithms. These can be mastered in practically any language and then easily transferred to another language. I say stick with C++ until you get fairly comfortable with everything else before switching languages. That will eliminate one extra variable from getting in the way of learning everything else.
0
Nov 24 '18
[deleted]
2
Nov 24 '18
I can’t say for certain what is most commonly used at this point, but it seems like there are enough people using 2017 that you should be able to find support for most problems that arise. I have been using 2017 for a project for a local company with a small dev team and things are going smoothly. Anecdotally, I’m writing in C# for the first time with having most of my experience in Java and C, but having several years experience understanding the fundamentals and some use of online resources makes it super easy to transfer my knowledge while learning a new language.
0
Nov 24 '18
[deleted]
2
Nov 25 '18
Kate Gregory's "C++ Fundamentals" on Pluralsight is great. Costs $30 for a month sub (first free) though.
1
Nov 24 '18
For me, University was the solution. There are tons of other posts on this very question here as well as other forums and those who took the route of learning on their own are more qualified to answer this than myself. All I can say is that you just have to keep trying and keep learning new things. Be curious and try to implement something that would be useful to you. If you find yourself doing tedious work, likely you can automate at least some of it. Learn data structures and how they work. I recommend manually building some using structures or classes so you can understand how pointers work and why they are useful. I like doing some leetcode challenges from time to time. You can sort by difficulty and many users offer in depth explanations.
1
u/mwhter Nov 25 '18
What's most commonly used?
VS Code, Atom or Sublime Text for GUI editors, vim or emacs for command line.
Add plugins as needed.
4
4
Nov 24 '18
Just keep going with it. If you get good at it (which takes a lot of time and frustration), you'll have more insight on the machine your working on than any Javascript/python dev ever would. Thats really valuable.
0
u/shevegen Nov 24 '18
Not sure if this is valuable as such. Sure, more information is always good but ... do you have to know how the computer works? This really depends totally on what you are using a given language for.
5
Nov 24 '18
I agree with perhaps not having it being your first language is best when you are still trying to figure out how loops work, or how you call functions. But I strongly feel that regardless of which field you end up in, you should at some point end up using a combination of either C or C++ as that experience is invaluable. I agree C++ is a monster nowadays, but the best programmers that I come across almost always have a consideration of the platform they are working on and how to best manipulate what they wrote in it.
1
Nov 24 '18
I just hope you are learning from someone who knows. After working for more than 12 years in C++ projects I can tell you for sure most people who use C++ don't understand the language.
1
Nov 24 '18
Well I'm watching a 9 hour YouTube compilation of one guy teaching it. I didn't do enough source checking on this guy to claim if its credible or not but so far he seems to know what he's talking about. Also using Wikiversity. What sucks is that all the tutorials are from 2015 Visual studio and I'm trying to do the same thing on 2017 cuz yanno newer is better right? But sometimes weird little things go wrong and I have no idea why.
1
u/glaba314 Nov 24 '18
The two really shouldn't be that different other than some C++17 features, which I don't think would be used in an introductory tutorial (I think). Also, what the person above means is that the C++ language has a lot of complexity that no one fully understands, but the basics that you'd learn in a tutorial are all common knowledge.
1
1
u/sign_on_the_window Nov 24 '18
In my experience, it doesn't really matter. It will be a bigger uphill battle learning C++ first, but you learn a bit more (memory management, garbage collection, operator overloading, templates, etc) than most other languages in the end. Once you learn C++ other languages will come much more naturally.
Just be patient and keep at it. It will be worth it in the end. :)
-2
u/Narase33 Nov 24 '18
Just remember, as long as performance is not really an issue, easy reading code is far more important
11
u/ImprovedPersonality Nov 24 '18
It’s very very rarely necessary to write ugly code for performance reasons. Most of the time neat, easy-to-understand code will also be more performant.
-2
u/Narase33 Nov 24 '18
There was a cppcon talk not agreeing with you
3
u/duzzar Nov 24 '18
What are you talking about? Most cppcon talks are exactly about zero cost abstractions, which basically means "easy, nice abstractions, with no performance loss compared to the low level way"
3
0
u/ImprovedPersonality Nov 24 '18
Link? Or even better a quick summary?
Of course there can be cases where polymorphism is too slow for your use case or where a custom, specific solution is a tiny bit faster than std’s containers and algorithms. But such code doesn’t necessarily have to be hard to read and it’s very rare in any case (and you should make sure it’s really the bottle neck in the critical path before optimizing).
I’m a digital designer. At work we develop digital hardware (ASIC) and firmware in-house. We tweak the CPUs and bus architecture to improve performance in specific usecases but there are very few parts of the firmware which trade readability for performance. The most prominent example are probably interrupt handlers which are written in hand-crafted assembly.
I know a company where they thought they had to avoid function calls for performance reasons and had 4000 lines long functions as a result. Just let your compiler inline that stuff for you …
-3
u/kankyo Nov 24 '18
Try to get out before you become a True Believer religious loon. I wasted a decade of my life on that trap :(
4
u/MINIMAN10001 Nov 24 '18
I mean you really shouldn't stick to just one language. They are tools, use them as you see fit.
1
u/singdawg Nov 24 '18
cant be too fixated on new tools at the cost of not mastering important old tools
117
u/[deleted] Nov 24 '18
I learned C++ as a first language, it was indeed a long process, but as a positive sideeffect I basically never had to learn a language again. Because once you understood most parts of C++ you understand every other imperative language.