how to read source code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • becker

    how to read source code?

    Hi, I am learning some code reading techniques for source codes written
    in C or C++. Could anybody give me any suggestions on how I can learn
    those techniques? Any book suggestions or info about good tutorials on
    web sites are appriciated. Thanks a lot in advance.
  • Malcolm

    #2
    Re: how to read source code?


    "becker" <becker@hotmail .com> wrote[color=blue]
    >
    > Hi, I am learning some code reading techniques for source codes written
    > in C or C++. Could anybody give me any suggestions on how I can learn
    > those techniques? Any book suggestions or info about good tutorials on
    > web sites are appriciated. Thanks a lot in advance.
    >[/color]
    C can be very difficult to read, because the language makes it easy to write
    what I call compileable gibberish.

    The main rule is that a compiler is much better at picking up syntax errors
    than a human. So don't expect to spot every missing semicolon. Unfortunately
    there are a few gotchas, e.g.

    for(i=0;i<len;i ++);
    str[i] = 'x';

    will compile cleanly and then produce a very strange bug as your string is
    extended, probably with garbage characters, and not set all xes at all.

    However most programmers are not pathological. Usually code is broken fairly
    logically into functions, and each function does a defined task. If you can
    work out what the function does, and what the parameters are, then it
    doesn't usually matter too much if you cannot follow the code. Most of the
    time the algorithm will be very striaghtforward and you can write code to do
    the same thing easily.

    A few functions will be the heart of the program, and may be difficult.
    However here your problem transcends computer language. If you don't
    understand the mathematics of a fast Fourier transform, for instance, then
    you will have to learn somehow. It will be very difficult to reverse
    engineer someone else's FFT() function and understand it that way.


    Comment

    Working...