Thread overview
Code spliting in module and packages
Jul 20, 2014
Matthieu
Jul 20, 2014
bearophile
Jul 21, 2014
Mike Parker
Jul 21, 2014
Matthieu
Jul 21, 2014
bearophile
Jul 21, 2014
Dicebot
Jul 21, 2014
bearophile
Jul 21, 2014
Dicebot
July 20, 2014
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
July 20, 2014
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
July 21, 2014
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

July 21, 2014
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
July 21, 2014
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
July 21, 2014
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.
July 21, 2014
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
July 21, 2014
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.