Re:Why the C Programming Language Sucks
by aburan28 on Friday August 21, 2015 @05:10AM
(#10096601)
The C language 'sucks' because you don't understand how a computer really works. Colleges should stop teaching Java and replace it with C/C++ because so few actually understand the low level inner workings of computers these days.
Re:Why the C Programming Language Sucks
by Horusiath on Friday August 21, 2015 @04:46AM
(#10096537)
WTF? You're moaning, that the systems programming language invented over 40 years ago has no means for automatic memory allocation management and high level abstractions. Sorry but this is just crappy post.
Re:Why the C Programming Language Sucks
by qznc on Friday August 21, 2015 @05:26AM
(#10096633)
The moaning is about the system language, which got its last revision in 2011 and still has not added a generic abstractions feature or RAII resource management.
Re:Why the C Programming Language Sucks
by bandrami on Friday August 21, 2015 @05:25AM
(#10096632)
OTOH C was invented because these exact same problems were being raised about assembly languages, and C addressed them with types and structures (which are, after all, abstractions to help the programmer allocate and manage resources).
And, before that, the assembly languages were addressing that problem with machine code.
No doubt in 10 years (whom am I kidding -- 10 months) whatever replaces Javascript will make the same complaints about it that this does about C.
Personally I find C pretty elegant for what it is, and it's the only thing I would use for serial comm programming, and since that's what I do mostly...
Re:Why the C Programming Language Sucks
by notacoward on Friday August 21, 2015 @09:11AM
(#10097183)
The biggest error the author makes isn't even stated explicitly. It's the underlying assumption that there's no reason not to have the language do this resource management for you. As we all know, however, automatic garbage collection does involve significant performance and predictability tradeoffs. Often, these tradeoffs need to be made differently for different kinds of code. A critique of C's design within its own problem domain (like stonewhite's in this thread) might be valuable, but a whine that treats all programming as the same is almost completely worthless.
Re:Why the C Programming Language Sucks
by lordnacho on Friday August 21, 2015 @05:16AM
(#10096608)
I think it's a question of what you're using C for.
C is an abstraction of a system. It has memory, file handles, and other things that a system has. That's why people write OSes in C. When you're writing an OS, what are you doing other than managing a resource? The 1/2/3 are necessary when they are the whole point of the language.
Of course it sucks to write something like a website in C when you can use a high level language like Python which has libraries containing plausible abstractions for web pages.
Re:Why the C Programming Language Sucks
by EmanueleAina on Friday August 21, 2015 @10:39AM
(#10097742)
To some extents, it depends on the definition of C: by the standard, you're right, you can't. But with some relatively common (GCC and clang) extension (ie. __attribute__((cleanup))) you definitely can, see g_autoptr() from GLib for an easy way to use it: https://blogs.gnome.org/desrt/2015/01/30/g_autoptr/
Re:Why the C Programming Language Sucks
by quesera on Friday August 21, 2015 @08:14AM
(#10096971)
> I cannot write an abstraction in C, which closes a file handle automatically.
Of course you can.
It's just a question of convenience, and whether the resulting style would align with idiomatic C. In my imagined implementation, it would look more like awkward JavaScript.
There are many many C codebases that are internally consistent but don't look much like textbook C. Sometimes C is the best choice even when it's less convenient.
Re:Why the C Programming Language Sucks
by tallanvor on Friday August 21, 2015 @05:23AM
(#10096624)
Another "Language X sucks because it's missing features I think are important" post...
But really, bashing C shows a complete lack of understanding of the history of computing. I wouldn't be surprised to find another post expounding on just how horrible assembly is.
Re:Why the C Programming Language Sucks
by stonewhite on Friday August 21, 2015 @05:20AM
(#10096615)
I think the proper rant would be about ambiguous spec which leads to strange outputs from different compilers, then results in very hacky ways to provide even some level of portability.
It may not provide enough abstractions to match your awesome Ruby on Rails application for your next great startup but that is OK. Lets try to remember that C was invented to avoid writing Unix in assembly, which all previous OS'es were written in. So abstraction-wise it supplies enough abstraction for its time and usage.
Re:Why the C Programming Language Sucks
by qznc on Friday August 21, 2015 @05:24AM
(#10096627)
C does not provide zero-cost abstractions like C++ does. This means for example that the standard library sort in C++ is faster than in C, because it can inline the comparison function.
Re:Why the C Programming Language Sucks
by forgettableuser on Friday August 21, 2015 @08:17AM
(#10096982)
Great point about this example being a code-size trade-off example and not an actual zero-cost example.
As for actual zero-cost optimization, Chandler Carruth who works on Clang at Google gave a talk at the 2012 LLVM Developers' Meeting warning people that C++ zero-cost abstractions are more myth than reality, and things developers expect to be zero-cost are often in-fact not. He goes into detail about how the optimizers work and what the challenges are.
Re:Why the C Programming Language Sucks
by kbart on Friday August 21, 2015 @05:29AM
(#10096648)
This article is basically a complaint that low level language does not support features of higher level languages. If you don't need manual resource management and you are working on web/desktop software - don't use C, there are better suited, high level, modern languages for that. But as an embedded programmer, I giggle every time I read that "C is dead/sucks".
Re:Why the C Programming Language Sucks
by qznc on Friday August 21, 2015 @05:22AM
(#10096621)
Yes, this is one of real reasons C sucks. C+RAII+Exceptions+Templates would be great, but C++ also adds a lot of other stuff unfortunately. You could use Rust, but that has a very different spirit [0] than C.
Re:Why the C Programming Language Sucks
by paulrpotts on Friday August 21, 2015 @11:20AM
(#10098070)
In 2015 I am getting paid to write thousands of lines of extremely efficient, extremely reliable embedded software in C. From my perspective it's a great language and I'm very, very good at it by now, having used written a lot of C since 1985 or so, when I first started to learn the language.
I do know other languages. I have used professionally, Perl, Python, Ruby, Scheme, Java, Objective-C, Lisp, Dylan, and others. I have been teaching myself Haskell in my bits of spare time for years now. I would love to be able to write some of these algorithms in my embedded work in Haskell, or an EDSL, and I think that is possible, but the fact remains that a lot of programming in the embedded space is all about managing state, and managing peripherals, which involves a lot of interrupt handlers, very low-level programming with event queues and tasks, and often a minimal OS (I'm using FreeRTOS right now) or, often, no OS at all (as in some code I've written professionally for Arduino boards and low-end Atmel microprocessors).
I am perfectly aware of C's imperfections and weak type systems, many of the safety pitfalls involved in working directly with machine words and pointers, and the relative lack of checking that most compilers do for you (compilers will often be perfectly happy to compile code that will mix signed and unsigned types in unsafe ways, or do widening or narrowing in unsafe ways, due to C's rather baroque rules for integral promotion and things like that). The partial equivalence (or, one might better say, automatic conversion under certain circumstances) between arrays and pointers is a source of endless confusion to newbies and the details of just how it works are a source of difficulty even to many experienced programmers. But after 30 years programming in C and 40 years programming altogether I can bang that shit out and make it readable and write good comments explaining what I am doing and very often my shit runs properly on the first try.
So from my perspective C is a great language. It has been the backbone of my whole career, although in truth I would love to do a lot more with Haskell.
C++ by comparison, which I've also used professionally, a lot -- does not even feel like language these days, but more some kind of endless, nightmarish research project where the best approach is to make sure you are not coming anywhere near the cutting edge.
Re:Why the C Programming Language Sucks
by Timmons on Friday August 21, 2015 @10:39AM
(#10097747)
Not defending this case of its use, but there is a time and place for 'goto'. Not many of them and people do use them for terrible things but in the right circumstance it is the right solution.
Only really posting this because I want to do my part to clear the 'goto' stigma that seems common in the younger programmers. It still exists because it can still do good ( sometimes :) )
And, before that, the assembly languages were addressing that problem with machine code.
No doubt in 10 years (whom am I kidding -- 10 months) whatever replaces Javascript will make the same complaints about it that this does about C.
Personally I find C pretty elegant for what it is, and it's the only thing I would use for serial comm programming, and since that's what I do mostly...
C is an abstraction of a system. It has memory, file handles, and other things that a system has. That's why people write OSes in C. When you're writing an OS, what are you doing other than managing a resource? The 1/2/3 are necessary when they are the whole point of the language.
Of course it sucks to write something like a website in C when you can use a high level language like Python which has libraries containing plausible abstractions for web pages.
Of course you can.
It's just a question of convenience, and whether the resulting style would align with idiomatic C. In my imagined implementation, it would look more like awkward JavaScript.
There are many many C codebases that are internally consistent but don't look much like textbook C. Sometimes C is the best choice even when it's less convenient.
But really, bashing C shows a complete lack of understanding of the history of computing. I wouldn't be surprised to find another post expounding on just how horrible assembly is.
It may not provide enough abstractions to match your awesome Ruby on Rails application for your next great startup but that is OK. Lets try to remember that C was invented to avoid writing Unix in assembly, which all previous OS'es were written in. So abstraction-wise it supplies enough abstraction for its time and usage.
As for actual zero-cost optimization, Chandler Carruth who works on Clang at Google gave a talk at the 2012 LLVM Developers' Meeting warning people that C++ zero-cost abstractions are more myth than reality, and things developers expect to be zero-cost are often in-fact not. He goes into detail about how the optimizers work and what the challenges are.
http://llvm.org/devmtg/2012-11/videos/Carruth-OptimizingAbst...
[0] http://beza1e1.tuxen.de/articles/spirit_of_c.html
I do know other languages. I have used professionally, Perl, Python, Ruby, Scheme, Java, Objective-C, Lisp, Dylan, and others. I have been teaching myself Haskell in my bits of spare time for years now. I would love to be able to write some of these algorithms in my embedded work in Haskell, or an EDSL, and I think that is possible, but the fact remains that a lot of programming in the embedded space is all about managing state, and managing peripherals, which involves a lot of interrupt handlers, very low-level programming with event queues and tasks, and often a minimal OS (I'm using FreeRTOS right now) or, often, no OS at all (as in some code I've written professionally for Arduino boards and low-end Atmel microprocessors).
I am perfectly aware of C's imperfections and weak type systems, many of the safety pitfalls involved in working directly with machine words and pointers, and the relative lack of checking that most compilers do for you (compilers will often be perfectly happy to compile code that will mix signed and unsigned types in unsafe ways, or do widening or narrowing in unsafe ways, due to C's rather baroque rules for integral promotion and things like that). The partial equivalence (or, one might better say, automatic conversion under certain circumstances) between arrays and pointers is a source of endless confusion to newbies and the details of just how it works are a source of difficulty even to many experienced programmers. But after 30 years programming in C and 40 years programming altogether I can bang that shit out and make it readable and write good comments explaining what I am doing and very often my shit runs properly on the first try.
So from my perspective C is a great language. It has been the backbone of my whole career, although in truth I would love to do a lot more with Haskell.
C++ by comparison, which I've also used professionally, a lot -- does not even feel like language these days, but more some kind of endless, nightmarish research project where the best approach is to make sure you are not coming anywhere near the cutting edge.
Had Pascal filled the role, we'd have long posts about Why the Pascal Programming Language Sucks. You know, aside from the one Brian Kernighan wrote.
Only really posting this because I want to do my part to clear the 'goto' stigma that seems common in the younger programmers. It still exists because it can still do good ( sometimes :) )