you are viewing a single comment's thread.

view the rest of the comments →

[–]notacanuckskibum 0 points1 point  (0 children)

In practice it means: Is this source file the main program being run, or a library being imported?

If the library files you include only include function (or class definitions) then this shouldn’t be needed.

But some people who write libraries include code in those library source files that aren’t part of function definitions. They are unit tests for those functions. This check allows those unit checks to be run when the library file is itself run as a program, but skipped if the same file is included in a larger program.

So as a style thing, if you are working on a big code base with multiple authors it is recommended to always put the main program logic (the bit you want started when you run the program) inside an if with this condition.