5 ms·
Datastructure APIs in C++
- ncmncm 7y agoIt is hard to express how fundamentally wrong the author is, in his definition of abstraction overhead, and his criteria for sound implementation practice. The term "abstraction overhead" is already defined rigorously as the difference between the runtime performance of handwritten pre-specialized code, vs code that uses a more general abstraction. So we don't have a proper term for what the author objects to, but avoiding powerful language features -- most particularly, destructors -- would be a huge step backward. Most of us don't get the luxury of discarding a system and rewriting from scratch. Instead, we make the code we have maintainable. Each of the tools the author reviles is present in the language specifically because using it properly makes libraries and programs more maintainable. A system coded using the features wisely, well, and pervasively is more maintainable, and fundamentally better. The alternative would be to say that systems in raw C, or assembly language, are more maintainable, which is obvious nonsense. The experiences that led the author to his conclusions are no doubt tragically lamentable, but do not represent anything like the mainstream experience of system construction and maintenance.
- RandyGaul 7y agoHi, author here :) > The term "abstraction overhead" is already defined Interesting, I didn't know that. I was just trying to describe an idea I had in my head, and not hijack some pre-existing term. > Most of us don't get the luxury of discarding a system and rewriting from scratch. Instead, we make the code we have maintainable. Each of the tools the author reviles is present in the language specifically because using it properly makes libraries and programs more maintainable. You're right. Re-writing things is a luxury. > The alternative would be to say that systems in raw C, or assembly language, are more maintainable, which is obvious nonsense. Well I didn't say that, and I don't agree that it's the alternative, as it's merely a single alternative. I tried to focus on encouraging a skeptical nature when picking language features to use, and tried to demonstrate the idea of applying skepticism with my own personal examples/choices. The purpose of the skepticism is to encourage conscious cost/benefit analysis that takes into account compilation time, but also how easy code is to grok by new eyes.
- comex 7y agoDon't worry about the parent's excessive negativity. Fast compilation time is a huge and underappreciated benefit. As for abstraction... I personally disagree with some of your conclusions as well, but I also recognize it's a fundamentally subjective topic. After all, how easy something is to understand depends on who is trying to understand it. Different people have different preferences and are familiar with different coding patterns.
- ncmncm 7y agoThank you, this makes your intention clearer. You should know that it is very common to advocate subsetting C++, mostly by people who prefer not to learn anything new. These efforts are always based on the fundamental mistake that old, familiar features are implicitly better than new features, so new features should be treated with especial suspicion. But new features obsolete old ones specifically because we know more today how to write fast and reliable software. So, if you consider subsetting the language, look at the totality of features, and favor new features over old. C++ inherits a great many design flaws from C, and constructs that depend on those flaws should be the first to go. Constructors, destructors, in-class member initializers, and exceptions are a huge win for reliable code. They have no effect on compile time, vs. dodgy C-like ways to achieve the same ends. Many of the newest features, particularly those connected to constexpr and concepts, replace dodgy template metaprogramming constructs that are very slow to compile.
- flohofwoe 7y ago> The alternative would be to say that systems in raw C, or assembly language, are more maintainable, which is obvious nonsense. The existence and success of Linux alone seems to contradict your opinion, and that's hardly the only pure C code base of that size that's been successfully developed and maintained over decades by many contributors. If anything, that makes C look like a pretty good choice for creating a big maintainable code base.
- jcelerier 7y ago> The existence and success of Linux alone seems to contradict your opinion, you cannot make useful comparisons with "Linux alone". See for instance SerenityOS (https://github.com/SerenityOS/serenity https://github.com/SerenityOS/serenity) : in one year and a few months it went from zero to full-blown C++ OS with graphical shell, userspace, and a dozen apps (https://github.com/SerenityOS/serenity/tree/master/Applications https://github.com/SerenityOS/serenity/tree/master/Applicati...)... in 140kloc. Of course we'll never know how Linux would have turned out if it had started today with modern C and modern computing power, but it does not seem out of this world that C++ is a more productive language than C by a non-negligible amount.
- flohofwoe 7y ago> but it does not seem out of this world that C++ is a more productive language than C by a non-negligible amount While this is worth discussing, such a nuanced statement is far from the absolutist "obvious nonsense" of the parent post I was replying to ;) Of course projects like SerenityOS are a great achievement, but I'm sure there's plenty of examples where operating systems have been brought into a similar state, in similar time, and with similar team size with C and a bit of assembly (e.g. AmigaOS comes to mind).
- ncmncm 7y agoThis is amazing. Why have I not heard about it?