26 ms·
C++ in Coders at Work
- adrianN 16y agoI'm currently implementing a complicated algorithm in C++. I don't have to use many language features for that, so I don't have a strong oppinion about them. But what I can say is that, compared to Java, the tools for C++ coding suck. Hard. In Eclipse you can write some gibberish and it automatically turns it into valid Java that mostly does what you want. The Java debugger is excellent and works without hickups. The experience you have with Eclipse and CDT just isn't the same. No automatic inclusion of header files, autocompletion doesn't always do what you want, no documentation included, even for the STL. Working with gdb is painful, most of the time it is not possible to properly inspect datastructures in memory and it is generally just easier to litter the code with print statements.
- pmjordan 16y agoPart of the tools issue arises because C++ insanely hard to parse (the preprocessor makes it even harder); recovering programmer intention from something that is "almost" C++ is an exercise in futility. This is, I think, a genuine problem with the language. There are of course good arguments in the "Java wouldn't need such good tools if it was a better language" camp; best of both worlds would be a language that's easy to write tools for but doesn't really need them. With regard to debugging, I think you're being unrealistic. You're comparing debugging on a fully introspective and managed virtual machine to debugging annotated assembly language. Apples & oranges. If a fully managed VM meets your needs, then use it. If it doesn't, well, welcome to low level programming. You also make it sound worse than it is; JVM debuggers aren't perfect either: they debug Java-the-language fine, but other JVM languages are more problematic. Good luck with JNI, too. Likewise, there are C++ debuggers which are STL-aware, and even those that aren't can usually be coaxed into displaying pointers as arrays or as supertype pointers. Using gdb directly is rarely necessary; there are perfectly decent frontends. If you're having problems because you're trying to debug compiler-optimised C++, then you're simply running into the limits of the platform. Debugging post-JIT Java is no fun either.
- anonymous246 16y agoCan you name some "better than gdb" debuggers. I'm pretty frustrated with gdb, but all the alternatives I tried in the past have sucked as hard or more than gdb.
- pmjordan 16y agoOn Unix systems, you usually still want to use gdb, just with a Frontend. On Mac OS X, this will usually be XCode, on KDE I like to use kdbg. There is ddd, too, which is ugly as hell but works well. On Windows you probably can't beat Visual Studio. I'm currently having to use pure gdb to debug some Mac OS X kernel code, and I feel your pain. Using a frontend is much nicer.
- agazso 16y agoEclipse and CDT for C++ coding sucks. However this doesn't mean there aren't any good tools. Both Visual Studio and XCode are very good for working with C++.
- mdwrigh2 16y agoDo you have any recommendations if you're working on a Linux platform? This is purely out of curiosity. I'll stick to my standbys of Vim and a terminal window.
- Raphael_Amiard 16y agoThe best IDE i was able to find for C++ on linux is Qt Creator. Its only drawback is that it's quite Qt integrated, but with very few tweaks you can make regular C++ projects with no Qt dependencies. Everything from the debugger to the code completion does work well, which is more you can say about most C++ IDE on linux.
- albertzeyer 16y agoThe current Qt Creator (or I think its beta version) really has the best available C++ syntax support (which has direct impact on stuff like auto completion) I have ever seen so far. The second best I have seen was in KDevelop (when configured correctly -- I remember it only worked correctly when you pre parsed the STL library). I am also very excited about the clang development. It was developed in a way that it should be very easy to integrate it (or parts of it) in an IDE. Xcode4 will do that. And others probably will follow at some point.
- gmartres 16y agoTry KDevelop 4. Its semantic highlighting is really awesome. And most importantly it doesn't get in your way. Unlike Eclipse or even Qt Creator which I find frustrating to work with.
- huherto 16y agoI recently came back to C++ after many years. I spent days trying to set up a good environment with vim, then I tried with jedit http://humbertook.blogspot.com/2010/11/personal-preferences-using-jedit.html http://humbertook.blogspot.com/2010/11/personal-preferences-... , Finally I started using Qt Creator. It is not as good as Eclipse, but it is a big improvement over vim; specially, if you are already using QT.
- jwh 16y agoHave you tried NetBeans? Whilst I couldn't find a way to automatically include header files, once they're added NetBeans automagically switches on autocomplete and finds documentation where available. I've used it for my own C++ projects (using headers and libraries from others as well as my own) and had no problem. I'm by no means an expert (used C++ for only a few months, coming from a PHP background) but I managed to get a few CGI applications working using Xerces-c
- srean 16y agoIn Eclipse you can write some gibberish and it automatically turns it into valid Java that mostly does what you want. Isn't this the reason that many treat java programmers as suspect ? I think IDEs are fine once you have mastered the language and the syntax, but it often masks the gaps and deficiencies in one's own knowledge. I find that a bit scary. I understand that mine would be a minority view. Guess work at the IDE together with TDD has significant fan following. Apparently it gets the job done, if that be so, who am I to complain. Edit: It seems I have hurt someone's ego :|
- frou_dh 16y agoI think C# really exhibits this. Almost everyone starts (and stays with) Visual Studio, which has extensive auto-completion, meaning if you ever use a plain text editor, it's startling how little of the library you have in your fingertips.
- barrkel 16y agoNo, I don't think this is a valid reason - in fact, I think it's a prejudice which disguises an ignorance of why languages with productive IDEs are so good. An IDE with code completion means you can get more done without having to waste time studying API docs; in fact, the IDE's editor can itself become the most efficient doc lookup tool. This gives you more time and attention space to point at your problem domain, rather than mere incidental details. Object orientation with static typing is a big contributor to this, because you start out with what you want to act on - the noun, which is usually a local variable or field - and get completion on the actions available on that noun. The contrast with functional and procedural styles is stark: there, you need to know the symbolic name of what you want to do to something you already have in hand, but editor completion is almost powerless to help you, because of the order of tokens in the syntax.
- deleted 16y ago[deleted]
- swift 16y agoStatically typed "pure" functional languages have somewhat different tradeoffs when it comes to looking up functions; the style of code completion common in OO languages doesn't work, but because the type of a function encodes so much more meaning about what the function does, you are often able to find the function you are looking for just by giving its type to a tool like Haskell's Hoogle. This is less automatic, but it enables you to search a large array of libraries simultaneously, which is very helpful when you don't know what library contains the function in question!
- pyrhho 16y ago> the tools for C++ coding suck. Hard. ?? What's wrong with vim? (or emacs, or your flavour of choice)
- masklinn 16y agoThe verbosity of the language?
- GvS 16y agoOn Windows I recommend Code::Blocks (http://www.codeblocks.org http://www.codeblocks.org )
- roel_v 16y ago(I'm gonna get reamed for this, but...) Visual Studio is great and with the proper setup can do all of that and more. Obviously it's Windows only, so that may be a problem. Frankly, I think much of people's hatred against C++ is the relative lack of good tools on non-Windows platforms.
- fossuser 16y agoThat's interesting to me that so many people dislike C++. I prefer it to Java (which I find extremely verbose), don't think its features are really that complex and like its speed. I think it's a powerful object orientated statically typed language. It seems when compared to other statically typed languages (it doesn't really make sense to compare with dynamically typed languages) C++ does a good job. The STL prevents you from having to reimplement many things you might otherwise need in C and the syntax is more natural or intuitive when compared with C as well. I have a feeling people just prefer what they're familiar with and make sweeping generalizations or exaggerated claims about other languages and technologies.
- cageface 16y agoA lot of C++ bias lingers from the days when compiler support for more sophisticated features like templates was very immature and buggy. C++ is much more pleasant to code in now than it was when I first used it in 1997. I certainly wouldn't want to write a webapp in C++, but for anything that requires speed and direct control of memory C++ is still really the only game in town and I quite enjoy it when it's the right tool for the job. People describe Objective-C as "c with objects" done the right way but I'd much rather code in C++ than Objective-C. I also don't really understand why people say they prefer to write in pure C, at least not in 2011. Hacking together a homegrown OO system in C with structs and function pointers and macros doesn't sound any easier or simpler to me.
- fossuser 16y agoThat makes a lot of sense. I hadn't thought of its past when the compiler wasn't as solid as it is now. I suppose I'm spoiled by the fact that a lot of that had already been completed by the time I started coding.
- rubashov 16y ago> wouldn't want to write a webapp in C++ Actually, POCO has all the stuff you need to write a web-app: templating, form handling, http request/reponse objects, etc. Not that I've done it, but it looks like you could write a web-app using POCO::Net rather painlessly. I like C++ and don't understand the frustration others express. I don't use a subset, and neither do the other people I work with. We use pretty much the whole thing, TMP, macros and all. Being well familiar with C++ I can never see a clear reason to prefer something like Java. Qt is better for GUI stuff. POCO is just as good, or better, for network stuff. With C++ you can go ahead and marry the host platform's system calls when that makes sense (i.e. write a unix program). When it comes to scientific or graphics type libraries it seems like the premier solution usually has a first class C++ interface. The Java equivalents seem harder to evaluate. I did a bunch of GIS stuff recently, using proj.4 and various other things. It sure appears to me that the Java/C# equivalents of the GIS type libraries are less supported and less popular ports of the C++/C ones. If you have perl/python and C++ in your tool belt, I just don't see the need to reach for the so-called C++ replacements. Aside from hiring considerations, that is.
- martijn_himself 16y agoInteresting article. I do not have much experience in C++ but I am learning Objective-C. Do any of the sentiments mentioned in the article carry over to Objective-C? Or is that comparing apples and oranges? Is Objective-C a better extension/ superset (whatever the formal name) to C?
- pmjordan 16y agoObjective-C and C++ are very different apart from their C ancestry. C++ doesn't make an especially good Obj-C replacement, and Obj-C is probably no better at the situations where C++ excels than raw C. Objective-C is a higher-level, dynamic-ish, highly-OO extension to C. (great for GUIs, not so great for writing drivers) C++ is quite low level, not dynamic at all, and not overly OO. C++ is very expressive in many situations due to its generic and automatic resource management features, which Obj-C lacks completely. (GUI code is typically horrendous, driver writing is nicer than in C)
- jimbokun 16y ago"(great for GUIs, not so great for writing drivers)" Probably the most succinct description of the relative strengths of Objective C and C++. Objective C for GUIs, C++ for drivers and embedded development.
- bonch 16y agoNeXTStep drivers were written in Objective-C using a framework called DriverKit, and this was on 90s machines. Objective-C is just C; there is no inherent performance penalty other than the dynamic dispatch of messages. In situations where that would actually be an issue, you'd be avoiding object-oriented features in C++ as well. However, driver performance bottlenecks are typically in I/O throughput, not the language the driver was compiled in. The fact OS X drivers are written in a C++ subset likely has to do with the demands of device manufacturers coming over from MacOS 9, just like the existence of Carbon was to appease application developers like Adobe.
- bonch 16y ago
- Maro 16y agoAll this C++ hatred is weird. If you need to do systems level programming (eg. write a database), and you want to go beyond C's code organization capabilities, and you can select a sensible subset of C++, it's a great language, and you get to control all aspects of memory and CPU. We're writing our database(s) in C++, and we're pretty much loving every minute of it, and would not switch to C, Java, Erlang or whatever. Of course we're a startup, so we got to select our own subset, write our own containers, etc: http://github.com/scalien/scaliendb http://github.com/scalien/scaliendb One downside is it's hard to find good C/C++ programmers on the market. The vast majority of applicants cannot complete our first interview filter (removing a characters from a C string and writing an instrusive stack in C++): http://scalien.com/pdf/job.pdf http://scalien.com/pdf/job.pdf
- cageface 16y agoOne downside is it's hard to find good C/C++ programmers on the market. It's interesting that C++ is increasingly becoming a niche skill. When I started programming you pretty much had a choice of C++ or VB if you wanted a job. Suits me fine though. A lot of the most interesting work (DSP, kernels, graphics etc) is in C++.
- pmjordan 16y agoI think C++'s popularity comes from the fact that it is essentially a better C. Which parts of it are better than C happen to be a matter of taste and for what you need it. I don't think anyone loves all of C++. But I think there isn't a viable competitor in the "C, but better" space at the moment. Go is probably too high level to be a complete replacement. D is... a weird case. I don't think it stands much of a chance in the market because it's not sufficiently better than C++. Overcoming C++'s momentum is extremely difficult at this point. EDIT: downvoters: if you think I'm trolling, please note that I've written more code in C++ than any other language. I would love a "better C" that's universally better than C++. If you disagree with my points, please elaborate.
- gaius 16y agoCurious; what makes ObjC not a viable competitor IYHO? D is doomed by the Phobos/Tango schism, no-one would risk their business on it.
- stelfer 16y agoMan I am tired of hearing what Zawinski thought about C++ fifteen freaking years ago. If you're good at C++, use it. If not, don't. If you want to get good at it, practice. How is that different from any language?
- rabc 16y agoI think the problem is in fact that nowadays developers jump into languagens like Python, Ruby or PHP because it's easy to learn, easy to install and run the environment and easy to code (you don't have to deal with memory or code optimization). C/C++ are the base for everything you code today. People start learn how to code with languages like Java, jump straight into OOP. That's wrong. Every developer should build at least a "hello world" in C, to know what's a real code. Ever developer must know about memory management, to scale optimize the code in any language. Other languages compilers do that for you, but you really need to know how it works.
- fogus 16y agoEvery developer should build at least a "hello world" in C, to know what's a real code. I'm not following. Are you saying that "Hello World" is emblematic of "real world" C code? My opinion is that "Hello World" serves one purpose only in C, to show how much the C compiler agrees with the host OS.
- rabc 16y agoThat was just an example. Developers should know what's a pointer and how to deal with it, because this is what happens everytime you hit the 'Build and Run' in compiler or run your Python script. And even a hello world in C can show all of that.
- l0nwlf 16y agoAnd why should developer bother to know how to deal with pointers ? And since when does writing "Hello World" in C teaches you how to use pointer and how to deal with it.
- roel_v 16y ago"And why should developer bother to know how to deal with pointers ?" Because if you don't even know the most basic things like the stack and the heap and memory addressing and the mechanics of calling functions, how can you expect to be a "developer"? Fine, let people start learning with languages that abstract all of that away, but for a well-rounded, complete education as a programmer (I'm not talking school-eduction, I'm talking general education) you need to know about these things.
- freedrull 16y agoThere are subsets of C++ that I just find too useful to pass up, particularly STL data structures like strings and vectors. Why shouldn't I use them? I'm just going to have to keep using them until I "blow my whole leg off" as they say.
- prog 16y agoI have to agree. I like STL + Boost a lot. I hope to try glib + C sometime. From what I see, that might allow me to C and still meet standard application needs.
- freedrull 16y agoGood point, glib offers a ton of useful functions: http://library.gnome.org/devel/glib/2.6/glib-String-Utility-Functions.html http://library.gnome.org/devel/glib/2.6/glib-String-Utility-... As you can see, its no std::string, but it can still save you some time.
- bhavin 16y agoThe following statement made by the Author doesn't sound like a programmer (leave C++ expert alone). "I think I once managed to read all the way through Stroustrup’s The C++ Programming Language and have looked at at least parts of The Design and Evolution of C++. But I have never done any serious programming in it." All I can say is, any programmer worth his mettle would make such a statement... Going through Stroustrups's book isn't possible if you're not interested in C++ programming (given that its not part of For Dummies series), IMHO. It is exactly like comparing it to a Novel. A programming guide is not about reading, its about learning.
- apu 16y agoThe author is Peter Siebel, a fairly well-known lisp hacker and author of Practical Common Lisp. While he's not a C++ programmer (and doesn't claim to be), you can't say he's not a real hacker. http://www.gigamonkeys.com/book/ http://www.gigamonkeys.com/book/
- phugoid 16y agoI'm not sure what you mean. Have you read Stroustrup's book? It was my first "practical" intro to object oriented programming, and I struggled with it. I would describe it as Byzantine technology explained with an economy of words that approaches poetry, at least in the way you must ponder each sentence. And the exercises are stimulating, in the sense of a cattle prod. I enjoy that sort of thing, in reasonable doses. Since then I've stayed away from C++ unless it's externally imposed, and built things with C and Python. I like a language whose basic features can fit in my small brain, a language that gets out of the way.
- js2 16y agoThere is some decent code in Doom Classic, but it is all C, and I would prefer to do new game development in (restrained) C++ … I had been harboring some suspicions that our big codebases might benefit from the application of some more of the various “modern” C++ design patterns, despite seeing other large game codebases suffer under them. I have since recanted that suspicion. http://bethblog.com/index.php/2010/10/29/john-carmack-discusses-rage-on-iphoneipadipod-touch/ http://bethblog.com/index.php/2010/10/29/john-carmack-discus...
- dan00 16y agoWhy we're using C++? Because we're writing 3d graphics and memory heavy gui applications for the engineering world. In this regard the combination of Qt and OpenSceneGraph is quite nice. I really can't understand, how someone can favour C for C++. Ok, C is the easier language, but the better abstraction capabilities of C++ outweighs this on a big code base.
- cletus 16y agoThe real shame about C++ is that it's the only mass market C-level language with advanced features built on top of it. Don't get me wrong: I agree with the author and his interviewees. I think C++ is a horrible language for the very reasons described: everyone uses a different subset of it and it's hideously complicated. For a more current view, see Linus Torvalds' comments [1] [2]. What I would like to see is a language very much like C (being low-level) with a few features built on top. What those features are I guess is the real trick. One thing I like about C++ is the constructor/destructor mechanism. It's very explicit. The trend now is towards garbage collection (which, admittedly, you can implement in C++). This is a trend I largely agree with. It's quicker and cheaper to write software that way (IMHO). But there is still a place for simper schemes as all GCs I've come across have issues. One thing I think such a language shouldn't be is object-oriented. To quote Joel Spolsky [3]: > A lot of us thought in the 1990s that the big battle would be between procedural and object oriented programming, and we thought that object oriented programming would provide a big boost in programmer productivity. I thought that, too. Some people still think that. It turns out we were wrong. Object oriented programming is handy dandy, but it's not really the productivity booster that was promised. Or at least such objects should be very limited in scope. Linus addresses some of the reasons for this, such as knowing which function is being called by simply looking at a code snippet (typically a patch in his case). When writing low-level code I certainly do much prefer C over C++. But having the tools to build automatic reference counting into C would be really nice at times. [1]: http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918 http://thread.gmane.org/gmane.comp.version-control.git/57643... [2]: http://www.realworldtech.com/forums/index.cfm?action=detail&id=110618&threadid=110549&roomid=2 http://www.realworldtech.com/forums/index.cfm?action=detail&... [3]: http://www.joelonsoftware.com/articles/APIWar.html http://www.joelonsoftware.com/articles/APIWar.html
- jmspring 16y agoOne thing to remember, especially when considering the discussion of C++ at Netscape, it took awhile for most compilers to implement a consistent set of the C++ features. Netscape was being built across a dozen or so platforms and this was a major concern. If you have built Mozilla recently, the process to do so is not a couple of click action it is somewhat involved. It was worse way back when. I've used C++ at the last for companies I have been involved with. The only consistency has been that no place used the same subset of C++ features. It usually boils down to what subset the team members are comfortable with. Variations have included exceptions or not, whether or not to use multiple inheritance, STL or Boost (yes, boost isn't really part of the C++ standard, but things like shared ptrs are in TR1), whether or not to use TR1, etc. I personally don't have a strong opinion, but there are people that abuse C++ in ways that produce lousy code -- classes as a way to have nearly global variables, the whole C with classes approach, etc. You really should use the right language for what you are working on and that plays well with any libraries you may want to use.
- cpeterso 16y agoFor curious folks, here is Mozilla's C++ Portability Guide (last updated July 2010, so it is still pretty recent). It is not a style guide. It contains some good lessons about writing portable code for "25 different machines and at least a dozen different C++ compilers." https://developer.mozilla.org/index.php?title=en/C%2B%2B_Portability_Guide https://developer.mozilla.org/index.php?title=en/C%2B%2B_Por...
- brown9-2 16y agoPrevious discussion on this same article: http://news.ycombinator.com/item?id=885482 http://news.ycombinator.com/item?id=885482
- oiuyuiopiuy 16y ago>..better than C++ unless efficiency is a concern Like other construction materials are better than steel unless strength and reliability are a concern.
- deleted 16y ago[deleted]
- jarin 16y ago"I think the decision to be backwards-compatible with C is a fatal flaw." --Guy Steele The funny thing is Objective-C is also backwards-compatible with C and there is a huge world of difference between programming in Objective-C and programming in C++.
- bonch 16y agoIt's not so much that it's backwards-compatible with C so much that it is C. It's plain C with a class and run-time messaging system built on it. Message sends are translated to C function calls by the compiler.
- tjr 16y agoWhile Objective-C is backwards-compatible with C, it doesn't tend to be as noticable as much as it is with C++. Objective-C feels like a markedly different language in which you can do inline C if you want to, while C++ feels like more of an extension of C.
- maayank 16y agoI don't know, I enjoyed my time doing C++ work. I think the key sentence is this: "I love to see how they do things because I think they don’t rely on it for the stuff that it’s not really that good at but totally use it as almost a metaprogramming language". Using templates, it has by far the best metaprogramming abilities in a object oriented language. I haven't used Smalltalk, but I've done production code in C# and Java and whenever using them I always yearned to the metaprogramming abilities of C++. Slowly but steadily I'm gaining ground on Lisp, so who knows, maybe lisp macros will satisfy this metaprogramming need in the near future :)
- sedachv 16y agoIf you want to see what C with macros would look like, check out C-Amplify: http://www.cliki.net/c-amplify http://www.cliki.net/c-amplify
- 16s 16y agoI really enjoy C++. It's a "live and let live" language. Pick what you want to use and be happy. Sure, not everyone picks the same pieces to use, but like in everything, humans will have differences and C++ allows and encourages that. You can do procedural, functional, OOP, generic, template meta-programming etc. It has something for everyone and does not try to force anything down your throat. That is why I love it. I use it daily and am very productive with it. Edit: grammar
- loup-vaillant 16y ago> does not try to force anything down your throat. It forces me to relinquish a host of assumptions about most programs. This is a huge source of bugs. > I use it daily and am very productive with it. Meaning, you write lots of code? Or you solve lots of problems that weren't introduced by C++ in the first place?