Re: give me some tips




"Yuri CHUANG" <yuri_1985@xxxxxxx> wrote in message
news:1142143263.604302.218540@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
So I desire to know some tips about writting a program perfectly.

There are two assumptions made in that statement:
1) that someone can always determine a method to solve every problem
2) that someone can always write a program which implements a solution
without errors

I'd start by learning how to solve some problems and write some programs
well. After solving and implementing
a few problems, you'll know whether you are better at "top-down" or
"bottoms-up" design. Each person has a
biological preference for each one (FYI, those who prefer "top-down" are N,
and "bottoms-up" are S, in Myers-Briggs personality Type Indicator).

Can
anyone give me some tips which are hardly learned from textbook or
easily ignored?

The following are my opinions for the C language are really are _specific_
to _my_ programming style. Others may not
have problems with the same areas of C that I do, so they probably have
their own list of issues. You'll need to develop
your own list of "problem areas" over time:

1) learn hexadecimal and the bit patterns for each value
2) don't forget your algebra
3) understand binary operations bitshifts, and, or, xor, one and two's
complement, etc...
4) use #define masks to extract bits from variables instead of using unions
5) include all the necessary include files, especially stdio.h and stdlib.h
6) avoid the use casts, except to ensure the type and precision of numerical
conversions and where you know it is necessary
7) avoid the use of type qualifiers (const, volatile, restrict), except
where necessary, because they can hide programming errors
8) avoid the use malloc(), except for dynamic data, because it leads to
memory allocation errors
8A) corollary: avoid the use pointers in main(), for the same reason
9) typedef structs and give them file scope (i.e., "global"), it can simply
certain problems


Rod Pemberton


.



Relevant Pages

  • Re: give me some tips
    ... your own list of "problem areas" over time: ... avoid the use of type qualifiers, except ... because they can hide programming errors ...
    (comp.lang.c)
  • Re: Which book is better for a begainer to study C language?
    ... *_The C Programming Language_, 2nd edition, by Kernighan and Ritchie ... Avoid the book "Practical C Programming" from O'Reilly. ... Avoid any book by Herbert Schildt. ... Schildt and provides an errata, but the errata is very incomplete and ...
    (comp.lang.c)
  • Re: Should I use "if" or "try" (as a matter of speed)?
    ... Shouldn't one avoid doing it the wrong way from the very beginning? ... make it "just work" the first time, you'll probably use the old code later on ... Extreme Programming ... that the refactor "make it right" stage must occur _now_, ...
    (comp.lang.python)
  • Re: My multipost-detecting usenet bot (David Filmer)
    ... A programming challenge:-D ... Cancels always run after the facts. ... to avoid is having your bot reply to a message that has been canceled ... unlikely, IMHO), but I'm not sure how to avoid it. ...
    (comp.lang.perl.misc)
  • Re: C needs a BOOST
    ... If, as Paul believes, there are awful things wrong with C++ standard containers, then it is important to avoid repeating those mistakes when extending C, and entirely on-topic to discuss what those mistakes were. ... I'd like to do some C++ programming professionally, but it seems not to be the language of choice in my chosen specialty, scientific computer programming. ... jacob at jacob point remcomp point fr ...
    (comp.std.c)