11 ms·
Why not just use C++?
by ndesaulniers 10y ago
Why not just use C++?
- astrodust 10y agoAs a long-time C++ programmer I can say there's a lot of reasons to not use C++, but still, yeah. What about D? Rust?
- frostirosti 10y agoC++ isn't strictly a superset of C! Which I always found crazy. Some C will not compile for C++.
- YSFEJ4SWJUVU6 10y agoWhy did you find that crazy? They are 2 fully separate languages that have both evolved after the latter (C++) was first introduced.
- EnFinlay 10y agoFor people who aren't professionally familiar with C or C++ it's an easy mistake to make considering how often things refer to "C/C++" like they are a single skill. Example: https://sjobs.brassring.com/TGWebHost/jobdetails.aspx?jobId=342549&PartnerId=25872&SiteId=5512 https://sjobs.brassring.com/TGWebHost/jobdetails.aspx?jobId=...
- jacquesm 10y agoOnce upon a time there was this thing called 'cfront'. Cfront took C++ and turned it into C which you then fed through your compiler. At that time mixing C and C++ was trivial, especially because C++ was still quite simple and the C compiler was the target. But after that things got more complicated. C evolved, several times in fact since that time and the C++ standard evolved as well. Leading to the impression that C and C++ are merely the old and the improved version of C but it is probably much better to think of them as two distinct species that share a common ancestor, where one of the two had some very radical mutations.
- loeg 10y agoIt would be relatively easy for C++ to add some kinds of C compatibility, and they just haven't bothered to. (E.g., the "static" keyword for parameter array sizes.) It's a little annoying for shared headers that have to be used in C and C++ programs.
- elastic_church 10y ago"5 years of Java/Javascript, with emphasis on PHP" Contact Pro IT Recruiting where we know our candidates, Referral bonuses too!
- dfrey 10y agoWhen people use the term "C/C++", I assume that they don't know either language well.
- TorKlingberg 10y agoI wouldn't call them "fully separate". Mixed C/C++ codebases are still fairly common, which works as long as the interface between them is in C.
- astrodust 10y agoMixed C, Objective C and C++ code-bases are still fairly common. That's not to say they're the same language.
- umanwizard 10y agoWell, your argument doesn't really prove anything, as Obj-C is actually much closer to C than C++ is.
- w8rbt 10y agoThey have separate ISO standards. IMO, this makes them fully separate. C - ISO/IEC 9899:2011 C++ - ISO/IEC 14882:2014
- AnimalMuppet 10y agoBut the standards have made some effort at avoiding gratuitous incompatibility, and have even introduced changes to reflect changes in the other standard. Also, much C code is still valid C++. Sure, you can write code that isn't, but I would guess (pulls a number out of nowhere) that 90% of the valid C code is also valid C++. That makes them languages that have separate standards, but not completely independent standards, that share a whole lot of source code. That's something less than fully separate in my book.
- deleted 10y ago[deleted]
- samfisher83 10y agoCan you provide C code that will not compile with c++ compiler?
- msoucy 10y agoSure: struct Foo { int virtual; };
- metaobject 10y agoYou're being pedantic about reserved words?
- spc476 10y agoI had that same problem. I wrote a C library [1] that has a structure field named "class". It's "class" because the protocol being described (DNS) calls that particular field "class" [2]. And I'm not about to pay lip service to an abomination like C++ [3][4]. [1] https://github.com/spc476/SPCDNS https://github.com/spc476/SPCDNS [2] https://github.com/spc476/SPCDNS/blob/ca5052c3d0c3252071a18ebbada808a7b536c860/src/dns.h#L255 https://github.com/spc476/SPCDNS/blob/ca5052c3d0c3252071a18e... [3] I am NOT a fan of C++. [4] But I had to anyway, but I used the C pre-processor to rename the field.
- camgunz 10y agoYeah I super hate this. There's no other language that requires other languages to contort themselves like C++ does. Every time I see `#ifdef __cplusplus` or `klass` my blood pressure spikes.
- astrodust 10y agoHere's a bunch of examples: http://www.geeksforgeeks.org/write-c-program-wont-compiler-c/ http://www.geeksforgeeks.org/write-c-program-wont-compiler-c...
- Chromozon 10y ago
- bobbyi_settv 10y agoIt would be hard for it to be a completely strict superset of C because that would require not introducing new reserved words (like "class") since those end up being legal variable names in C but not C++.
- frostirosti 10y agoWhy not just write another language, that compiles to machine code, but doesn't totally enforce type safety. Call it Iron.
- lacampbell 10y agoAnd make sure Iron has a small group of annoying, hardcore fans who relentlessly disrupts any thread about C or indeed programming in general with their ham fisted advocacy.
- geofft 10y agoThat seems annoying. It's probably a lot better to have a large group of hardcore fans of C who relentlessly disrupt all of programming in general with vulnerability-riddled code. Make sure they're writing code instead of disrupting any discussion threads, that will make sure they're not annoying.
- jacquesm 10y agoC has sharp edges, and buffer overflows are bad, we can all agree on that. Still, there are good ways to advocate a language and there are bad ways. Iron fans are in-your-face to the point that it crossed a line for me in a way that no other language supporters have and I haven't coded in C for a long time now so I don't feel like I have dog in the race.
- jacquesm 10y agoI wonder if the Iron fans realize that they are doing more harm than good the way they go about this. It reminds me of the perl zealot days.
- oblio 10y agoThe Iron fans are doing a bit of harm but that Perl zealotism is one of the things that made it wildly popular in its day. And unlike Perl, Iron development is structured, not "organic" a la Larry Wall/Perl. I'm not an Iron zealot but I do believe that there rarely is such a thing as bad publicity :)
- catnaroek 10y agoCello and C++ are have very different design goals. Cello is essentially a dynamic language implementation on top of C, and uses runtime reflection in places where a C++ programmer would probably prefer compile-time template hackery.
- int_19h 10y agoIdiomatic C++ is not like Cello at all. But it still allows you to do all things that Cello does - and most of them wouldn't be macros then, but classes and overloaded operators on them.
- catnaroek 10y agoSomehow I doubt C++'s built-in object system will allow you to create classes (yes, classes, not objects) and/or alter their vtables at runtime. (I know, vtables are an implementation detail. You still get the idea.)
- int_19h 10y agoNot anymore so than the C one - it's just as static. The point is that building blocks that you get from C++ are higher-level even so - classes, operator overloading, template metaprogramming etc - which should make it possible to implement something like Cello with a lot less effort (and hacks).
- lacampbell 10y agoslow compile times, complex language, sanity
- IshKebab 10y agoCompile times aren't that slow, and the language is barely less complex than this insane hack. In fact C++'s complexity allows libraries to make their use a lot simpler. Consider string concatenation in C++ and C. Which is really simpler? The main reason I can think not to use C++ is that C has a simple stable ABI so you can easily use C libraries from many languages and compilers. But you can always wrap C++ libraries in a C API so that's not a huge concern. Just a pain.
- kbwt 10y ago> Compile times aren't that slow I beg to differ. C++ encourages placing more code than strictly necessary into header files. Even the standard headers such as <algorithm> add considerably to the compile time, and they keep getting larger with every revision of the standard. When you are making incremental changes, it accumulates to a lot of time spent waiting.
- gruez 10y agouse precompiled headers?
- comex 10y agoPrecompiled headers never worked well due to a variety of limitations. C++ modules, on the other hand, will be like precompiled headers done right. If they ever get standardized. They didn't make it into C++17, and the prototype implementations in Clang and MSVC are incompatible with each other, but I guess it'll happen someday…
- gruez 10y ago>Precompiled headers never worked well due to a variety of limitations. want to elaborate? i use MSVC's implementation and never encounter any problems with it. then again, i also don't work on large projects, so i would like some insight.
- feelix 10y agoThat's like saying "Why not just use lisp?" to a python programmer. They're entirely separate languages (albeit it they do share some commonalities, but not as many as you might think). C is my main language and I dabble in C++. I really dislike C++. I love C. I welcome any efforts to add a bit of higher level functionality to C. I have no desire (ever) to switch to C++.
- loeg 10y agoC programmer here. Cello isn't really C. So as long as you're using something that isn't quite C, and you want an object model, I think "why not C++?" is a reasonable question.
- AnimalMuppet 10y agoBut it didn't look to me like Cello was an object model. To me, it felt more like Perl or Python than C++ - more like a dynamic scripting language.
- webkike 10y agoLooks like C to be. Just some macros and function calls.
- khedoros1 10y agoIf someone showed me a sample of the code, out of context, I wouldn't have guessed it was C. Maybe Javascript (with the "var" declarations).
- feelix 10y agoWhy would you say that "Cello isn't really C"?
- orange_fritter 10y agoIt's arguable that extensive use of macros and faux-dynamic-typing violate the ideology of C that makes it simple and predictable.
- jokoon 10y agoA good and valid reason would be compiler availability. C++11, 14 and 17 might not stable for every compiler out there. C++11 and further can be fancy, and not be supported in every possible platform like exotic ones. Bad reasons would be to talk about the gimmicks of C++, but generally it boils down to programmers being taught well about the language, because it's not an easy one to understand fully, as there many weird pitfalls. C++ still has to fix some its flaws, like compile times (this should be improved with modules). So to put it simply, you can still do good work with C because C compilers are just simple and straightforward. When you don't need C anymore (because you only use for it's size and speed, not for the high level), you use something more high level like python. C++ should allow programmers to do everything, but C++ is not perfect and not fully accessible to everyone.