7 ms·
>The first rule of C is don't write C if you can avoid it. Man, this is just lame. C is a really nice, useful language, especially if you learn the internals.
by Sir_Cmpwn 11y ago
>The first rule of C is don't write C if you can avoid it.
Man, this is just lame. C is a really nice, useful language, especially if you learn the internals. It requires discipline and care to use effectively, but it can be done right. The problem is that a lot of C programmers only know C and can't apply higher level concepts or abstractions to it because they've never learned anything else. This makes their code harder to maintain and easier to break.
- adrianN 11y agoI'd argue that it can't be done right for non trivial programs without enormous effort. Even software written by expert C programmers with years and years of experience contains bugs that are caused by C's unsafe features.
- workitout 11y agoI'd agree, there was a great book called Deep C Secrets by Peter van der Linden. The book itself is not without errors but still provided some useful insights to things I didn't realize I was doing wrong back when I coded in C.
- lostcolony 11y agoHe's not saying that C isn't useful, but that for most problems it's overkill. Why inflict the extra burden on yourself -for no benefit-? Most code being written can be done just as well in a language with garbage collection, that has more powerful abstractions and paradigms as first class citizens...why not take advantage of them? Of course you can write those higher level concepts/abstractions in C, but the point is, -they've already been written-, tested, and documented, by other people. Why write untested, undocumented code that reimplements those things when you have no compelling reason to?
- kqr 11y agoThere are even languages without garbage collection that makes a lot of things easier than they are in C. See Ada, Rust, ~~Go~~ D and others.
- TheCoelacanth 11y agoGo is garbage collected.
- kqr 11y agoWhoops, sorry. I meant D rather than Go, but I guess that is also sorta-kinda garbage collected.
- unscaled 11y agoD is also primarily garbage collected. You had an option to create scoped classes (allocated on stack) but it's apparently deprecated now. I think Swift would be a better example here. Or objective C with ARC.
- rhodysurf 11y agoRust is great, but I think C is much easier
- catnaroek 11y agoYou mean it's easier to write an incorrect program in C than a correct one in Rust? Of course! If you mean it's easier to write correct programs in C than correct programs in Rust, I'm afraid you're badly mistaken.
- bpicolo 11y agoI mean, Rust has a lot of high-level features that make it flat out easier once you get past fighting with the compiler...
- catnaroek 11y ago> once you get past fighting the compiler Actually, it's the very process of “fighting the compiler” (as you call it, though I prefer to view it as collaboration between a human who knows what he wants and a program whose logic codifies what is possible) that makes it easier to write correct programs in Rust/Haskell/ML/$FAVORITE_TYPEFUL_LANGUAGE.
- Tepix 11y agoErrors are human. It's easier and more dangerous to screw up in C than in other languages. Don't use it unless there's a good reason to.
- _ph_ 11y agoModula-2 was released in 1980 - a Pascal successor which offers faster compilations speeds (precompiled modules) executables as fast as C built ones and a very safe type system avoiding most common errors in C programs. It is sad it was mostly ignored for so long a time. Fortunately, Go picks up its heritage these days.
- xenadu02 11y agoIf I make a mistake in Python, C#, Java, Swift, Go, Ruby, Javascript, Haskell, D, Rust, et al I don't leak arbitrary contents of memory, smash the stack, overrun a buffer, or otherwise provide huge gaping security holes that allow arbitrary code injection. C is riddled with opportunities to do _just that_ with even the slightest mistake. Yes, I can make a logic error in any of the above languages that performs some operation a user shouldn't actually be allowed to perform. But I can't accidentally let the user read or write arbitrary memory locations. With the exception of unsafe blocks or similar mechanisms; being limited to these explicit scopes, most programmer's natural laziness leads to avoiding unsafe behavior whenever possible. It also greatly limits the scope of potential bugs, as well as testing and code review required.
- akira2501 11y ago> But I can't accidentally let the user read or write arbitrary memory locations. Many of the languages you mention contain an 'eval' method, and most use environment variables in less than transparent ways. I wouldn't be so sure of this claim.
- masklinn 11y agoUsing eval is not accidental.
- akira2501 11y agoYes, it easily can be. My point was, no language allows you to get away with ignoring security (e.g. there is no free lunch). http://blog.codeclimate.com/blog/2013/01/10/rails-remote-code-execution-vulnerability-explained/ http://blog.codeclimate.com/blog/2013/01/10/rails-remote-cod...