5 ms·
When people tell me that they love C, I don't get it. C is so tiny that if you're going to write anything non-trivial you either have to re-implement various c
by mikevm 13y ago
When people tell me that they love C, I don't get it.
C is so tiny that if you're going to write anything non-trivial you either have to re-implement various common data-structures yourself, or find appropriate libraries. No built-in string type, no vectors, no nothing. Also, the lack of generics makes for really ugly code, filled with void pointers and casts whenever you attempt to write type agnostic data structures such as lists, queues, etc.
It also seems that whenever I have to write in C, I end up writing code that painfully wants to be object-oriented, or implementing features that are already part of C++.
So why would you willfully pick to use C when C++ is around?
Heck, even if some sick reason you don't want to use explicitly use objects, at least you can enjoy some of the other benefits of C++ (e.g. its standard library).
- EliRivers 13y agoThere are many platforms that have a C compiler, but not a C++ compiler. Sometimes you just don't have the choice.
- georgemcbay 13y ago"...or find appropriate libraries." But... finding appropriate libraries is generally simple. Due to C++'s ongoing ABI issues C is, to this day, still the predominate language for library authors who want their library to be nearly universally consumable (in C, C++, Python, Go, Ruby, node/JavaScript, etc). That said, I agree with part of your point which is why I use Go when I can today (though it also isn't suitable to be a C-like universal library language for other reasons). Built in strings, interfaces, maps, etc remove a lot of the basic code level pain points without also introducing the overbearing level of language complexity of C++/stl/boost (and I say that as someone who spent nearly 10 years programming professionally in C++ and at one time misguidedly considered myself a fan of the language). Go is not so big on the full spectrum of traditional object orientation or generics, but once adapting to OO solely by composition and duck-type interfaces I haven't found either of those to be a big issue for me.
- to3m 13y agoI've found this too. It's rather turned me off using C for anything; in no time at all, I always find myself doing something that would be very straightforward in C++, but is a certain amount of bother in C. So (I ask myself)... what is this buying me again? What's the point? Fortunately, most C++ compilers' support for inline C code is excellent. Even gcc didn't get it wrong ;)
- icedchai 13y agoPeople love C because it's simple. Figuring out what some C++ code does can be very complex, depending on what particular features the previous developers decided to use. C is also the lowest common denominator, making it better for certain development tasks (I'm thinking of mainly lower level shared libraries.)
- pjmlp 13y agoI also don't get it. When I got to learn C, back in 1992, I was already doing system programming in MS-DOS with Turbo Pascal. A language with support for OOP, proper modules, blazing compile times, strings, vectors that don't decay into pointers, safer while offering the same low level features as C. C looked stone age to me, luckily I got into C++ a few months later and saw a language which gave me back most of the features Turbo Pascal had, with the advantage of being a language in the process of being standardized. I only used C when forced to do so during university assignments and on my first job. Sadly C's compatibility is what helped C++ to become widespread, but also the cause of many of its issues in terms of security. At least with modern C++ is possible to avoid Cisms as much as possible.
- maratc 13y agoSome people think that C is a better language than C++, and may disagree with you on standard library being a "benefit". You may try to look at "C++ FQA" at http://yosefk.com/c++fqa/ http://yosefk.com/c++fqa/ for an example.
- a8da6b0c91d 13y agoIf I recall correctly that FQA mostly bitches that C++ isn't Smalltalk, and offers no praise for C.
- maratc 13y agoNo, FQA only mentions Smalltalk once in passing: "Lisp, Smalltalk and Forth are examples of languages with almost no syntax." FQA mostly bitches about how C++ sucks, and comparisons to C are quite frequent.
- ketralnis 13y agoAnd yet your operating system and over half of your userland is in C. Must be doing something right.
- pjmlp 13y agoOnly if you are speaking about UNIX distributions, excluding Mac OS X.
- EpicEng 13y agoThe Windows and OSX kernels are written in C. Not sure where you got your info.
- pjmlp 13y agoSomehow the HN crash removed my comment. The MacOS X drivers are written in C++. Windows kernel code is being made C++ compliant given that C is a legacy language from Microsoft's point of view. Many new APIs since Windows XP are being made available only as COM objects. As of Windows 8, the DDK officially supports C++ and many of the samples have been updated accordingly.
- EpicEng 13y agoYeah, the comments refuting what you said were as well. OSX kernel is C. Drivers being written in C++ is irrelevant. Windows kernel is C, the fact that they are making it compilable by a C++ compiler is irrelevant. So what's your point exactly? Let us not forget you said that nothing outside *NIX was C, and you are wrong.
- pjmlp 13y ago> OSX kernel is C. Drivers being written in C++ is irrelevant. A kernel without drivers is useless. > Windows kernel is C, the fact that they are making it compilable by a C++ compiler is irrelevant. It is not irrelevant. Code compiled by a C++ compiler is C++, regardless how C fans try to bend it. Having this discussion since 1993. Besides many new APIs since Windows XP are COM only as well. C is legacy according to Microsoft, unless they change their mind about it. Even the latest C99 additions to their compiler were done as a requirement for C++11/14 compliance, not because they changed their mind. > So what's your point exactly? Let us not forget you said that nothing outside *NIX was C, and you are wrong. L4, Genode, OS/400, BeOS, Symbian are also done in C++. What other OS, non UNIX based with the same maturity as the list above, can you point out being done in C? UNIX based systems are the only ones that will be fully done in C due to their symbiotic relationship and the way their developers consider a sacrilege to use something else.
- 0x09 13y ago>C is so tiny that if you're going to write anything non-trivial you ... pretty much know exactly how you're going to write it from the start. Since C is so constrained it's very easy to design for, and you usually have a very clear idea of what you are getting into, even if that includes reimplementing a common data structure or using external libraries. And if you are using an external library, the API is not likely to surprise you. There are countlessly fewer ways to design something within the rules of the language in C than C++. Different people will see this as a blessing or a curse. For some situations it just makes sense. If your program revolves heavily around C libraries you will likely be forced into a C-like design anyway. And likewise, if you are designing a library with a primary interface in C. If you are already coding in this style, C offers some niceities to (ab)use that C++ doesn't (especially compound literals, designated initializers, and VLAs). It's easy to become familiar with C which makes it easy for C to be a go-to language (obviously this depends on your problem space.)
- mratzloff 13y agoWell, C is simpler than C++. That means it's simpler to understand exactly what is happening. It's not that far removed from an assembly language. And you really can't beat C for FFI. If you have a common library you want to share among many different platforms, C is the way to go.
- aryastark 13y ago> So why would you willfully pick to use C when C++ is around? There are many reasons to not use C. But C++ existing is not one of them. Over the 15 years or so that I've used C++, there is always the constant nagging feeling that I don't really know what is going on. My programs tend to work. But I often find that there are incredibly subtle nuances buried deep in the C++ run time model that are simply beyond comprehension. If you can keep all the rules of C++ in your head, then you are a god among gods. Today there are few reasons to even need C++. I tend to stick with C or go to Perl/Python. I don't really need a language that attempts to straddle the middle. Especially one that more often than not, gets it all wrong anyway.
- EpicEng 13y agoIt also seems that whenever I have to write in C, I end up writing code that painfully wants to be object-oriented, or implementing features that are already part of C++. So I guess you just don't really know/aren't comfortable with C. That's fine, but that hardly means that everyone else has the same problem. So why would you willfully pick to use C when C++ is around? Because they are two very different languages and have their own strengths and weaknesses? OO is not the "one true way", that has been shown time and time again. It's really not difficult to find a library for things you need in C. The fact that they aren't all available to include the moment you open your editor/IDE isn't a reason to use C++. I use both C and C++ regularly. I love a lot of things about C++, but it also brings a lot of baggage along with it. It is an extremely complex language and I have seen some really, terribly awful code written in it. I've seen bad C code as well, but C++ makes it easier to write bad code and harder to restructure it if you need to because you have to deal with much more abstraction. C++ also lends itself to writing code which contains very subtle errors in it. C makes that more difficult. I read your post and I just hear someone with little C experience who loves his objects and can't fathom doing things another way.
- klipt 13y ago> OO is not the "one true way" Personally, I think C++'s big win over C++ is not OOP but generics. You can do OOP in C if you want; you can't do generics efficiently and safely.
- fatca 13y agoIn what are these various common data-structures supposed to be implemented? Also in a language that already has them? We have to keep building and maintaining a kernel, a libc, and other basic infrastructure software. Should we also do that in a language that implements the missing things already? Maybe the CPU itself should implement these common data structures? What solution do you propose?