Hacker News new | ask | show | jobs
by Chromozon 3511 days ago
Hopefully you will be learning C++ and not straight up C. Modern C++ has pretty much solved all the shortcomings of C, and it's sad that people are still stuck learning archaic C for no good reason. If you are actually learning C++, do NOT even look at K&R C. It is extremely outdated and straight up teaches bad practices.
3 comments

That is definitely some kind of https://xkcd.com/386/ - moment for me.

I totally disagree. I am not sure if your comment is satire or not, I would do it the other way around. Learn C as it is fundamental to modern OSes and just learn C++ if you have to (e.g. maybe later at a job, or because you need a specific library, like OpenCV). However I do not think that fully grasping C++ is a worthwile endeavor, as there are many things implemented due to historical and/or compatibility reasons (to C) and not because they provide a real benefit. Not that C is perfect but I consider it less fucked-up than C++.

That is the path to write unsafe and unidiomatic C++.

CppCon 2015: Kate Gregory “Stop Teaching C"

https://www.youtube.com/watch?v=YnWhqhNdYyk

Although I am not the big C++ fan, this is a wonderful talk and she has a great approach to teaching programming languages. Thanks!
Two totally different languages with two totally different use cases. Their use cases should not overlap if applied correctly.

C++ is a very high level language compared to C. C++ has low level constructs which closely resemble C but should only be used for high performance implementations of high level abstractions.

You are right, it is crucial to emphasize to beginners that these languages are different (and C++ not being some kind of add-on to C, which is - considering its name - a valid guess, but we have the same discussion with Java and JavaScript). But I think learning C, Python and JavaScript (and maybe some Java) to a degree that let's you get useful work done, is a lot simpler (meaning takes less time) than learning C++.

Not that I would discourage anyone from learning C++ (ok, probably, I might) I just consider it a bad PL for people starting out with programming.

Not only that, but Cython really takes away a huge amount of performance bottleneck encountered in Python code by generating pure C from a Python language superset.

More details here: http://scikit-learn.org/stable/developers/performance.html

There are still some of us that write (and hire for!) straight C.
Yet I only find job postings where they're looking for someone to code C/C++. I still don't know what that means. Does that mean both or one or the other? Or that they're still undecided as to what language to use? Maybe they don't know what language they are using..?
Basically what this means is that you will compile all your code using a C++ compiler, but because C++ is backwards compatible with C, they just call it "C/C++".

A lot of developers still write in a C-esque fashion because that's what they were taught in school or just haven't learned a new way of doing things. Developers still use the C standard library for file IO instead of C++ fstream. Developers use new and delete with raw pointers and manage the memory themselves instead of using a vector. I was recently on a project where all the code was written in an old C style- variables declared at the top of each function, raw pointers everywhere, usage of C strings, etc. Memory leaks and segfaults were abundant. Uninitialized and unused variables a'plenty. And they were using a C++ compiler.

In my group's case, it means both. We expect new hires to know C++ for most of our work, but for portability across different architectures C is sometimes still necessary.
In cases like that, I think it'd be so much better if people wrote "C and C++" to make it clear that both are indeed a requirement.
Firstly, let me qualify all of this by saying I try to be a true polygot and use the best tool for the job. Among my regular languages the past few decades include C, C++, Lisp, Java, Clojure, Smalltalk, Python, Ruby, C#, Haskell, Rust, and many more. As such, I have no attachments to any particular language.

C++ and C, while both using the letter C, are for all purposes, entirely differently languages with different goals. Use the one that meets your goals best. While I can agree that K&R is outdated in some areas, there are still plenty of reasons to learn and even use C. If for no other reason, some of the most popular, active, and most used code bases in the world are written in C.

C is essential if you want to understand a lot of the ecosystems around you, fix them, interact with them properly, and maybe one day contribute to or patch them if necessary. I know some people will argue that if they know C++ (or programming in general) they can read C, but hands-on experience is the only real way to learn. You will not know why things are done or recognize when they are done poorly/incorrectly. Moreover, C is a great teacher of how things work, and sometimes also how not to do things. To be ignorant of C is generally to be woefully unaware of how a huge part of a lot of the software you probably use works.

I worked/work in game programming, distributed computing, AI, and many other fields. I find C to be extremely valuable in all fields I have touched and at home and at work. If nothing else, learning about memory, byte ordering, alignment, packing, bit manipulation, etc is a huge solid base. C++ can teach you a lot of that too, but it deals with certain issues on fundamentally different levels (especially modern C++) and has just as many potholes and here be dragons areas. It is true that I don't start as many new projects in C as I used to, but it doesn't stop me if lets say the main thing I need to do is interact with something already in C/embedded, or have a certain level of control that C affords me while being able to also hire people that can work in it (factors when evaluating project constraints).

One argument I consistently hear with regard to C that you hint at is that if you learn C first, before C++, whenever, it will somehow taint you. I would argue that with every language, you are not learning the language if you do not how to write programs in it idiomatically, or even when to counter-balance idiomatic code with code that does what you need to do (ex: boost performance or other tradeoffs). At that point, you are not a programmer but a parrot or like someone who memorizes math formulas but can't apply them.

Programming is not regurgitating countless lines of syntax, it is critical thinking, problem solving, creativity, and many more things. Learn C, and learn other languages. Do not listen to anyone who tells you to learn any particular languages. Match the language with your task, problems, and other constraints. When in C, do C. When in C++, do C++. When in Python, don't do C. And so on. It's really not that hard for anyone experienced.