Re: Common programming mistakes?




<rodneys@xxxxxx> wrote in message
news:1141295434.583975.190120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,

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).

I would add:
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 influenced
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
- ...

yeah.

Regards

rs



.



Relevant Pages

  • Re: Requesting advice how to clean up C code for validating string represents integer
    ... technical definition of a programming language) which in ordinary ... usage has a "wide variety of exact meanings in many walks of life", ... whether some random set of memory cells in a C core image, ... north-west relative to the rest of the Bay Area. ...
    (comp.lang.c)
  • Re: [EGN] Variable hoisting
    ... >>no idea of my programming abilities, ... >>be made by manually hoisting loop invariants. ... inversely correlated in common instances. ...
    (comp.programming)
  • Re: MAKEINTRESOURCE in win32asm
    ... > practical use, as there is no reason, in Asm Programming ... (which would also require a second read from memory to complete), ... haven't noticed it...you must have had some address pointer, ... ooh, "messages"...the value zero can mean "window created", the value ...
    (alt.lang.asm)
  • Re: A case for HTML as a programming language
    ... > language that can express any finite state machine can express any ... amount of external read/write memory, ... By contrast, a full computer with only HTML as its language, no real ... programming language in addition, and links only to static WebPages (no ...
    (comp.programming)
  • Re: The Great Debate V. What have changed ?
    ... I programmed using the Delphi VCL for years. ... > wanted more memory statistics than Delphi was giving me. ... To thoose with more than 5 years programming ... > overestimated egos. ...
    (alt.lang.asm)