Live data from Hacker News

The Unreasonable Effectiveness of C

damienkatz.net

241–250 of 394 posts

Re: The Unreasonable Effectiveness of C

#241
post #47
post #36

Earlier quoted context omitted.

> a barely functional string type There's a string type in C? All I see are character arrays and a few (poorly thought out) conventions for using them.

It may be cumbersome, but C has string handling: http://en.wikipedia.org/wiki/C_string_handling

This is an article about the standard library. C has no built in string handling. As an example, there are embedded systems that do no have support for string types due to a lack of support for libraries that handle it, yet they are 100% compliant with the C spec.

Re: The Unreasonable Effectiveness of C

#242
post #19

Earlier quoted context omitted.

You can wind up with "an unmaintanable mess riddled with security holes" in any language -- that's not unique to C. Regarding the flaws you have mentioned in C: Its flaws are very very well known, and this is a virtue. All languages and implementations have gotchas and hangups. C is just far more upfront about it. And there are a ton of static and runtime tools to help you deal with the most common and dangerous mist…

Security holes you wind up with in a Java or whatever codebase take the form of logic errors allowing for compromise of user information, or SQL injection or command injection. These are bad, they totally compromise data and systems. Security holes in C applications allow for the injection of low-level programs. This is way more annoying, IMO. also the static and runtime tools for C are good, and getting better, but…

Agree and in C you still have all the bugs of the type that you describe for Java or whatever...

It just there is a lot of C out there which means we will see it for ever in our systems somewhere. It will get better over time as tools improve the existing C code base.

Re: The Unreasonable Effectiveness of C

#243
post #65

Earlier quoted context omitted.

> It's a tool for some jobs; definitely not all. I'd completely agree. I would not use C for doing any web platform work (writing a REST service as you say). I may write a webserver in C if I had tight memory constraints. Where I see C still being very useful: embedded applications, drivers, and latency sensitive code. When you are trying to push the most I/O possible through a network interface or disk interface, C…

I have done low-level and mobile programming on very restricted platforms and I cannot see any reason why in the world I would use C instead of C++. Basically there is always an opportunity to use C++ if you can use C. Myths that C++ is slower are spread by people who just do not know C++ well or are not skilled/clever enough to use it.

Bravo. I had to read 15 minutes worth of comments to finally find one person who actually knows the truth. And this little gem was downvoted. Bravo.

Re: The Unreasonable Effectiveness of C

#244

Earlier quoted context omitted.

And can't be _implemented_ in any language. C gives you at least the charming fact that you can implement one without any overhead of objects, classes, implicit memory management or some other concept, just having a lightweight implementation that you may use in an environment without any libraries, like std or else..

So what you're saying is that C lets you write it on your own. In fact, and this might sound crazy, but you can do that exact same thing in C++, it's just that people don't because the C++ standard library provides plenty of performant and featureful data structures for you. Besides, anything the C++ standard template library map does when implementing a red-black tree is exactly what you would need to do if you wrot…

I'm confused.

C has libraries too. I personally like the headers used by openbsd: http://www.openbsd.org/cgi-bin/cvsweb/src/sys/sys/tree.h?rev...

Re: The Unreasonable Effectiveness of C

#245
post #121

Earlier quoted context omitted.

well the thing is, it also works for std::vector , or std::vector , or anything you want. Last time I checked in C you'd have to either duplicate all your array code for each type or resort to something like void*. Only for that I'd use C++ (yes, you can use it without classes if you want).

Last time I checked in C, all pointer types where the same storage size. There's no need to define the same data structure multiple times by using templates. You just use casts.

Nope. There is no need in C for all pointers to be the same size. An implementation is free (and there indeed, exist some) where a char* is a different size from an int. You can* safely cast any data pointer to void, and a void back to any data pointer. POSIX requires that function pointers can do this; the C standard doesn't require it.

Now, that said, it is possible to write generic link list routines (I've done it) but the devil is in the details.

Re: The Unreasonable Effectiveness of C

#246
post #211

Earlier quoted context omitted.

Really?! Have you ever looked at what InteliJ allows as refactoring tools?

IntelliJ Idea for Java?

Yes.

There are lots of refactorings that cannot be done by simple search and replace, even for C, because they require semantic knowledge of the language.

Re: The Unreasonable Effectiveness of C

#247
post #18

Earlier quoted context omitted.

That's the IDE not the language. Java, itself, does not highlight your syntax errors. Nor does C. There are IDEs out there that will do exactly the same thing for you for your C code.

The difficulty of writing static analysis software does depend on the language, though. In Visual Studio, for example, intellisense and autocompletion are vastly superior in C# compared to C++. As a matter of interest, which C IDEs are you referring to? I'd like to check them out.

Try Xcode 4.5.x (wich uses Clang as the default C compiler).

VS2012 has similar capabilities for C++.

Re: The Unreasonable Effectiveness of C

#248
post #77

Earlier quoted context omitted.

The article argued that C was effective in practice, not that it was better than X in some other sense. Would you prefer to write production code in FORTRAN, ALGOL 60 and 68, Turbo Pascal, or Smalltalk to writing it in C today?

Yes. Though I tend to use PLT Racket these days when the choice of language is not constrained by other factors.

Seriously? Actual production code in ALGOL in 2013? If I ever had to deal with that code, I think I'd feel about like you would have if I wrote this comment in Aramaic because I prefer it to English on numerous grounds. I'd very much prefer the extremely unpopular Racket which is at least alive to some degree.

I think the author's criteria for "effectiveness" are very much different from yours, hence the different conclusions.

Re: The Unreasonable Effectiveness of C

#249
post #77

Earlier quoted context omitted.

The article argued that C was effective in practice, not that it was better than X in some other sense. Would you prefer to write production code in FORTRAN, ALGOL 60 and 68, Turbo Pascal, or Smalltalk to writing it in C today?

Yes. Though I tend to use PLT Racket these days when the choice of language is not constrained by other factors.

[deleted]

Re: The Unreasonable Effectiveness of C

#250
post #3

To nitpick on a single statement: > C has the fastest development interactivity of any mainstream statically typed language. What? Despite all its shortcomings, Java in a modern IDE effectively has zero build time. The level of interactivity is as fast as that of interpreted languages. I haven't seen anyone manage this with C yet.

I have worked on several projects in Java (using Eclipse as an IDE). In my experience there is a 'significant' latency between when I hit run, and my program starts. (My suspicion is this time is spent starting the JVM, not compiling). Every (non kernel) C project I have worked with has effectively 0 build time after making changes. This is because they all used make which (like Eclipse and likely all IDEs) only reco…

As a tip I suggest running your code in debug mode. Which allows you to rewrite method contents as the program is running. If you place a break point in the method you are working in every time you save the program will reenter the method. I usually work in this mode.

JRebel is also worth investigating if you are getting paid to work with java code.

Post reply on HN