www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Code spliting in module and packages

reply "Matthieu" <matthieukern gmail.com> writes:
Hi!

I can't find any good tutorial about how to split my source code
in modules and packages. I don't want to use a Java splitting
style (one class per file) or something like that, I want to use
the D way, but it's so hard to find it! Can someone explain to me
how to do it well, please?

In the same time, is there someone who knows where to find a good
style guide for D, something like the PEP for python?

Thx.
Matthieu
Jul 20 2014
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Matthieu:

Can someone explain to me how to do it well, please?
Put related stuff in a module, and unrelated stuff in other modules. If the module grows too much, split it up in two or more. It's about the same as in Python. Just remember that classes can see each other private members only if they are in the same module. So if you move things to another module, sometimes some stuff (like unittests) breaks.
 In the same time, is there someone who knows where to find a 
 good style guide for D, something like the PEP for python?
A starting point: http://dlang.org/dstyle.html Bye, bearophile
Jul 20 2014
prev sibling next sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 7/21/2014 7:13 AM, Matthieu wrote:
 Hi!

 I can't find any good tutorial about how to split my source code
 in modules and packages. I don't want to use a Java splitting
 style (one class per file) or something like that, I want to use
 the D way, but it's so hard to find it! Can someone explain to me
 how to do it well, please?
I don't think there is a "D way." It's a matter of personal preference. I don't like to see huge modules, so I prefer to keep them small. But what is a reasonable level of separation for me may not be the same for you. Just go with what feels natural to you. --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
Jul 20 2014
parent reply "Matthieu" <matthieukern gmail.com> writes:
Hi,

Thanks for your answers. I'll continue to code as I ussed to do,
and try to improve my style to have a better usage of the modules
(today i'm most one class per file, so I don't use the modules at
all).

Bye,
Matthieu
Jul 21 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
Matthieu:

 Thanks for your answers. I'll continue to code as I ussed to do,
 and try to improve my style to have a better usage of the 
 modules
 (today i'm most one class per file, so I don't use the modules 
 at all).
Also, try to use less classes and more free (pure) functions :-) This means a little more functional style. Bye, bearophile
Jul 21 2014
prev sibling parent reply "Dicebot" <public dicebot.lv> writes:
Probably most idiomatic D way is to use files _instead_ of 
classes :)
It is a bit idealistic though and is not yet 100% feasible in 
practice.
Jul 21 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Dicebot:

 Probably most idiomatic D way is to use files _instead_ of 
 classes :)
 It is a bit idealistic though and is not yet 100% feasible in 
 practice.
What's stopping it from being feasible? Bye, bearophile
Jul 21 2014
parent "Dicebot" <public dicebot.lv> writes:
On Monday, 21 July 2014 at 18:02:33 UTC, bearophile wrote:
 Dicebot:

 Probably most idiomatic D way is to use files _instead_ of 
 classes :)
 It is a bit idealistic though and is not yet 100% feasible in 
 practice.
What's stopping it from being feasible? Bye, bearophile
Stuff like this : http://forum.dlang.org/post/mailman.57.1405963972.32463.digitalmars-d puremagic.com Also infamous private name clash issue.
Jul 21 2014