Re: give me some tips
- From: "Rod Pemberton" <do_not_have@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 12 Mar 2006 05:51:11 -0500
"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
.
- Follow-Ups:
- Re: give me some tips
- From: Keith Thompson
- Re: give me some tips
- From: Michael Mair
- Re: give me some tips
- From: Rod Pemberton
- Re: give me some tips
- References:
- give me some tips
- From: Yuri CHUANG
- give me some tips
- Prev by Date: Re: Learning C
- Next by Date: Re: Learning C
- Previous by thread: Re: give me some tips
- Next by thread: Re: give me some tips
- Index(es):
Relevant Pages
|