How do you style your source code?

Dear All,

how do you organize your source code of a big project?
Normally I try to follow the programming style guides for c++ or Java and now I want to adopt them, as far as possible, for Igor. Therefore I use a lot of set- and getter functions and also like to have a header file as in c++. If I try this and put all the constants to this the calling procedure file didn't know the constants. Is there any possibility for this?

But the most important question for me is, what kind of style guide do you use?

Thanks,
Hi,

well as Igor procedures are not object orientated, there is no use for getters and setter functions. And I also think that every programming language deserves its own style.

First question would be, how big is big?
Are we talking about 500 lines of code, or something like 400 functions in 10 files compromising >10000 lines of code?

In general I'll try to follow:

  • Prefer builtins operations instead of homebrown algorithms, e. g. DeletePoints, Extract, MatrixOp are underrated.
  • Use #pragma rtgGlobals=3 and enable "WAVE/NVAR/SVAR Checking".
  • No macros (only in very rare cases).
  • Very few global variables.
  • Use free waves for temporary waves.
  • Write your code as much as possible without SetDataFolder, nearly all functions/operations work with datafolder references.
  • Use small functions, so that they are easy to document. This is especially important as there is nothing smaller than function level block scope. Small is half the screen height.
  • Document them, at least one sentence per function, complicated functions deserve also parameter documentation.
  • You can quite quickly split the project into multiple files, as static functions help you to minimize the exposed API.
  • If the project gets really large use Independent Modules, maybe even RegularModules inside them.
  • Properly split the code into GUI and non-GUI code. This also makes unit testing possible.


I'm also currently playing with unit testing[1] and doxygen[2] docu for procedures.

[1]: http://www.igorexchange.com/project/unitTesting
[2]: http://www.igorexchange.com/project/doxIPFFilter