www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Best practice and module declarations

reply Jonathan M Davis <jmdavisprog gmail.com> writes:
I was wondering what the general consesus was (if there is one) on whether it's 
valuable to always put module declarations in each module.

Obviously, if you need the module to have a name other than the file name, then 
you need to have the module declaration. However, is it necessarily desirable
to 
have it when the module name matches the file name? Or would there even be a 
reason for it to be desirable _not_ to have the module declaration?

I can't think of any particularly strong reasons to have it or not to have it. 
My first reaction is to just always use it, but thinking about it, I'm not sure 
that there's really much point if the file name and the module name already 
match. Does anyone have reasons why it would matter other than personal 
preference?

- Jonathan M Davis
Jul 14 2010
next sibling parent torhu <no spam.invalid> writes:
On 15.07.2010 00:22, Jonathan M Davis wrote:
 I was wondering what the general consesus was (if there is one) on whether it's
 valuable to always put module declarations in each module.

 Obviously, if you need the module to have a name other than the file name, then
 you need to have the module declaration. However, is it necessarily desirable
to
 have it when the module name matches the file name? Or would there even be a
 reason for it to be desirable _not_ to have the module declaration?

 I can't think of any particularly strong reasons to have it or not to have it.
 My first reaction is to just always use it, but thinking about it, I'm not sure
 that there's really much point if the file name and the module name already
 match. Does anyone have reasons why it would matter other than personal
 preference?

Some of the D build tools complain if you don't use module declarations. And IIRC, modules in subdirectories (packages) need to have them. So I end up adding them for anything but single-file test programs.
Jul 14 2010
prev sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--001485f7d244635000048b6873e6
Content-Type: text/plain; charset=ISO-8859-1

I was wondering what the general consesus was (if there is one) on whether
 it's
 valuable to always put module declarations in each module.


 I can't think of any particularly strong reasons to have it or not to have
 it.
 My first reaction is to just always use it, but thinking about it, I'm not
 sure
 that there's really much point if the file name and the module name
 already
 match. Does anyone have reasons why it would matter other than personal
 preference?


- you can put documentation comments before the module declaration, to have them at the beginning of the docs. That's where you put general indications on the use of this module, and copyright/author/license indications. I quite like these module-level docs, personally. - it defines a new symbol, which you can use in template with alias parameters and __traits, like in __traits(allMembers, moduleName). If you're into compile-time introspection, that can be useful. (though maybe these symobols exist even without module decls, I don't know). Philippe --001485f7d244635000048b6873e6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style= =3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); p= adding-left: 1ex;"><div><div class=3D"h5"><blockquote class=3D"gmail_quote"= style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 2= 04); padding-left: 1ex;"> I was wondering what the general consesus was (if there is one) on whether = it&#39;s<br> valuable to always put module declarations in each module.<br> </blockquote></div></div></blockquote><div>=A0</div><blockquote class=3D"gm= ail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(2= 04, 204, 204); padding-left: 1ex;"><div><div class=3D"h5"><blockquote class= =3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid= rgb(204, 204, 204); padding-left: 1ex;"> I can&#39;t think of any particularly strong reasons to have it or not to h= ave it.<br> My first reaction is to just always use it, but thinking about it, I&#39;m = not sure<br> that there&#39;s really much point if the file name and the module name alr= eady<br> match. Does anyone have reasons why it would matter other than personal<br> preference?<br> </blockquote><br></div></div></blockquote><div><br>I can see two reasons to= use module declarations:<br><br>- you can put documentation comments befor= e the module declaration, to have them at the beginning of the docs. That&#= 39;s where you put general indications on the use of this module, and copyr= ight/author/license indications. I quite like these module-level docs, pers= onally. <br> <br>- it defines a new symbol, which you can use in template with alias par= ameters and __traits, like in __traits(allMembers, moduleName). If you&#39;= re into compile-time introspection, that can be useful.<br>(though maybe th= ese symobols exist even without module decls, I don&#39;t know).<br> <br><br>Philippe<br><br></div></div> --001485f7d244635000048b6873e6--
Jul 15 2010