version(Main) like python's __name__ == "__main__"

Chris Miller chris at dprogramming.com
Wed Nov 21 03:43:08 PST 2007


On Wed, 21 Nov 2007 06:38:21 -0500, Lionello Lunesu  
<lio at lunesu.remove.com> wrote:

> I'd like to suggest a new predefined version identifier called "Main"  
> which is defined on the main module only. The definition of "main  
> module" would be:
>
> * the first module on the command line, or
> * the module whose name will be used for the executable, or
> * the module mentioned after DMD's "-run"
>
> The two issues with this suggestion are:
>
> * vagueness of the definition of "main module"
> * Main version identifier is set for one module only (by definition)
>
> It's use would be similar to Python's "__main__" [1]:
>
> version(Main)
> {
> void main()
> {
>    // test code
> }
> }
>
> It would allow one to write small examples/tests in each module, that  
> can be executed immediately, but won't cause conflicts when linked  
> against in a larger project.
>
> L.
>
> [1] http://docs.python.org/lib/module-main.html


That's pretty cool, I'll vote for it.



More information about the Digitalmars-d mailing list