More than one main

bearophile bearophileHUGS at lycos.com
Thu Mar 24 09:50:27 PDT 2011


spir:

>Very annoying esp. during development since running unittests on a module, or set of modules, requires a main() func.<

This is not so bad, because rdmd has a --main switch.


>* the linker automatically adds an empty main() to the first module if needed<

The linker probably has zero knowledge of what a "first module" is.


>* allow empty main() in every module, more than one beeing just ignored<

I don't need just empty mains, I need demo code in them.

------------------------------

Jacob Carlborg:

> Doesn't rdmd have an option to add a main function?

Right, I have said it in my original post too.

------------------------------

Kagamin:

> unittests should be able to be a demo code for the module. Sometimes they say that unittests do demonstrate, how the module should work.<

For me the code inside unittests and the demo code inside the main (and the functions called just by the main) have different purposes. A demo may open a GUI, interact on the command line with the user, allow the module to be used stand alone with some kind of little interface, show graphs on the screen, etc. While unittests are mostly to test the module is working correctly and they are not supposed to be interactive or to be show graphs, etc. One my real example: in a module that plots functions on the screen, in the main I generate and show some function plots to the user. This is not done in unittests.

Bye,
bearophile


More information about the Digitalmars-d mailing list