Declare and Define Before Use? [rant]

Ali fakeemail at example.com
Wed Apr 4 19:19:30 UTC 2018


On Wednesday, 4 April 2018 at 18:57:27 UTC, kdevel wrote:
> Why are people writing
>
>    import std.stdio;
>
>    void main ()
>    {

>    }
>
>    struct S {

>    }
>
> but not
>
>    void main ()
>    {

>    }
>
>    struct S {

>    }
>
>    import std.stdio;
>
> ?


Personally i found it weird and inconsistent that
you can import and define anywhere at module scope
but for any other scope you have to define and import before use

I think the rules should have been the same everywhere
and if there was an exception to be made, it could be made for 
the main function
since the main function is special anyway

Personally I would either do
> import

> declare and define

> main

or
> main

> import

> declare and define

the later, is because main is special, so it is as if i am saying
this is what i want to do (main) and to do it (import) this stuff 
and (declare and define this stuff) ... putting main first would 
be just to highlight it and attract attention to it

importing and declaring anywhere at module scope is just too 
random for my taste




More information about the Digitalmars-d-learn mailing list