Slashdot Mirror


Best Practices for Programming in C

An anonymous reader writes "Although the C language has been around for close to 30 years, its appeal has not yet worn off. It continues to attract a large number of people who must develop new skills for writing new applications, or for porting or maintaining existing applications. This article provides a set of guidelines that can help you with your coding."

2 of 123 comments (clear)

  1. Re:Best practice? Don't use it! by pauljlucas · · Score: 5, Insightful
    ... most programmers don't have enough training to use a more complex language.
    C is a fairly complex language, e.g.:
    some_func( (void (*)(void*))x );
    C is really just glorified assembly language.
    I don't think this has ever been in distpute by anybody. However, it's still far easier to write in C than assembly.
    I think that C and 'C++ used as C' is the reason alot of commercial software is so bug ridden. Hopefully Java, .NET/.GNU, scripting languages and competent use of modern C++ are starting to change that.
    Java (and other "restrictive" languages) only prevent a small class of errors, e.g., memory leaks. They do nothing to prevent logic or algorithmic errors, and they all have their own gotchas. Try changing what hashcode() returns for an object at run-time after you've put in into a hashmap: have fun finding and debugging that!
    --
    If you reply, do so only to what I explicitly wrote. If I didn't write it, don't assume or infer it.
  2. Re:Using continue in place of the null statement? by AuraSeer · · Score: 5, Insightful

    It's even clearer to use curly brackets, but the article doesn't mention that either.

    IMO every loop should have brackets, and every 'if' statement too, even when not strictly necessary. They're as good as extra whitespace for visually separating chunks of code, and there's absolutely no downside to including them. I've never understood why many C programmers are so resistant to the idea of extra brackets.