November 09, 2014 Re: How to let D's one module contains lots of classes. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to tcak | On Sunday, 9 November 2014 at 12:21:28 UTC, tcak wrote:
> On Sunday, 9 November 2014 at 11:30:22 UTC, AlanThinker wrote:
>> Yes, you are right.
>> Package can do it.
>> Thanks all of you!
>
> Yes, package can do it, thou this adds burden to maintain packages this time. Weirdness of this design is seen in druntime as well.
>
> core.sync.mutex.Mutex
>
> Doubling mutex word unnecessarily. Every time I will create a module, half an hour, I am thinking what name to give the module. Either will create many classes in one file, or use same name for both module and class that causes above example.
If we can create partial module, it will be easier to use. then no package needed.
such as:
################
// test/foo/gui/button.d
partial module foo.gui;
class Button
{
public this() {
import std.stdio : writeln;
writeln( "New Button!" );
}
}
// test/foo/gui/widget.d
partial module foo.gui;
class Widget {
public this() {
import std.stdio : writeln;
writeln( "New Widget!" );
}
}
// test/foo/namespace.d
module namespace;
import foo.gui;
void main()
{
auto w = new foo.gui.Widget;
auto b = new foo.gui.Button;
}
###############
| |||
November 09, 2014 Re: How to let D's one module contains lots of classes. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to AlanThinker | On Sunday, 9 November 2014 at 13:17:37 UTC, AlanThinker wrote:
> On Sunday, 9 November 2014 at 12:21:28 UTC, tcak wrote:
>
> If we can create partial module, it will be easier to use. then no package needed.
> such as:
>
> ################
> // test/foo/gui/button.d
> partial module foo.gui;
>
> class Button
> {
> public this() {
> import std.stdio : writeln;
> writeln( "New Button!" );
> }
> }
> // test/foo/gui/widget.d
> partial module foo.gui;
>
> class Widget {
> public this() {
> import std.stdio : writeln;
> writeln( "New Widget!" );
> }
> }
>
> // test/foo/namespace.d
> module namespace;
>
> import foo.gui;
>
> void main()
> {
> auto w = new foo.gui.Widget;
> auto b = new foo.gui.Button;
> }
>
> ###############
That's good, but there is no need to add a new keyword as "partial" for module I think. If compiler would just merge same modules together automatically, that would do it.
| |||
November 09, 2014 Re: How to let D's one module contains lots of classes. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to tcak | On Sunday, 9 November 2014 at 15:40:53 UTC, tcak wrote:
> On Sunday, 9 November 2014 at 13:17:37 UTC, AlanThinker wrote:
>
> That's good, but there is no need to add a new keyword as "partial" for module I think. If compiler would just merge same modules together automatically, that would do it.
Maybe this thing could open up some security issues, but if merging would be restricted to files in same folder, this would completely (99% of time) prevent problems.
* Security Issue: Same module name from a 3rd party library, etc.
| |||
November 09, 2014 Re: How to let D's one module contains lots of classes. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to tcak Attachments: | On Sun, 09 Nov 2014 15:40:51 +0000
tcak via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> That's good, but there is no need to add a new keyword as "partial" for module I think.
and even compiler changes are unnecessary. `import()`, it rocks.
| |||
November 09, 2014 Re: How to let D's one module contains lots of classes. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Sunday, 9 November 2014 at 15:54:45 UTC, ketmar via Digitalmars-d wrote:
> On Sun, 09 Nov 2014 15:40:51 +0000
> tcak via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
>
>> That's good, but there is no need to add a new keyword as "partial" for module I think.
> and even compiler changes are unnecessary. `import()`, it rocks.
Hmm. `import()` requires filename, and -I flag. Convenience (partial module thing) is turning into `assembly can do everything, no need for high level language` then.
| |||
November 09, 2014 Re: How to let D's one module contains lots of classes. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to tcak Attachments: | On Sun, 09 Nov 2014 16:05:31 +0000
tcak via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> On Sunday, 9 November 2014 at 15:54:45 UTC, ketmar via Digitalmars-d wrote:
> > On Sun, 09 Nov 2014 15:40:51 +0000
> > tcak via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> >
> >> That's good, but there is no need to add a new keyword as "partial" for module I think.
> > and even compiler changes are unnecessary. `import()`, it rocks.
>
> Hmm. `import()` requires filename, and -I flag. Convenience (partial module thing) is turning into `assembly can do everything, no need for high level language` then.
building reasonably complex software without build system is... strange. so let build system care about that.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply