304 points · by ingve · 7y ago · 251 comments
This was a big problem for me when I first started using C++. I don't remember it being too bad when I was just working on small projects and things I wanted to do at school. The problems started when moving past the "1-person" projects. Want to contribute to other projects? Chances are they all have very different build setups and configurations when it comes to building, testing, dependency management. That adds some friction even before you start taking a look at the actual code-base.
I understand that a lot of these problems can occur for languages as old as C++, but I wish the tooling was a little more opinionated and worked a little better at guiding newcomers into doing things in a nicer manner.
Maybe one can't reorganise the source tree layout because to do so would break our custom tooling / integration systems / interface with proprietary vendor tools. We can't change version numbering schemes because our packages already exist 'in the wild' and can't be changed mid-sequence without causing both technical and user pain.
Fundamentally: the codebase has worked perfectly well this way for the last 20 years; what's the business case for changing it (at potentially significant cost) just to be compatible with XYZ new tool that everyone is rallying behind?
In my experience, this just means they don't know how to do custom thing in Maven. Maven is very configurable; it can do pretty much anything you want, as long as you're willing to throw enough XML at it.
And if you are throwing a ton of XML at it, and your pom file starts to look like a nuclear disaster, that's a good sign that the custom thing you're doing isn't such a good idea after all.
Even grabbing libraries from github, I was unsure if I should grab just the headers and DLLs, or import the entire tree and mashup my build scripts with theirs.
I wish I had stayed with it since college but now I feel I have to reach for something like Go or Rust just to get something shareable in reasonable time purely because of the tooling, whereas I would really like to use the C++ language itself specifically for working with win32.
Honestly this is something that apt (et al.) make so easy on Linux distros that when you move to Mac or Windows you just have hard time believing people still in 2018 have to _deal with this shit_ (installing libraries and their headers by downloading each one separately and running an "installer" and trying to figure out where it put everything)
Like, why. It's one of the principle things keeping me away from developing on Windows for the last 10 or 15 years, the absolute lack of standards with regards to dev package management. Every time I decide I need to get something working on Windows it's an incredible pain in the ass compared to Ubuntu. Oh, now go to THIS website and download this installer and run it, now this one, now this one. And figure out for each one where it decided to put the headers. Now copy the DLLs around, etc. (Yes, there is system32 and Program Files but installers don't adhere to this by any means, and discovery via a build system is not given.) It's just barely worth it, and people only put up with it because of the huge user base. Honestly, for small projects I've found it easier to install MingW32 under Linux and cross-compile instead of working on Windows, it's that much of a pain.
At least Mac has Homebrew and Windows has a couple of good solutions now I guess (chocolatey, who came up with that name), but they are not officially supported and that is sad. I understand, they don't want to pay an army of people to package open source software full time, which effectively is what keeps Debian and Fedora going.. but they should. I would say it's one of principle reasons then end up doing something like providing an Ubuntu environment on Windows .. it's not just that people wanted a Unix-like environment, it's that they wanted _package management_.
You get one version of each package, and it is often years out of date. If you need a newer version you'll have to install it yourself and then try to navigate how to get your projects to use your local version. For any popular package that is still undergoing a fair amount of change it is likely that eventually some project you want to build will need a newer version than the one your distro provides.
So you still need a solution to the versioning problem separate from the distro packaging environment, at least for development.
I do agree that there is a lot of room for standardizing tool chain and dependency install workflows, but the tools themselves are of high quality now imo.
Headers/libraries on an Ubuntu LTS may be years out-of-date.
Am I supposed to just download a tar.gz and do the configure/make/make install dance to /usr/local or /opt or something for each dependency that I need a more current version of?
Even worse - what if my deployment target is 3-4 years older than the machine I'm developing/compiling on?
I don't think anything is "solved" with a traditional UNIX environment. Not even close.
The chocolatey repo (https://github.com/chocolatey/choco/wiki/History) explains the name as a pun based on the previous package manager NuGet: "Chocolatey started out as a joke because everyone loves Chocolatey nougat (nuget)."
Gonna be very hard to do. For the last 15+ years COM is essential part of WinAPI, and too many things in Rust conflict with COM: ownership, OOP, virtual tables, inheritance, they all too different.
Not just in Rust, in all languages, actually. You only have 2 good choices for complex platform-dependent windows development: either C++, or a microsoft's language with COM support embedded deep in the runtime, like VB6 or VBScript or .NET.
And remember -- a lot of the complexity comes from historical reasons AND also allow you to, e.g. run on, say an Atmel 328p or other microcontroller. So the complexity is partly from having such a wide target area.
It does look promising but because of the mess I'll probably gravitate to another language if I don't need to consume such a low level API.
Tho, it still won't be anything like ruby or node. Some Qt projects opt for cmake over qmake, for example. But at least getting your project bootstrapped is much simpler/faster.
What people call "opinionated" is nothing more than something being "architected". Someone has made a bunch of decisions for you that down the road you have no idea whether or not it will actually be good for you.
Using these types of frameworks short-circuits the process of being able to understand the nuances of building software. It's the apartment building or high rise of software development.
It turns design of your system from a personal journey toward the solution of your problem into little more than assembling linking logs.
I can understand the argument for an opinionated toolbox, but not for wanting base tooling itself to be opinionated.
Opinionated also means that these decisions will be the same in other places/projects I may join. In the medium and long term, that advantage may easily offset the value of custom decisions.
A lot of stylistic stuff like filesystem layout falls into this bucket.
After the hellscape that is CMakeLists.txt, Bazel is such a breath of fresh air. I'd encourage anyone looking at C++ for new projects to give it serious consideration.
CMake is the most used build system for C++. Meson doesn't even register. CMake is also 6th fastest growing language on github : https://fossbytes.com/fastest-growing-languages-in-2018-gith...
Meson seems to be spreading pretty rapidly. After I was introduced to it a few years ago for work, I started using it as my default build system for C++ elsewhere and more C++ devs I know have started using it. I've seen it replace CMake and make at large companies for C++.
#beentheredonethat
That’s great! I’ve been using it since 2013 and still haven’t learned it!
Just for context, I was such a C++ bigot at one time that my car's license plate read C++HACKR and my personal website was on the cpphacker.org domain. But somehow I drifted into doing more Java and wound up mostly leaving the C++ world.
Edit: heck, this conversation triggered such a pang of nostalgia that I just re-registered cpphacker.org. Maybe I'll go back to having a personal website there. I've been thinking hard about setting up a new personal site and ditching Facebook anyway...
I've been using Python since 2008-ish on and off for various scripting tasks and small tools, I can't say that I've "learned" it. They keep adding new stuff, some things I forgot, others I never needed.
I've been using C++ professionally since ~2006 and for similar reasons I won't say that I master it either. Metaprogramming is a clear weak point for me, but OTOH I find the whole exercise pointless and unpleasant. Unless one wants to be on the standards body, it's not really worth trying to learn C++ (or any other language) at 100% IMO.
As a contrast, the description of Common Lisp syntax fits on a sticky note, but the library and semantics spec take about the same number of pages to describe a similar amount of functionality.
The two extremes represent different locations on the syntax-vs-library complexity tradeoff continuum.
I'd say it's a syntax x language semantics x libraries triangle. Common Lisp may have trivial syntax, but there are some hidden gems of complexity in the language semantics level. To this day I don't really understand eval-when, and I've been using Common Lisp for the past 9 years.
And does it really matter if you don't? No, not at all.
Incidentally, after working with node for a couple years near really knowledgeable coworkers, it's been the first time in my life as a developer that I feel I have a near complete understanding of the language I'm using.
Granted, most of that feeling probably comes from the small standard library (which is the root of several important issues, as we all know), and the feeling adds nothing to your life as a developer except for a vague sense of comfort, but it's still nice.
admittedly, Java got a lot bigger in Java 8 and beyond. but it's still the language I'd put forward as "most possible to master".
Can anyone recommend any source for someone with lots of pre-C++11 experience to get up to speed with current capabilities, and the current community?
EDIT: Thanks everyone for the suggestions!
EDIT2: I skimmed Anthony Calandra's list, and most of the new features seem indeed just cute, but not fundamental changes. Still, I want to reiterate the worry I expressed downthread: how much did the underlying semantics, the idioms, and the general way of thinking change?
Other books I've been reading: _C++ 17 The Complete Guide_ by Josuttis _C++ 17 in Detail_ by Filipek
Lots of good blogs out there. Also the CPP Podcast. http://cppcast.com/
There are also a lot of great blogs covering new features. Also
Note: I do wish HN would adopt standard markdown
https://github.com/AnthonyCalandra/modern-cpp-features/blob/...
If you already know the language flow control you don't need to read paragraphs of a book to relearn to how "think" in the language. You just need the "whats new" parts.
(I hear the compile times are the same though -.-)
Which probably means that someone who learned modern C++ will have significant difficulty with older C++.
Sometimes it makes me wonder if someone should just declare a subset of C++ as "good" and call it a new language.
The combination of "auto" (plus template type inference), ranged for-loops, initializer lists, structured bindings, lambdas and certain new standard library mechanisms (std::unique_ptr, std::variant, std::optional, std::move, etc.) together change the high-level expressiveness of the language, encoding a lot of common patterns and eliminating common, redundant code. For example:
std::vector values = {1, 2, 3};
for (auto v : values) { ... }
New for loops support structured bindings: for (auto &&[key, value] : mapOfStuff) { ... }
There's a lot of little conveniences, such as the ability to define a default constructor, or accept a initializer list in the constructor: struct Foo {
Foo(std::initializer_list<int> values) { ... }
}
Foo f = {1, 2, 3};
or indeed named initializers: struct Person {
string name
}
Person p = {.name = "bob"};
The forthcoming range library in C++20 also finally make lazy sequence iteration functional and composable, e.g. something like (off the top of my head): getNumbers()
| view::filter([](int a, int b) { return a > b; }
| view::reverse()
| view::take(10);
Another big change that's coming is concepts, which are somewhat similar to Rust traits or Haskell typeclasses: The ability to put compile-time constraints on template arguments. For example, in classical C++, invalid template invocations generate notoriously bad error messages, since templates are only compiled once they have been expanded with their arguments: template <typename T>
T add100(T v) {
// Compiler will fail on this line:
return v + 100;
}
auto n = add100("hello world");
Concepts will let you constrain T to something that actually supports the operations you need: template <Incrementable T>
T add100(T v) {
return v + 100;
}
// Compiler fails on this line:
auto n = add100("hello world");
Then there's the contract spec, which adds support for Eiffel-type contracts.Lastly, C++ designers seem to have thought a lot about safe memory semantics, and so there's a renewed focus on smart pointers (that actually work) together with move semantics and tightening of cop constructor semantics. The end result is that it's generally easier to work with RAII and avoid explicit heap allocation with the "new" keyword.
Wouldn't have it any other way haha
To me, this is the most powerful reason to learn C and C++. If you know these languages, you can read the codebases of all the things you use and contribute to them (every browser in existence, every Unix in existence, most user space tools, many GUI tools, many low-level libraries that mobile apps use).
Even if everybody stops writing C/C++ today, you'll still be using software written in C/C++ for decades.
And of course, that's a joke -- there's still at least 10x more C/C++ being written every day in the world than any other language that compiles to native code (Rust, Go, etc.)
Welcome! As someone who’s been using C++ pretty much continuously for two decades, I think there has never been a better time to learn it. We finally have compiler competition that has resulted in robust support for the language’s great features.
Ah, yes. I think they called it "C".
OTOH if not for C compatibility we would not have this discussion, since we would most likely never heard of C++.
In modern C++ it is very much possible to write fast and safe code, but the tradeoff is now put into the amount of stuff the developer needs to know to be productive (Which in my experience isn't as bad as people like to go on about on here/reddit, even if it still pretty shoddy)
You can make whole applications without touching memory management with RAII patterns; and C++ APIs are usually not the Java OOP monstrosities everyone hates.
Operator overloading is just so damn useful . You can make very elegant APIs in C++ as a result.
Honestly, I don’t really like it. The only real reason for that is that using smart pointers is verbose, but I don’t want to do manual memory management where it’s possible to instead rely on RAII.
Ironically enough, though, C++ is probably the second of two languages I’d consider my “go to.”
Its pretty unlikely anyone is going to take on the monumental project of "write a software GUI kitchen sink suite like Qt, but in Rust" any time soon. Not because you can't, but because such projects are by their nature at minimum millions of LOCs.
> blog post in January 2019
> "learnt" in past tense
This is what also makes Bjarne one of the greatest language designers. Where most designers would have gone off making new languages, Bjarne has been polishing the C++ stone the whole time.
Is it better to build a complex programming language that handles real world complexity?
Or is it better to build a simple programming language where complexity is an emergent property than in turn use that to handle real world complexity.
One issue of building a complex programming language is that if you build the language to handle one type of complexity, it becomes hard mutate or shift that programming language to handle a different type of complexity. This is essentially the issue with whats happening with the newer versions of C++.
Autodesk AutoCAD (36+ years old) CAD software is one of those piece of software that is still widely used today and very likely used to design physical products many people use today from your toothbrush, office chairs, towering skyscraper buildings to parts of a jet plane you've flown in from your last vacation.
I don't think this is more than a minor issue. If you can't afford it, the book is very easy to obtain online for free, either through piracy or a paid / free trial Safari Books Online subscription. If you felt so inclined, you could pay for the book after making money with the C++ it taught you.
The document is definitely not a good way to learn the language.
Personally, I find Scala standard library much easier to work with and at the same time much more flexible and powerful.
Like a few days ago I saw a bunch of complaints about how C++14 and beyond were adding so much stuff and it's just bloat or overcomplication. No! Using that stuff makes my life so much easier, whereas C++98 was indeed a miserable nightmare.
What is the best C++ IDE on the Mac?
In particular, fully project-aware autocomplete is a baseline feature. Does emacs or Vim offer an autocomplete plugin that matches the power of IntelliJ, or even Xcode?
Is CLion worth the money? Other paid alternatives?
[1] https://www.qt.io/download
[2] https://valloric.github.io/YouCompleteMe/
[4] https://marketplace.visualstudio.com/items?itemName=ms-vscod...
[5] https://github.com/MaskRay/ccls
So I agree, 1 year doesn’t even begin to cut it. You need more than book knowledge, you need the experience of watching your masterpiece crumble under its own weight (sometimes several times) or have the joy of hunting some obscure bug because you failed to recognize the trap you had set for yourself.
I certainly wouldn't want to scare anyone off from C++, because personally I find the empowerment is worth the pain. It just takes time to learn what to avoid.
Very good point, but that's by no means unique to C++. Maybe that level of experience ;) in a related language, plus a good working knowledge of C++ would be acceptable?
He started ~2 months ago.
I've started to learn some C++ a few days ago, mostly go get into lower level code and into game development (Unreal), and I've found it to be pretty great!
I've been going through A Tour Of C++ and it's a great primer on the whole language. I also read the Learn X In Y Minutes on C++ to get a feel of it before diving in.
What are some high quality, small C++ projects I could play around with and read the source code? I'd like to explore it in more practical use next.
So many times I wish to learn it seriously but these new editors for web development and Python made me lazy enough that I wish to have some environment and way to write and compile C programs easily.
I heard modern C++ is way better than what it was in early 2000. I want to give it a try, hopefully, I will be able to learn and implement Pointers properly.
I can't stress enough how true this is.
Things might even work in the end, but you can end with a weak project that wont scale or will crumble when faced with the destructive nature of time.
I know its a controversial topic, but i think a little bit of zen-budhism training of the mind can make wonders in making those sort of decisions, where the unbalanced parts of our psychology will eventually show up and cripple what could be a great thing.
I am an IT enginner, but i practice a lot of self-mind vigilance to understand my decision making process, to avoid making the most confortable decisions and going for the write answer, no matter how painful and expensive it may sound.
To give an example of this, i remember for instance CouchDB vs. MongoDB, where the concepts were layout in CouchDB, but it was done in Erlang, so as soon someone did almost the same thing in a language that suits a database development well like C++, the tool sky rocket and reach all of its potential.
The language i see this happening the most for instance is Python. Where you have great concepts and great enginners but where a lot of them shouldn't be using Python for that particular goaç. Again here i can use Mercurial as an example of a great tool in a bad fitting language (for the given tool, as Python might be a great fit for other use cases).
This is obviously not what one should do. Read the test cases first is what I do. It makes for much quicker iteration.
I tried rust, but they keep changing it and breaking modules i need to use!
If you find your dependencies are breaking:
• Keep a lockfile (Cargo.lock) committed in your project, so that your deps won't suddenly get updated to some newer, potentially buggy/incompatible version.
• If you're updating dependencies, also update the compiler. It's possible that new versions of dependencies require latest version of compiler.
1. Current setup and where to go learning (the books) 2. It also had nightmares in colleague with C++, but yes, C++11 fixed a lot of it. 3. Nice links to the other tooling.
So, author, thank you for your post!
Also, you could "learn" it in a year, but it takes you a lifetime to master it.
- Manual memory management and direct use of pointers.
- Emphasis on giving as much latitude as possible to compiler writers so they can generate fast code on obscure architectures.
- Separation of header files from object files.
- Explicit handling of object files and linking in the build process.
In fact, I think after learning C++ you should be able to read almost any C code with no issue, which is nice for being able to peek under the hood of the infrastructure we rely on every day.
If all you know is C++ you will be able to produce a limited amount of working code in a handful of C++-like languages, sure - but even in Python or Java or Bash you'll produce very unidiomatic code if you write in C++ style. If you tried to work in e.g. Smalltalk or Erlang or even OCaml you'd really struggle. It is not a good way to learn general-purpose programming, because the language is hugely complicated and most of the complications are C++-specific.
Learning bash became easy when I learned pipelines and the GNU coreutils.
Now I wish I could take what I'd learned from GNU coreutils and apply that to C++.
>"Rust"
>3 results
T-h-r-e-e? How is this even possible?
--
[0] - Everything I worked on, from games through embedded to web development, was a poor fit for C++/Java-style OO, but I suspect there are some domains where OO modeling is the best way of looking at things.
I agree though, that having the entire program be a graph of objects is actually usually the worst pattern.
This is what I was primarily thinking about, and this is what is most written about in OOP books. OOP is a big bag that wraps itself around a lot of things, and which appropriated quite a lot of concepts. The concept of gluing together a bunch of data and code in order to treat them as a single entity is indeed useful (at least for imperative code), and while it is the foundation of OOP, I don't think it's really the distinguishing thing about various OOP approaches. For the class-based OOP, it's the composition of data+behaviour, encapsulation, polymorphism and inheritance that together create a particular philosophy - one that I find much less useful than advertised.
The building blocks are no doubt useful - a proper type system is great, but you don't need classes and objects for that. So is polymorphism, and again, you don't need Java-style classes to get method dispatch (see e.g. Common Lisp multimethods for an arguably better way of doing this, and one that doesn't even treat methods as parts of classes!).
I'll concede that OOP approach fits UI libraries unusually well (though you can hit some conceptual roadblocks there too; I'm not sure I've ever seen a good OOP design of tables, nor do I know how to design it well). But then again, I was recently writing some React code in ClojureScript, and it turns out that functions and plain data can handle building stateful UI components well too.
What I mean by saying that OOP appropriated things - I've seen people thinking, and even myself I used to think, that "abstraction" is something that a class creates, and is what you achieve with OOP. I gradually grew out of that belief, and I vividly remembering that reading SICP made it finally click in my head that quite a lot - if not most - of the software engineering practices discussed and attributed to OOP are in fact more general concepts applicable regardless of your programming paradigm.
For Alan Kay it was all about messanging but I dont think most people think about that.
Structs with some kind of dynamic dispatch based on the type would be the most general discription I think.
But to be clear: Node and Java (and anything with a managed heap) doesn't have a paradigm for things like RAII or inlined parametrazation or copy-by-value or move semantics because it doesn't have a way to express them. But those are useful tools and important in some regimes.
C++ is very messy, but for the most part you can ignore the messy things.
I feel we should build our programs the same way. Bottom up from a small set of simple primitives. Not top down like C++.
* C++
* Lua
..
.. [a thousand other things]
..
..
* Node
* Javascript
__ bottom of the pile..
The Node/JS ecosystem is such a steaming pile of garbage, I can honestly see with great clarity why people should be running from it back into the arms of C++[11,17] ..
Now, I'm sure some people have an easier time with Makefiles, but I've found it even easier to get up and running in Javascript. Most of the tools in Javascript (create-react-app, Webpack, etc.) are very user friendly, making setup trivial.
It is best not to speak with such authority/certainty that C++ is easier to use than Javascript.
Don't underestimate the pile of garbage JS indeed is! Yes, you can install a package with ease, you'll have to do that with about 100 packages that keep changing all the time with all kinds of breaking changes (not talking about their 1000's of dependencies). I'm also sick and tired of the hipster JS community where every piece of shit can become a hype. With JS you'll be forced to work with things you hate. Almost all codebases I have to work with are horrendous piles of rubbish that often need to be completely rewritten from scratch. Almost everything you write doesn't last. You've spent a year learning Backbone? Just throw it away, now it's Angular you can start all over again. One year later? Stop doing Angular, it's React now, just start all over again! Hey, now we have some hipsters promoting Vue, they say it's the holy grail, just start all over again, it's fun! Flux stores? Fluxxor, Alt, Redux, Redux with Saga's, or just go with Thunk? It doesn't matter that much, it only lasts for 1 or 2 years! I'm completely sick and tired of it, including the fact that I'm only working on stupid e-commerce websites..
Talking about make files, a magnitude easier than trying to setup babel and webpack for a medium sized SSR SPA. I recently had to upgrade from babel 6 to 7, what a fuckin pain that was, so many changes, the deployment server refused to boot etc, etc..
Mind your step going into JS!
https://www.infoq.com/presentations/Simple-Made-Easy
JavaScript is a simple language that can be made extremely complicated via "simple" tooling. You can open the node_modules folder and see how sausages are made. :-)
C++ is dealing with essential complexities, there is no silver bullet:
Unless of course you have 30+ years of experience in the software business, have kept abreast of all the latest and greatest distractions from proper software engineering practices, have built a few hundred examples of such personally, and have no desire to throw more garbage at the fiery pile. As is my personal case. Node/Javascript are the Visual Basic of the 21st Century - this doesn't mean people haven't been productive with them as technologies, just that they've been productive in spite of them.
https://nbviewer.jupyter.org/gist/ontouchstart/1af198f8535eb...