Reason #73 why C++ is a terrible intro language
blahedo.org
blahedo.org
The entire thread is worth reading.
test.cpp(19): warning C4018: '<' : signed/unsigned mismatch
Default configuration of MSVC 2012 (this has been an on-by-default warning for roughly a decade, maybe longer).I'm curious whether CL does warn on this by default, or if MSVC's default just includes similar warning flags.
I can't argue with that. I'd also teach students right from the start to look at the intermediate files as one of the early steps to understanding compile problems (so with gcc that would be the '-save-temps' option).
Yes, C++ will let you make mistakes. It's not your nanny, it's a programming tool for... GASP ...programmers...
Let's see if we can get ACTOR resurrected...
Even though he wasn't ragging on C++ as a general-purpose programming language, it would be nice if the programming community could have honest conversations about its shortcomings without resorting to defensive, ad-hominem attacks.
The problem presented in the article is not well thought out and cannot be achieved with these instructions:
Write down your name.
Make a pile of pennies with as many pennies as there are letters in your name.
Keep doing this:
Write down an 'X'
Remove one of the pennies
as long as the number of pennies is less than the number of letters in your name.
So, outside of being a mind-reader how is a C++ compiler supposed to correct _your_ thinking?int foo = -1 unsigned int bar = 1
then "foo > bar" evaluates true. And it shouldn't, because that makes no sense. Languages should not violate the Principle of Least Surprise unless there's a really good reason.
Personally I always use -Wextra (the relevant flag for clang) when working on my own code.
I say this because it's a lot less dismissive of the troubles of the programmer to be. I remember being new not so long ago, and being frustrated immensely by the dismissals of experienced C++ programmers who feel that programming is inherently all about knowing and dealing with the hard edges of the machine, and much less about the rather beautiful theoretical side most people would call Computer Science. And I feel that's pretty much wrong; that programming is a balance between wrangling the machine and building elegant, beautiful logical constructions.
Covering both sides separately is important, and builds a strong programmer. Teaching only one side, or not acknowledging the differences between these two very separate skills/processes confuses aspiring programmers tremendously, and turns them away from the tremendous power that can be had in languages like C++.
Yes, assembly will let you make mistakes. It's not your nanny, it's a programming tool for... GASP ...programmers...
So, therefore, C++ is equal to or less than BaSUCK and yer a silly-nanny like yer old man.
cout << is_unsigned<string::size_type>::value;
and check it ourselves.At least C++ has unsigned types. Java doesn't even warn about `new int[-30]` and similar fun stuff (at least not generally).
Seriously, if you have languages with signed & unsigned types, and implicit conversion between the two, this can happen. In languages that don't have these features, it can't. However, almost all of them ALSO have ways that poorly written code works until it doesn't. It's a phenomenon very reminiscent of the halting problem.
I suppose you could s/beginner/person/ on that statement as well, with lower probability of mistakes but still nonzero.
1) Tutorials usually use 'int' (self-referential)
2) 'unsigned' is one more thing to type.
3) It can be hidden behind a typedef.
4) Negative numbers can serve as error codes.
5) Wraparound can cause bugs for either.
6) Occasionally safer (if x - 3 < 0)
I've usually taken to using explicit width unsigned integers (uint32_t) unless there is a reason not to.Suppose you have an object with a interface like object.setValue(7). You'd like to assert that people are sending you valid data, but if the type is uint then you can't do that. if the type is int, then you can assert(value>0, "Value must be greater than zero").
Now if anyone calls setValue(-1) you'll get an assertion that would have been skipped before.
I feel that pedants and more experienced C++ programmers will tell me I am sloppy or should be getting warnings on setValue(-1) but I've been burned before. My life is easier when I avoid unsigned types.
The behavior of int delta = unit1 - unit2 is also annoying. Not unexpected if you're paying attention, just annoying.
I might use them more if underflow / overflow caused an exception instead of undefined behavior.
On the article itself, I don't believe anyone sincerely consider C++ to be a good introductory language. It is dragged by a lot of low-level concerns which are only a dead-weight for a beginner. At this point of a programming cursus, the focus should be on understanding algorithms and low level details that can be useful in other contexts only serves to trip students.
As for the higher level of C++, such as everything object oriented, I believe it becomes and additional load on the understanding of the language(why are Strings initialized this way? How come I can call a function from a data type with the dot-notation, but functions I define can only be called by themselves?)
I find it to be also weird that String::length returns a type_t. The way I understood this type was that it represented a memory size. When we call length, we want the number of characters, independantly of the character size under the hood.
My 'real' intro languages were Pascal and Prolog. Pascal was fine, but prolog was very much a waste of time.
I would say Python because I think that it offers the best mix between learnability and usefulness.
Also, yes, I'll throw Python out there as the best beginning intro language we have now. It's syntax-light compared to the other languages teachers know, familiar to instructors coming from a Java or C++ background, and, best of all, wasn't designed as a teaching language, so it isn't crippled in bizarre ways.
However, I also think that teaching multiple languages is essential, and they should all be from different families or at least have different features, so Haskell, Prolog, Lisp, Forth, and, yes, C++ should all be in the program.
C++ has a whole bunch of other issues, however. The inundation of poor educational resources on it and the fact that many treat it as "C with Classes" rather than its own language doesn't help matters much.
incorrect behavior is incorrect behavior. You want it to crash when you decrement past some value, instead it does something that looks like crazy voodoo to you (from a boolean algebra perspective this is completely expected behavior! You're just loosing the top binary digit b/c you have nowhere to store it!)
We don't program to make programs crash. Yeah, it's a slightly easier to debug when you have a crash, but never bet on crashing or segfaulting for "checking" if your program works.
BUT.
The example the author uses fails to capture a minor nuance of the real world: there is an implicit assumption that you can't keep removing pennies once you hit zero. Had the pseudo-code been this...
as long as the number of pennies is less than the number of letters in your name *and there are pennies to remove*.
...then the generated C++ conditional would've been: } while (pennies > 0 && pennies < name.length());
This is more an example of why sloppily converting algos in English to machine-friendly codes is terrible."On two occasions I have been asked, — "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" In one case a member of the Upper, and in the other a member of the Lower, House put this question. I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."
When the concept of classes and OOP just sort of jumped out from the middle of the first semester I could see people's heads exploding everywhere.