Thread: Advice...

  1. #1
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547

    Advice...

    A philosophical question for C programmers... (just C... please)

    What's the best advice you ever got regarding programming in C?

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    What's the best advice you ever got regarding programming in C?
    "Compile often; test often."

    Soma

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Probably how to compile with warning levels turned up. That, or to make it clean and readable. (But I don't think anyone ever actually told me the latter, it's just something I do.)


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    To add more comments (as I didn't comment at all at the time)

  5. #5
    Registered User
    Join Date
    Jul 2010
    Location
    Oklahoma
    Posts
    107
    CommonTater,

    The best advice that I received about programming in C came from a professor who would call a program "wrong" if it were poorly formatted or difficult to read, in conjunction with Paul S. Wang's text: An Introduction to ANSI C on UNIX (isbn: 0-534-14232-X). On page 90, Wang summarized his advice...

    ...
    Advice on thinking in C was given. A recommended program-formatting style was also described. These principles form the foundation on which all the elaborate constructs of later chapters will be built. No time spent in their mastery should be considered wasted.
    ...
    The actual advice was given on pages 87-9, but it amounts to what we end up talking about quite frequently with regard to formatting, declarations, naming conventions and comments. Knowing the standards made later discussions easier and most importantly meaningful.

    I've found that a flowchart has been invaluable, but I'm not completely confident that is exclusively a C issue.

    The next most important thing, being familiar with the compiler one has chosen to employ. It is imperative for proper use of any language. Primarily because, messages vary from one to the next and getting settings fine tuned is usually system specific. For example, telling the linker which library to use, or where to find it and such "road blocks" would sometimes make for very long sessions in the laboratory. The professor was very clear about that as well....

    Later during the engineering courses, the various sorts of documentation styles were emphasized because it was essential to appreciate the body of work during the maintenance/testing phase. In fact, it would be very difficult, if not impossible, to perform maintenance/testing on large projects with out it. This leads me to a completely separate topic...revision control.

    On a side note, I don't mean to continuously quote Wang. His text is a favorite and it easy to get to. I did intentionally omitted his specific advice because there are all sorts of standards out there...not to mention something about copyright lawyers that makes me break out in a sweat.

    Best Regards,
    Kept the text books....
    Went interdisciplinary after college....
    Still looking for a real job since 2005....

    During the interim, I may be reached at ELance, vWorker, FreeLancer, oDesk and WyzAnt.

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    10
    Make sure you don't overcomplicate your applications, if there is an automated way of doing something, use it, don't try to make your own way up.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    1. Do the simplest thing that could possibly work - only consider more complicated routes if the simplest way isn't good enough. (A corollary of this is not to optimize early.)
    2. Always compile everything with as many warnings and errors as you can turned on (with gcc, at the very least use -Wall and -Wextra) and make sure it compiles without any warnings (with gcc you can use -Werror to turn warnings into errors).

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    There is a lot of stuff which is just good programming practice, regardless of the language.

    But one thing which is rather more C specific is KISS. C has so much flexibility that you can all too easily create monsters that cannot be debugged or changed. Yes, occasionally, you need to get creative for some reason or another, but for the most part, keep it obvious.

    A modern compiler with maximum warnings is the minimum.

    Anyone working professionally should be using additional tools like these:
    Gimpel Software PC-lint Overview
    Software Quality and Security Analysis | Coverity
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Apr 2011
    Posts
    33
    c can do anything...
    from hacking to kernel design.....
    (but i never succeded.)

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    For me it was "Think first, type later"...

    It came from a programmer sitting in his cubical, staring at the ceiling. I asked if there was a problem and he answered: "Nope. Just thinking it through before I commit to it."
    Last edited by CommonTater; 05-01-2011 at 07:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advice
    By zacs7 in forum Game Programming
    Replies: 3
    Last Post: 10-06-2007, 03:48 AM
  2. Advice?
    By cgsarebeast in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2007, 12:22 PM
  3. Need Advice
    By jamez05 in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2006, 11:21 AM
  4. advice
    By daman in forum C Programming
    Replies: 2
    Last Post: 04-19-2004, 10:30 AM
  5. Need your help, advice
    By Coconut in forum Tech Board
    Replies: 2
    Last Post: 10-09-2002, 08:23 PM