11 ms·
C++ confessions of a C developer
- tluyben2 10y agoAfter many years of writing a self confessed horrible mix of C/C++ and calling it C++ (and I think more people have done that), I decided to learn C++11 and then C++14. I am enjoying it quite a bit I must say... Anyone else have that experience?
- huu 10y agoI'm on a similar boat. The biggest change for me was to recognize that I'm not the one who's supposed to be doing the debugging. The more (modern) C++ I wrote, the more I found myself leveraging the compiler to find bugs for me.
- satysin 10y agoMost C++ programmers I have known wrote C++98 as C and did a crap job at it. [0] However C++11/14/17 are almost like new languages in a way. Using C++11 or later is actually a lot of fun, it isn't the horror show it used to be. Not as comfy as C# or Java but not like walking on broken glass anymore :) Edit [0] Not saying I was any better :o)
- kartan 10y ago> and calling it C++ We used to call it C+. It was code that could not be compiled by a C compiler. But at the same time was painfully obvious that it was not proper C++.
- pzh 10y agoI think there is this misconception that there is a 'proper C++'. C++ was designed to support various programming styles, including this 'transitional' style where you have a C codebase that you slowly convert to a more object-oriented style, but overall it still remains an ugly mix of the two. What makes C++ proper is pretty much what code style and best practices your organization/project decides to adopt. For some projects, 'proper' may be object-oriented C++ with class hierarchies, whereas for others it may be a more functional or template-based style that doesn't even use classes a lot.
- astrodust 10y agoAs C++ features started to creep back into C you'd see a lot more of this. The // comment identifier is perhaps the most famous of these.
- deleted 10y ago[deleted]
- revelation 10y agoI made a conscious choice to use some of the new stuff like unique_ptr (primarily) and shared_ptr for memory management w/ move, lambdas, range loops and forward for varargs functions that are not an unsafe macro mess, constexpr, static asserts. It was quite nice, some of that is due to compiler progress, i.e. I always run with address sanitizer now. Sadly they seem to have added more than they cleaned up. It's 2016, I don't want to have to write another freaking include guard. That should have ended years ago. UTF8 and friends are also a consistent pain, mostly because 3rd party library support is absent. This requires a strong message from the standard library or it's always going to falter.
- pizzaisthebest 10y ago> It's 2016, I don't want to have to write another freaking include guard. I'd say there are bigger issues with C++ than include guards, but include guards should be out when modules are in the standard (2020?).
- revelation 10y agoIt's pars pro toto, yes what I actually need is modules to do the whole forward declaration pimpl extern template stuff for me.
- astrodust 10y agoModules are a gargantuan step forward. While we'll likely never get the effortless compilation speeds achieved by Pascal, hopefully the three day build on top-of-the-line hardware is a thing of the past.
- mrich 10y agopragma once is supported by enough compilers to be considered a standard by now :)
- PeCaN 10y agoThe annoying thing is that in spite of the fact that everyone (including the bizarrely malcompliant and bug-ridden bcc32 compiler I use at work) supports #pragma once, it will never get standardized simply because pragma anything is supposed to be strictly implementation-defined.
- pjmlp 10y agoI don't get to write much C++ code at work, given that we switched focus to become mostly a Java/.NET shop around 2006. Even C++ARM was already a pleasure compared with bare bones C. I has lucky to be able to bring Turbo Pascal best practices into C++, and that Borland had very good tooling. On my opinion, Turbo Vision, Object Windows Library and Visual Control Library beat anything that I saw from other vendors in regard to C++ frameworks for desktop applications. It always saddened me that given C++'s compatibility with C, most vendors would just throw over the fence a C library and it was up to us to create sane C++ bindings for them. A good example is the sad state of database bindings. But I do use C++ on personal projects, and C++11/14 has been quite rejuvenating and I do enjoy using it, specially for hobby coding across mobile OSes, given that it enjoy first class support in all SDKs.
- eropple 10y agoI learned how to write "C++" in the early 00's when I was the maintainer of a half-assedly "converted" CircleMUD that more or less just used function overloading so the idiot--err, charming gentleman--from whom I inherited the codebase didn't have to remember the order of arguments for "send text to character". I then didn't touch it for most of a decade and re-learned C++ essentially from scratch maybe...three years ago? C++11 from the jump, with slowly adding in C++14 stuff as it made sense. And I like it well enough. It's never going to be my first-choice language, but that's because the environment around C++ is a mess rather than the language itself. The language has stuff to know, but I find that most of it is stuff that is totally comprehensible given that I understand how C++ works--like, of course I need virtual dtors if I've got classes, because I understand vtables and the necessity for a lookup in one. It's complex, in that there are a ton of different components, but I don't find it complicated, in that any component is difficult to understand in isolation or that the interactions between components have particularly many gremlins. (Which isn't to say that I'm a particularly good C++ developer or anything, but I understand the land mines and how to be better at stuff I need to be better at when it matters.) These days, I can't envision ever writing more C than is necessary to wrap C++ for use as a library in Ruby, etc.; life's too short to not have dtors.
- slavik81 10y agoWhen I was just starting programming, I was taught that if you use printf, it's not real C++. Over the years that followed, I slowly learned about all the trade-offs involved with iostreams, and I became increasingly distrustful of complaints that were not about specific problems, but just that similar code would be possible in C.
- int_19h 10y agoBack in the day, embracing the STL and Boost way of doing things, and treating C++ less like "Java where you have to write * in variable declarations", certainly did a lot to improve both productivity, and my enjoyment of the language.
- developer2 10y agoAs a non-C++ developer, I'm curious just how many developers who choose C++ are using Boost. From what little I have heard from friends, it seems that C++ essentially implies using Boost - which could be seen as a good thing, or a really really bad thing.
- user5994461 10y agoWell. One doesn't have to use boost ever. I'd assume that most C++ programmers out here don't use boost on a daily basis. At the heart of the languages, in C you can only make additions and divisions, in C++ you can also make classes and use containers to store data. These are very low level building blocks, it's not enough to make any meaningful development productively. You're forced to use 3rd party libraries if you want to achieve anything. (e.g. File, IO, Socket, Thread...) There are many libraries/frameworks out there. I'd dare saying that C and C++ are extremely fragmented [by domains, platforms, tools...]. There is a minor subset of the desktop C++ developers that pick Boost as the default library choice and try to put that in all projects. They're just very vocal on StackOverflow [and all over the internet].
- gpderetta 10y agoI would say, as an heavy boost user, that today boost is no longer required. Most of boost basic utilities have either been incorporated in or superceded by the standard library. Boost is still very useful for many advanced or domain specific libraries.
- int_19h 10y agoThere are still a lot of minor conveniences, like lexical_cast, or uuid, or various helper algorithms (esp. for strings), that aren't subsumed, or at least not fully. Also, one big deal is Asio. Which, granted, can be had separately from Boost... but Boost offers a convenient place to get it along with other minor stuff. Then there's the question of how up-to-date the C++ implementation you're coding against is. A lot of stuff is nominally in the standard library, and if you use the latest and greatest, you might even have it out of the box... but for many people, they're still working on, at most, C++11 compilers, and so they need an outside source for stuff like filesystem.
- mschuetz 10y agoC++11 and 14 are the reasons I started to enjoy C++. I still dislike the cumbersome build process around of it but at least the language itself has become something that is nice to use.
- pg_is_a_butt 10y ago... with 0 examples of C or C++
- clishem 10y agoIncredible book (and reference) if you want to learn literally everything about C++ (and which parts to use, how and why): http://www.icce.rug.nl/documents/cplusplus/ http://www.icce.rug.nl/documents/cplusplus/ It's continually updated (pdf available on GitHub).
- bogomipz 10y agoI have a question. I often see titles of blog posts or books such as "Learn Modern C++" or "Learn Modern Java" but how possible or practical is this for a newcomer when the languages have been around this long? For instance what happens if you opt for the strictly "modern" just Java 8 or C++17 type approach to learning these. And then you end up as the case in the real world needing to maintain legacy code? Or you collaborate with people who have been using the language for a long time but don't use these modern approaches?
- pjmlp 10y agoYou cry, and use them just on your own private projects. Additionally keep looking for opportunities to sneak in some features, or pushing for toolchain updates.
- 35bge57dtjku 10y ago> Or you collaborate with people who have been using the language for a long time but don't use these modern approaches? That's always going to be a problem, but that's no reason to not learn the latest versions. > And then you end up as the case in the real world needing to maintain legacy code? It's not like learning the newer ways of doing things prevents you from learning everything else.
- khedoros1 10y agoThe point of learning the "Modern" style is so that the newer, safer features are the ones you think of when writing new code. No matter which style you're first introduced to, you're going to end up coming into contact with a lot of different programming styles. Given that you may have to learn them all eventually, and that you've got to start somewhere, doesn't it make sense to introduce students to the features of the language that try to correct past mistakes?
- millstone 10y agoA lot of what is considered modern C++ uses very advanced ideas. See this function from GOTW 94 [1], which Herb Sutter references approvingly, calling it "easy:" template<class Container, class Value> void append_unique( Container& c, const Value& v ) { if( find(begin(c), end(c), v) == end(c) ) c.emplace_back(v); assert( !c.empty() ); } Sutter likes this because it's written against an (conceptual) interface "Container", not an implementation like std::vector. He brags that not a single specific type appears anywhere in the code, making it much more powerful. This is modern C++, and it is totally inaccessible to a newcomer. It hits you with templates, iterators, and several generic STL functions. Call it slightly wrong, and you'll get an avalanche of impenetrable error messages. Dig a little ("what does emplace_back do?") and you're confronted with allocator traits, placement new, perfect forwarding, etc. Modern C++ is just not accessible to newcomers. The same thing in C (non-generically) would use concrete types and a for loop. 1: https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/ https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style...
- bogomipz 10y agoDoes anyone know if the videos from this conference have been posted somewhere? The slides are. The talks referenced in the author's post sound really good.
- userbinator 10y agoPersonally, unfortunately the more exposure I've had to the "Modern C++" community, the more I feel like it's dogmatic, cargo-cult, and obsessed with "best practices", which really puts me off. It looks like a manifestation of the second-system effect compared to C, which I'd characterise as a simple, pragmatic, and humble language. Then again, I've always thought OOP was oversold and that may have something to do with it. That is not to say I fundamentally dislike the language itself; C++ certainly has some very useful features compared to C, and I sometimes wish I could make use of them when I'm writing C too, but the "C++ is so much better than C, C is bad" and all-too-common "some bloke named Herb says X, so you must follow him" sort of attitude coming from self-proclaimed "Modern C++" developers I find rather distasteful. I don't care about purity or adherence to any perceived "expert opinion", I just want to use the features of the language that make it easier and simpler to solve a problem more efficiently (and likewise, not use the features which don't help)... which is what programming languages ultimately are for, and yet I feel much of the "Modern C++" community has missed that point.
- kccqzy 10y ago> I've always thought OOP was oversold and that may have something to do with it. Almost all of the recent innovations in C++ focus on aspects other than OOP. I can't think very many new OOP languages features in C++11/14/17, except for `override` and `final`. All the new hotness is about functional programming and in some sense, generic programming, which, IMO, is the right direction. > I just want to use the features of the language that make it easier and simpler to solve a problem more efficiently (and likewise, not use the features which don't help)... which is what programming languages ultimately are for, and yet I feel much of the "Modern C++" community has missed that point. I feel that you are exactly the kind of person the author has described in the beginning of the article: a C++ sceptic, especially a "Modern C++" sceptic. The article even quotes Douglas Crockford in saying "some of those features were more trouble than they were worth." The article also quotes Bjarne Stroustrup saying "[w]ithin C++, there is a smaller and cleaner language struggling to get out." The "Modern C++" community that you have derided is exactly the community that knows not every feature in C++ is good, a community that tries to enshrine the tried and tested "good features" into "expert opinion" and "best practices" and then spread them through talks like this one.
- minipci1321 10y agoPeople criticising C++ always sound to me like the language somehow leads them into abusing it. People mess up when coding in C++, not the other way round. Blaming the tools and seeking restrictions to one's freedom of expression in using them, won't have my sympathy. At one shop I once worked, they have added all sorts of protections to all tools they used, in order to prevent developers from doing wrong. For example, in the source configuration management, they disabled branching and parallel development, someone considered that too complicated. And Make and its language was completely hidden, of course. I personally greatly value C++ for the expressive power it gives, compared to straight C -- not only solve the problem but express the algorithm the way that a random person reading the code instantly grasps the idea, etc. I find it harder to achieve using straight C, on average. (I am in low-level and performance-related development, choice is frequently only between the two.)
- Klockan 10y agoThe bigger the team the more restrictions you want in a language. C++ is lovely when you are working alone, but as the team grows people start having very conflicting opinions on what parts of the language should be used. The only way to handle this is to restrict everyone to a subset of C++ and forbid everything else, otherwise it will be impossible to navigate the codebase. Innocent looking things like try/catch becomes a nightmare when not everyone has taken that into consideration when they clean up resources. Either you have to enforce proper cleanup around every function call or you have to forbid everyone from throwing exceptions, there is no middle ground here.
- minipci1321 10y agoI agree that the problematic of big teams of heterogeneous skills is not the same as the small teams of skilled people (some fields simply won't tolerate anything else), but the rest of your message stills sounds the same to me -- somehow the __language__ needs to be "restricted" because some (few?) __people__ on the team abused it?
- pjmlp 10y agoDoes anyone know everything about Python 3.5, language and libraries, including evolution issues when having to handle old code? What about style guides to forbid people to use generators, metaclasses or other advanced features? Just to pick a language most people think it is easier than C++.
- Tempest1981 10y agoIs anyone using Stroustrup's C++ Core Guidelines? And GSL? https://isocpp.org/blog/2015/09/bjarne-stroustrup-announces-cpp-core-guidelines https://isocpp.org/blog/2015/09/bjarne-stroustrup-announces-... They look like a way to add some safety to pointers and memory allocation, for those who demand bare-metal performance. Wondering if it's taking off...