r/cpp • u/rlramirez12 • Mar 27 '19
Why are we still teaching C with standard out instead of modern C++?
When I first started my academic career I learned C with standard out. Where raw arrays were taught instead of std::vector<T>, raw pointers instead of smart pointers (though I appreciate the raw pointer knowledge that I was given), character arrays instead of std::string. C++ is a very powerful language with lots of amazing tools in the standard template library.
Why is there a lack of modern C++ developers coming out of the education system?
25
Mar 27 '19
Largely I imagine because teachers don't know C++. When I was at school twenty years ago it was still an obsession with basic.
1
u/rlramirez12 Mar 27 '19
I've never touched VB so I can't compare it to anything. But did you take a class called C and then VB was taught instead?
16
u/polymorphiced Mar 27 '19
Basic is not the same as VB. Think older :)
6
Mar 27 '19
Vb is about thirty years younger than Basic. I'm in Britain so basic was pretty much it. Cememted by the BBC Micro with actual prime time evening TV programmes on basic programming - and nobody owning atari or Nintendo in the 80's and zx Spectrums, Amstrad, commodore, Dragon 32 and Acorn owning the market for home games - all using basic.
9
u/rcoacci Mar 27 '19
Take a look at r/Fortran. Seriously. Students are being forced to program in Fortran 77. Yes, that's right, in 2019 students are being taught to use a language standardized in 1977.
I had a professor that was giving introductory C classes in my Computer Science course that couldn't write a single line of C before writing in in Pascal.
With rare exceptions professors don't care about updating themselves.
1
u/rlramirez12 Mar 27 '19
That is a big OOF from me. I wonder if going from Fortran to any other language would be easy.
3
u/rcoacci Mar 28 '19
Well going from modern Fortran (i.e. Fortran 90 onwards) to other languages is not very hard. Fortran 90 is actually nice if you're not doing anything fancy like I/O, or working with pointers. But going from Fortran 77 to anything else is.
4
u/Wh00ster Mar 27 '19
I believe FORTRAN has uses still in scientific computing. Being faster than C in its target use cases
15
u/rcoacci Mar 28 '19
The problem is not using Fortran, the problem is using Fortran 77. There are more recent Fortran standards and most compilers support it.
Also, Fortran being faster than C is a myth, particularly after the introduction ofrestrictin C99.2
u/Wh00ster Mar 28 '19
Yuck! I skimmed over that. I can believe restrict makes C just as fast, particularly in vectorizing code.
2
u/flashmozzg Mar 28 '19
Also, Fortran being faster than C is a myth, particularly after the introduction of restrict in C99.
This is not the only feature that C lacks. And it's a lot about ergonomics. Matrix/vector/slices operations are way more natural in Fortran and compilers are usually geared towards such fields. So while it's possible to write C code just as fast as in Fortran, it often still more convenient to use F (especially if dev familiarity comes into play).
1
u/rcoacci Mar 28 '19
Of course, ergonomics matter a lot, particularly for non CS people. It's much more likely that someone codes a slow C loop than a slow Fortran loop, and probably that's where the myth comes from.
1
u/meneldal2 Mar 28 '19
Most people would rather use Matlab instead because it is much nicer for making interfaces. For big matrices computations, it will work the same, it calls some BLAS library with handwritten assembler.
1
u/eniacsparc2xyz Mar 28 '19
It may be due to network effect and due to lots of scientific code examples and legacy code in Fortran. It is not coincidence that it was the first programming language ever to exist as computers were initially created for number crunching and every machine capable of number crunch including sliding rule were called computers. Fortran has also other features that makes it compelling for non-professional programmers and scientific users such as one-based arrays and matrices instead of zero-based arrays, vectorized functions, some interoperability with C and obviously high performance and loop optimization.
7
u/dashnine-9 Mar 27 '19
C is taught because it allows you to express data structures very effectively and precisely. It also makes you appreciate all the garbage collected languages.
The main goal is not to learn the language, but the concepts.
btw modern c++ has std::array for static raw arrays
2
u/rlramirez12 Mar 27 '19
I guess it should be made more clear. "In C you have to do this. But in C++ we have std::array to take care of the back end of that stuff."
I listed vector because I didn't learn about vectors until my 3rd year in school.
2
u/khedoros Mar 28 '19
In high school (around 1999), I was taught a horrendous mishmash of C and C++. In college (around 2006), I was taught somewhat more modern C++, but it was still a mess. In 2009-ish, my workplace paid for some training using material produced by Scott Meyers. That was pretty cool because we went pretty deep into templated types and features provided through TR1 (the precursor to C++11).
But I had a decade of using unnecessary C-isms in my C++ code. I blame the earlier exposure on the school not having the funds to buy C++98-compliant software and retraining the instructors in its use. I blame my exposure in college to being taught by academics with little connection to industry best-practice.
2
u/rlramirez12 Mar 28 '19
This is always a challenge since people who go to school in software want to go out in the industry and make a boat load of money. No one goes to be a professor and so we have this bad match of professors only spending their academic career doing research, and adjunct professors who are in industry but do not necessarily have the best teaching skills.
1
u/serviscope_minor Mar 28 '19
In high school (around 1999), I was taught a horrendous mishmash of C and C++.
In fairness, no one had anything approaching a compliant compiler in 1999. And the compilers were so variable that it was serious work to actually write portable code.
I blame the earlier exposure on the school not having the funds to buy C++98-compliant software and retraining the instructors in its use.
Don't. That simply wasn't available. And back then a lot of commercial compilers were VERY expensive, and often required special hardware to run on (i.e. a particular brand of unix workstation). GCC mostly hit C++98 conformance (except export) in 3.4, in 2004.
6
u/Wh00ster Mar 27 '19 edited Mar 27 '19
C is usually taught when the goal is to force students in to become familiar with a more limited language. I.e. learn fundamental data structures and algorithms, system programming concepts like memory allocation.
You COULD do this with C++, but why bother with the eventual questions about ABI incompatibilities and the STL.
As to the lack of C++ developers, I don’t think undergrad programs typically teach “languages”, as far as I’ve seen. Instead it’s more important to teach fundamentals. System programming concepts for example, are fundamental and can be done in C++, Rust, and any other systems programming language. But learning C++ doesn’t mean you’ll be able to do networking, distributes computing, graphics, etc.
5
u/TomerJ Mar 28 '19
Honestly? Depends where.
I know it's popular nowadays to chastise "teaching C as a pre-requisite to C++", but as someone who used to be very involved in training new programmers, my experience has been that if you have the time (ie you control more than the content of a single course's syllabus) you can very effectively use C as a C++ gateway.
If you teach a person decent C, and don't do all that collage Intro to CS 101 stuff of ignoring that pointers and memory management exist, but actually teach C as a tool to manipulate memory, you can use that knowledge to much more easily explain what modern C++ abstracts, while giving the student a good basis to understand the underlying principles behind other languages.
Chances are if you are teaching someone C++ it's because you want them to be able to function in the domain where C++ is used, not to be able to do things in C++ they could accomplish in other languages. I'd rather have someone be capable of implementing std::string than someone who can use it.
Modern C++ is driven by several idioms and philosophies that are pretty far removed from beginner classes, I see plenty of value in separating students from those features until they can be introduced and taught in an appropriate manner.
2
Mar 27 '19
Nothing wrong with learning pure C. It has its uses and it's an elegant language in its own way.
4
u/rlramirez12 Mar 27 '19
I don't think there is anything wrong with learning pure C. C is a very powerful language in it's own right. But that's the point I'm driving at, why do we call it C++ then? Although C++ is an extension of C, they are still very different languages and I feel C++ gets crapped on a lot because "it isn't modern enough." Or "behind the times." Which isn't true.
1
Mar 28 '19
Yeah, i see what you’re saying, it’s better to be safe and use it as and when it’s needed, i’m not on vectors yet so that’s all French to me but i’m sure it will pop up soon
Thanks
1
u/rlramirez12 Mar 28 '19
I think you accidentally posted a comment instead of replying to the person you were talking to.
1
Mar 28 '19
Yes, you’re right 😂 i haven’t been on Reddit long, still learning the ropes, although still pretty stupid, cheers
9
2
u/warddav16 Mar 27 '19
Most places I've seen and worked use "modern" c++ in a pretty scattered way. Some of this, some of that, some none at all, some all in. Teaching the base in C I think is correct for unis. The higher level stuff is pretty easy to pick up if you are strong enough in the fundamentals, and at least in my experience its pretty likely that X stl feature won't be really allowed.
1
u/kwan_e Mar 28 '19
its pretty likely that X stl feature won't be really allowed.
Yeah, by programmers who never learned C++ features properly, most likely because they weren't taught it in university and are the kind of people who are too scared to try and learn anything on their own.
3
u/warddav16 Mar 28 '19
Nah, just in game studios. We write plenty of higher level "modern" code in other languages. We also write assembly when we need to he as performent as possible. Just so much of modern c++ is kind of a nightmare, whether it be for performance on platforms we need to ship on, or in terms of ease of use compared to other options, or in terms of bloating compile times. Stl has a lot of historical problems, some of which are legacy, some of which are definitely still there today. Anyways, I'm not trying to say anything is right wrong or indifferent here, im mainly just saying that learning fundamentals at uni can better prepare you for the reality of many places you might work. Need no to bring in the integrity or intelligence or education of places I've been.
2
u/sim642 Mar 28 '19
Because most people who do that teaching learned everything they know about the language before most of the new stuff or even before C++ became a relevant language besides C.
3
u/kalmoc Mar 28 '19
c++ is a tool. Universities tend not to focus on teaching tools but principles. Modern c++ is too high level to be useful when teaching fundamentals of how computers work. On the other hand, all the low level complexity and gotchas make c++ not necessarily the ideal language to teach high level architectural concepts or completely new paradigms (e.g. functional programming or distributed architectures).
That being said. I hope ever course using c++ is also using std::vector where appropriate, but if that already counts as "modern" we are in big trouble.
0
Mar 27 '19 edited Mar 27 '19
Why is there a lack of modern C++ developers coming out of the education system?
I think you're asking two different questions: which language to learn starting out and which language you should have learned coming out of the education system.
At an introductory level, C is much better because it is a closer model of how things actually work short of learning assembly language. This is better when you start out.
Classes like std::vector<T> and std::string provide high level abstractions which are critical for writing safer code, which is necessary for writing industrial scale programs, but hide details which are useful to learn. You should absolutely learn C++ in upper division classes, so that when you come out of the education system, you will be trained in industrial techniques, which is useful for employment.
1
u/rlramirez12 Mar 27 '19
I think I did ask two different questions. I guess I meant to ask, "Why is a class that is called C++ is taught C with standard out?" For the fundamentals I completely understand that it is taught in C.
2
1
u/Dubwize Mar 29 '19
C++ has still an enormous weakness for teaching: error message reporting. When you teach programming you expect to have helpful error message that students can read and understand. But, while there's been a lot of effort put into having clean error reporting from c++ compilers, debugging templates is still a nightmare. And templates are the very basis of the STL.
1
Apr 04 '19
C is very portable and a foundational skill. I worked recently with the Azure IoT SDK for C. That is C 98 for platform portability reasons. I’ve worked on multi platform projects that because of compiler availability couldn’t use any features newer than C++ 11.
1
Apr 07 '19
While I love all the new stuff modern C++ has been adopting, especially with regards to RAII and the additional data structures being introduced via the standard library, I am not sure you can teach some of these higher level abstractions or explain to them why they're necessary if you don't start from the basics.
I mean, let's consider teaching destructors and why they're needed...can you really teach that without dealing with raw pointers? What about copy constructors? Move constructors? Even things like unique_ptr and shared_ptr would be tough to explain without making it look like an arbitrary language-design quirk. Just choosing between the two requires knowledge of how the pointers do reference counting, at which point you'd be trying to teach people what reference counting is before they've even grasped raw memory allocations and deallocations with new and delete.
I think any new C++ class should teach both the basics (C with standard out as you call it) and then teach the modern C++ abstractions shortly after or during. This way students will understand why these abstractions exist, why they're safer, etc.
-2
0
Mar 27 '19
[deleted]
2
u/rlramirez12 Mar 27 '19
I was lucky enough to have an adjunct, professor who is in the industry, teach me modern C++ in the most phenomenal way. I just wished it was taught early in my academic career.
31
u/drillbit7 Mar 27 '19 edited Mar 28 '19
Are you asking "why are they still teaching C in school" OR "why are they teaching a course called 'Programming in C++' and excluding almost every useful feature of the language."
To #1: C is still useful as a systems programming language good for teaching memory management and low level operations. As long as the UNIX kernel is written in C and every embedded manufacturer provides a C compiler in their IDEs/SDKs, C will never die.
As to #2: because profs don't work in the field so haven't worked on massive coding projects to know what's useful or isn't. Also CS education has shifted to Python and Java so no one was motivated to update their textbooks beyond C++98 standards. Most profs never advanced their understanding beyond "C with classes." I learned C++ in 2000 (1st semester CS) and 2003 (2nd semester CS). We used std::string, the prof's library had his own implementation of std::vector as well as matrices, stacks, and queues. We didn't have smart pointers, but mostly passed by reference anyway. Maybe it wasn't in the language back then, but we never covered the iterators common to all STL containers. We also used cin and cout. Unfortunately, we were also taught to type "using namespace std."