More than one main

bearophile bearophileHUGS at lycos.com
Thu Mar 24 11:47:36 PDT 2011


Jonathan M Davis:

> But honestly, what you're trying to do just strikes me as plain weird. Maybe
> it's a typical thing to do in scripting languages, but it definitely isn't in
> compiled languages.

It's very common in well designed Python modules. Probably you don't see it in compiled languages like C/C++ because they don't have a good module system. D has modules related to Python ones, so I am using this Python idiom in D too. Most D1 modules of dlibs1 have demo code :-)

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

Walter:

> That's what the version statement is for:
> 
> version (My_Demo)
> {
>      void main()
>      {
>          ...
>      }
> }
> 
> There's no reason to add more features to duplicate that.

I too have suggested to use the version() statement, but My_Demo is not a _standard_ version generated automatically by tools like rdmd. In a project you usually use many modules, and some of them have demo code in their main. If you use rdmd or similar tools, you want only one of those mains to be compiled, the right one.

Bye,
bearophile


More information about the Digitalmars-d mailing list