Live data from Hacker News

Why does everyone here seem to dislike C++?

news.ycombinator.com

31–40 of 46 posts

Re: Why does everyone here seem to dislike C++?

#31
There is only one thing "wrong" with C++ and that is undefined behavior. An accident of history, but one that will make you cry at times. For the rest the tooling around it is quite depressing as well. But none of this prevents you from getting great work done, they are annoyances. i.e. you can have a solid career with C++ so the languages to learn are suggestions for horizon expansion not career advice.

Now it looks like you want to stay close to the hardware so there are a few options that can be interesting to look at. Game programming is not nearly as much fun as game playing so be careful what you want.

Rust: the new kid on the block, learning this will help you look different at C/C++ and even if you don't continue using it professionally you will pick up nice things.

A scripting language with a REPL. Lua, JS, a lisp, python, perl, ruby, it doesn't matter. Just have a look at one and see what tools to make tools you can build with them.

The following I would suggest having a look at but not more than 1 weekend each ;) They are very far from windows apps and game stuff.

Ada/spark: the old kid on the block, a could have been interesting. Again not something that is widely used so learn for curiosity not for career.

JavaCard: the slow kid on the block. Not talking about plain java here, but specifically the JavaCard environment which is a whole different playing field. You will pick up standard Java as well, by doing this. Massive different perspective, but no games ;(

Outside of languages I would spent time picking up Vulkan the new graphics API and OpenCL or Cuda. These will help with getting into the game market but also help you look at visualization and data presentation. Valuable skills no matter where you go afterwards.

Remember in the end people don't pay for code. They pay for solutions to their problems. If you can solve problems you will always have a job.

Re: Why does everyone here seem to dislike C++?

#32
post #8

Earlier quoted context omitted.

As a computer engineering student (the programming counterpart to electrical engineering), I still prefer C over C++. I dislike C++ because it's just so unbelievably complicated and hard to learn. There's a special place in hell for the abominations C++ calls error messages. Clang helps, but not enough unfortunately.

Im suprised that nobody has mentioned golang, which is generaly described as the successor to "c".

Golang is great, and I'd love to move my code over to it from C and C++. But one of my projects involves creating a Windows DLL, and I don't think Golang provides a way to for me to compile to that just yet. I don't think Go has a strong GUI story yet either (and even if it did, it will take a while for the tooling to match XCode or Delphi or Xojo).

Languages have different strengths, part of programming is deciding which languages & toolset are most productive for the project you're working on.

Re: Why does everyone here seem to dislike C++?

#33
While C++ has plenty of interesting and nice features to play with it lacks something important Java has, reflection. C++ would be pretty close to "perfect" language if it would add reflective capabilities on top of all the other nice features.

Yes. I know some libraries add "reflection" but its not good enough. It needs to be baked in language and not require additional syntax on classes to be used as data for your own reflective code.

Re: Why does everyone here seem to dislike C++?

#34
Because what I can clearly express in one line of swift/haskell/etc is often like 15 lines of nasty in C/C++. And when I make a mistake, the former has around a 90% chance of telling me about it immediately whereas the later is maybe 30%. When you're dealing with a couple person decades of code, that really really matters.

It's kind of like building a house using a rock instead of a hammer. It works. But after a few years building houses with a rock....when you try out a nailgun for the first time......yea not going back to that insanity. Of course sometimes a rock is your only choice...embedded, and a few other domains, but I'm never writing another line of C++ unless it's genuinely the only language that can solve the problem. To be fair, if you stick with EE, then yea it may be your only choice most of the time.

Also, as a counterpoint to the C++ makes more $$ comments. I doubled my salary(and got way more job offers) going from embedded C to iOS dev. Most of that's attributable to moving out of an economic backwater, but C/C++ is not necessarily a magic ticket to more cash. Being the company expert in C++ might be, but then so is being the company expert in . I'd be lucky to see any increase at all moving back to C.

Re: Why does everyone here seem to dislike C++?

#35

People get very hung up on the complexity of the language and all the bad code one could potentially write. I use a C++ compiler to compile my preferred subset of the language, and for me that's within epsilon of the best of all possible worlds. If I was on a team that forced me to use every language and library feature, I'd probably be unhappy.

Interesting workflow. Whats your preferred subset ?

Re: Why does everyone here seem to dislike C++?

#36

People get very hung up on the complexity of the language and all the bad code one could potentially write. I use a C++ compiler to compile my preferred subset of the language, and for me that's within epsilon of the best of all possible worlds. If I was on a team that forced me to use every language and library feature, I'd probably be unhappy.

[deleted]

Re: Why does everyone here seem to dislike C++?

#37
post #33

While C++ has plenty of interesting and nice features to play with it lacks something important Java has, reflection. C++ would be pretty close to "perfect" language if it would add reflective capabilities on top of all the other nice features. Yes. I know some libraries add "reflection" but its not good enough. It needs to be baked in language and not require additional syntax on classes to be used as data for your…

Generic reflection for C++ would require disabling optimizations that affect object memory layout somehow. It would also mean you need to have all the symbols present.

It would also require additional overhead for RTTI information per object, if you want it to work using arbitrary void *.

It'd br great to have reflection of course. At least so some subset, non-generic but with zero (or low) overhead.

Just being able to iterate known type struct or class fields could be something.

Re: Why does everyone here seem to dislike C++?

#38
post #9

Apart from school, let me give you an advice. If you have a brain that can handle multiple levels of OO in c++ across multiple threads; keeping multupltformness in mind and crunching out optimized code with all that you learned in your data structure classes, stick with C++. The pay is way better (like three times more here in Toronto) than anything web or app related, the working hours are more sane, and stuff are u…

There are hardly any (well paid) remote positions in C++ though? So it's the kind of path where your career might dictate where you live.

Re: Why does everyone here seem to dislike C++?

#39
It varies per person. The history of imperative programming branches off from ALGOL into several directions. One was to C and then C++. Here's my point-by-point trace of how those were "designed." You'll see that C is more an accident of history designed to work on ancient hardware then lots of uptake since UNIX was written in it. C++ was actually designed carefully on top of C with features from many languages but inherits C issues and kludginess of that approach.

http://pastebin.com/UAQaWuWG

Now, there were a few other paths from ALGOL. One was Wirth's tradition of languages that were simple, type-safe, memory-safe as possible, compiled lightening fast, consistent, and still performed well. Started with Pascal with Turbo Pascal and Delphi being big commercial successes. Drawback with him was he leaned too far to simplicity as some features might justify extra complexity. Yet, the Oberon's, Modula-3, and Component Pascal derived from this style could do much of what C++ developers could with more safety, consistency, and development speed. Examples below:

https://en.wikipedia.org/wiki/Modula-3_%28programming_langua...

http://blackboxframework.org/index.php?cID=why-program-in-co...

http://www.freepascal.org/

Another branch was Ada family. It was designed to prevent as many faults as possible in embedded programming mainly. They systematically eliminate them with syntax, semantics, and defaults. SPARK variant extends that to automatically prove absence of common errors in code via formal verification that runs behind the scenes. The systems were never popular for various reasons but empirical studies by military showed vastly lower defects than C or C++ with productivity and maintenance advantages.

http://www.adacore.com/uploads/technical-papers/SafeSecureAd...

http://libre.adacore.com/

So, ignoring functional programming and such, it's hard for me to like C++ coming from a Pascal background where the syntax was readable even to lay people a bit (a la BASIC), operations were safe by default, compiles up to 100kloc/sec on Pentium3, no segfaults, less hacks, GC by default, unsafe for speed if I need it, and small set of features all developers understand and use. C++ was nothing like that although they've improved it a lot over time.

So, given I know better stuff is possible and even out there right now, I have to still think C++ is crap because it combines pieces inconsistently to approximate stuff like I use plus builds on an unsafe foundation with undefined behavior.

Re: Why does everyone here seem to dislike C++?

#40
post #6

Expressing yourself in languages like Python is much easier than C++. You'll be able to concentrate more on solving the problem at hand than dealing with the language. I highly recommend these two short books: https://www.amazon.com/Treading-Python-Beginning-Programming... http://www.amazon.com/Treading-Python-2-Intermediate/dp/1490...

You'll spend more time debugging errors that could have been caught at compile time by strict static types. The minimum here should be C with the warnings enabled. Things like Ada and Rust may improve upon this. Also, I think performance issues can count as "dealing with the language". Python is roughly 100x slower, making it like all your computers are a dozen years older. It's like having a 2004 computer in 2016.

I'd wager that python's ease of expression is enough to beat C/C++'s strict static types as far as reducing bugs. I'm all about strict static types, but C++'s incarnation of them is surprisingly un-helpful. Several other languages(swift, haskell, etc) actually deliver on at least most of the promise of static typing, with nearly the ease of use of python, and nearly the runtime performance of C. Maybe the newest flavors of C++ are better, but the C++ I coded in 7ish years ago was a morass of boilerplate and foot shooting.
Post reply on HN