4 ms·
C is good and simple but C is not expressive. There are a whole hosts of situation where code has to be duplicated or slightly modified. For instance, it's real
by norswap 14y ago
C is good and simple but C is not expressive. There are a whole hosts of situation where code has to be duplicated or slightly modified. For instance, it's really hard to do good generic data structures in C without ending up with casts everywhere. Polymorphism is even worse.
For me, that really is the edge that C++ holds over C.
- Jimmie 14y agoI agree. I kind of wish there was a middle ground between C and C++. C++ is bloated but C is not enough.
- shuaib 14y agoObjective-C?
- agumonkey 14y agoIt seems that C++ really requires one to be subtle in his coding style. Stroustrup discusses this here: http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-Stroustrup-Cpp11-Style http://channel9.msdn.com/Events/GoingNative/GoingNative-2012...
- Leynos 14y agoDoes D not aim to fill this niche? (I suppose in terms of exposure and infrastructure, D is lacking relative to C and C++).
- heretohelp 14y agoNo, it's closer to a garbage collected Algol but with way more features.
- Jun8 14y agoPeople generally master and commonly use only a subset of C++, i.e. C+.
- CrLf 14y agoLike the old saying, "you can write cobol in any language". Polymorphism and "good generic data structures" (in the sense you are implying) are not a necessary requirement of elegant and maintainable code. It is part of the problem that programmers have taken OO concepts as the end-all of good code, and must apply those concepts everywhere even if that means implementing them from scratch at the cost of (unnecessary) complexity. Large systems have been written in C. Many large open-source projects use C. There is no evidence that these are less maintainable (in general) because of language choices. Some of these graft OO concepts onto C. GTK is noticeable for this (although it doesn't seem to be too bad for application developers, I'm afraid for those tasked to maintain the libraries themselves). Procedural programming is not a sin (if "procedural programming" exists at all today, as most of the simplest object concepts have become common practice and are now though as an integral part of it).
- cygx 14y agoLike the old saying, "you can write cobol in any language". As far as I know, there is no such 'old saying'. However, The determined Real Programmer can write FORTRAN programs in any language.
- pcwalton 14y agoParametric polymorphism (i.e. generics) is not an object-oriented concept.
- norswap 14y agoThe problem never was the lack of OO, the problem is that you have to repeat yourself. There will come a type when you have a type that behaves a certain way (certain members, argument of certain functions) and then you will make a type that is mostly the same thing, but then slightly different (maybe one attribute is replaced by something else). You'll have to adapt everything you reproduce a lot of your logic or jump trough very annoying hoops to have your existing logic work with this new type. If from OO, I could have only Java-like interfaces, it would probably be enough. Implicit type conversions could also work I suppose.
- luser001 14y ago> There is no evidence that these are less maintainable (in general) because of language choices. I have an example. The Squid proxy code used calling via function pointers everywhere as DIY polymorphism. That made it quite difficult for me (ymmv) to follow the code. Things like ctags would have worked if they'd used "real" C++ polymorphism. IMHO. YMMV.
- iambvk 14y agoLinux kernel has lists, etc. that can be used as generic data structures. IMO they are good enough for most purposes.
- norswap 14y agoWell the trouble is really polymorphism, and I was actually thinking more about polymorphic data structure: i.e. data structures where the elements are required to have certain methods callable on them. I agree this is typical OO design and could be approached in other ways, but none I know of are satisfactory.