Re: Common programming mistakes?
- From: "cr88192" <cr88192@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 3 Mar 2006 07:51:39 +1000
<rodneys@xxxxxx> wrote in message
news:1141295434.583975.190120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,I would add:
do you know whether a "list of common programming mistakes"
exists? I think of some kind of list that states the most common
programming errors together with their frequency and the cost to find
them (measured in fraction of total developing time).
For example, I think of something like:
- uninitialized variable (now reported by most compilers)
- accessing "dead" objects (freed memory, closed file handles,...)
- a declaration hides another declaration
- declaration/definition mismatch
- private member instead of public member (this is a design error)
- resource leaks (memory,...)
- unwanted side-effect
- ...
(I have omitted the frequencies and costs since I don't know them).
uninitialized memory (eg: using malloc and forgetting to use memset or such
to return it to a sane state);
typing the wrong number of function args or typing them in the wrong order,
or calling the wrong function (though not particually damaging for the most
part, these kind of error are particularly common in my experience...).
the former can be solved in one of a few ways:
allocator functions that always initialize memory (actually, I do this
normally, but every so often writing standalone code, I can forget the
memset...);
functions that create the object (more typically with more complex types,
which need values initialized, eg, to something more complicated than 'all
zeros').
the latter is often caught by the compiler, but sometimes not caught at all
(if the args match, but the function is wrong).
additionally, I typically (anymore) compile my code with options that
require all functions to have prototypes, and use some (custom written)
tools to mine the source files for prototypes which are written to a
specified header.
this is, imo, not just useful for making sure functions are called
correctly, but also helping enforce modular seperation (at least on some
level).
Additionally, it would be interesting how such a list has influencedyeah.
the design of programming languages:
- accessing freed memory, memory leaks -> garbage collection
- declaration/definition mismatch -> type checking
- unwanted side-effect ->
declaration of read-only objects, side-effect free languages
- ...
Regards
rs
.
- References:
- Common programming mistakes?
- From: rodneys
- Common programming mistakes?
- Prev by Date: Re: Best Programming Language For Standalone Application
- Next by Date: Re: Common programming mistakes?
- Previous by thread: Re: Common programming mistakes?
- Next by thread: Re: Common programming mistakes?
- Index(es):
Relevant Pages
|