December 21, 2011
On Tuesday, December 20, 2011 17:32:53 Andrei Alexandrescu wrote:
> On 12/20/11 2:58 PM, Marco Leise wrote:
> > Am 19.12.2011, 19:08 Uhr, schrieb Walter Bright
> > 
> > <newshound2@digitalmars.com>:
> >> On 12/16/2011 2:55 PM, Walter Bright wrote:
> >>> For example, in std.datetime there's "final class Clock". It
> >>> inherits
> >>> nothing,
> >>> and nothing can be derived from it. The comments for it say it is
> >>> merely a
> >>> namespace. It should be a struct.
> >> 
> >> Or perhaps it should be in its own module.
> > 
> > When I first saw it I thought "That's how _Java_ goes about free functions: Make it a class." :)
> 
> Same here. If I had my way I'd rethink the name of those functions. Having a cutesy prefix "Clock." is hardly justifiable.

It's not the only place in Phobos which uses a class as a namespace. I believe that both std.process and std.windows.registry are doing the same thing.

In this case, it nicely group all of the functions that are grabbing the time in one form or another. They're all effectively grabbing the time from the system clock, so they're grouped on Clock.

- Jonathan M Davis
December 21, 2011
On Wednesday, 21 December 2011 at 02:10:30 UTC, Jonathan M Davis wrote:
> On Tuesday, December 20, 2011 17:32:53 Andrei Alexandrescu wrote:
>> On 12/20/11 2:58 PM, Marco Leise wrote:
>> > Am 19.12.2011, 19:08 Uhr, schrieb Walter Bright
>> > 
>> > <newshound2@digitalmars.com>:
>> >> On 12/16/2011 2:55 PM, Walter Bright wrote:
>> >>> For example, in std.datetime there's "final class Clock". It
>> >>> inherits
>> >>> nothing,
>> >>> and nothing can be derived from it. The comments for it say it is
>> >>> merely a
>> >>> namespace. It should be a struct.
>> >> 
>> >> Or perhaps it should be in its own module.
>> > 
>> > When I first saw it I thought "That's how _Java_ goes about free
>> > functions: Make it a class." :)
>> 
>> Same here. If I had my way I'd rethink the name of those functions.
>> Having a cutesy prefix "Clock." is hardly justifiable.
>
> It's not the only place in Phobos which uses a class as a namespace. I believe that both std.process and std.windows.registry are doing the same thing.
>
> In this case, it nicely group all of the functions that are grabbing the time in one form or another. They're all effectively grabbing the time from the system clock, so they're grouped on Clock.
>
> - Jonathan M Davis

Sounds like the perfect candidate for its own module.
December 21, 2011
On Wednesday, December 21, 2011 06:18:59 Jakob Ovrum wrote:
> On Wednesday, 21 December 2011 at 02:10:30 UTC, Jonathan M Davis
> > It's not the only place in Phobos which uses a class as a namespace. I believe that both std.process and std.windows.registry are doing the same thing.
> > 
> > In this case, it nicely group all of the functions that are grabbing the time in one form or another. They're all effectively grabbing the time from the system clock, so they're grouped on Clock.
> > 
> > - Jonathan M Davis
> 
> Sounds like the perfect candidate for its own module.

Not out of the question, I suppose, but it would make an awfully small module and would inevitably make it that much harder for people to figure out how to get the current time.

- Jonathan M Davis
December 21, 2011
On Tuesday, December 20, 2011 21:34:30 Jonathan M Davis wrote:
> On Wednesday, December 21, 2011 06:18:59 Jakob Ovrum wrote:
> > On Wednesday, 21 December 2011 at 02:10:30 UTC, Jonathan M Davis
> > 
> > > It's not the only place in Phobos which uses a class as a namespace. I believe that both std.process and std.windows.registry are doing the same thing.
> > > 
> > > In this case, it nicely group all of the functions that are grabbing the time in one form or another. They're all effectively grabbing the time from the system clock, so they're grouped on Clock.
> > > 
> > > - Jonathan M Davis
> > 
> > Sounds like the perfect candidate for its own module.
> 
> Not out of the question, I suppose, but it would make an awfully small module and would inevitably make it that much harder for people to figure out how to get the current time.

Not to mention, I quite like the effect that you get with it as a class, since it's explicit that it's coming from the clock, whereas if it were a module, that wouldn't be the case. You get the same effect with std.process' Environment. When you're calling functions on it, it's explicit that you're getting information from and affecting the environment. In a way, it's like a singleton, but there's nothing to instantiate.

- Jonathan M Davis
December 21, 2011
On 12/20/2011 5:52 PM, Marco Leise wrote:
> Ok, I jumped on the band wagon to early. Personally I only had this problem with
> classes and structs.
>
> struct Test {
> byte arr[1024 * 1024 *10];
> }
>
> and
>
> class Test {
> byte arr[1024 * 1024 *10];
> }
>
> both create a 10MB executable. While for the class, init may contain more data
> than just that one field, I don't see the struct adding anything or going into
> TLS. Can these initializers also go into .bss?

The struct one already does. Compile it, obj2asm it, and you'll see it there.
December 21, 2011
21.12.2011 0:22, Walter Bright пишет:
> First off, dmd most definitely puts 0 initialized static data into the
> BSS segment. So what's going on here?
>
> 1. char data is not initialized to 0, it is initialized to 0xFF.
> Non-zero data cannot be put in BSS.
Sorry, it was because of copying C code in my post. ubyte array was tested in D.
>
> 2. Static data goes, by default, into thread local storage. BSS data is
> not thread local. To put it in global data, it has to be declared with
> __gshared.
I completely forgot about TLS.
>
> So,
>
> __gshared byte arr[1024 * 1024 *10];
>
> will go into BSS.
>
> There is pretty much no reason to have such huge arrays in static data.
> Instead, dynamically allocate them.
Of course, it was just an example of a huge executable.


Now I see that dmd uses BSS , thank you for the explanation!

I still think that zero-filled TLS arrays can occupy no size in the executable, but it should be done with compiler and D run-time system support and surely it is not worth the time it will take to implement.

I apologize for the unfair accusation.
December 21, 2011
On Wed, 21 Dec 2011 07:34:30 +0200, Jonathan M Davis <jmdavisProg@gmx.com> wrote:

> On Wednesday, December 21, 2011 06:18:59 Jakob Ovrum wrote:
>> On Wednesday, 21 December 2011 at 02:10:30 UTC, Jonathan M Davis
>> > It's not the only place in Phobos which uses a class as a
>> > namespace. I believe that both std.process and
>> > std.windows.registry are doing the same thing.
>> >
>> > In this case, it nicely group all of the functions that are
>> > grabbing the time in one form or another. They're all
>> > effectively grabbing the time from the system clock, so they're
>> > grouped on Clock.
>> >
>> > - Jonathan M Davis
>>
>> Sounds like the perfect candidate for its own module.
>
> Not out of the question, I suppose, but it would make an awfully small module
> and would inevitably make it that much harder for people to figure out how to
> get the current time.
>
> - Jonathan M Davis

Supporting module nesting in single file wouldn't hurt, would it?

module main;
module nested
{
}
December 21, 2011
On 21. 12. 2011 14:22, so wrote:
> Supporting module nesting in single file wouldn't hurt, would it?
>
> module main;
> module nested
> {
> }

Kind of...

template MyNamespaceImpl ()
{
    int i;
}

alias MyNamespaceImpl!() MyNamespace;

void main ()
{
    MyNamespace.i = 1;

    with (MyNamespace)
    {
        i = 2;
    }

    writeln(MyNamespace.i);
    readln();
}
December 27, 2011
Am 21.12.2011, 07:11 Uhr, schrieb Walter Bright <newshound2@digitalmars.com>:

> On 12/20/2011 5:52 PM, Marco Leise wrote:
>> Ok, I jumped on the band wagon to early. Personally I only had this problem with
>> classes and structs.
>>
>> struct Test {
>> byte arr[1024 * 1024 *10];
>> }
>>
>> and
>>
>> class Test {
>> byte arr[1024 * 1024 *10];
>> }
>>
>> both create a 10MB executable. While for the class, init may contain more data
>> than just that one field, I don't see the struct adding anything or going into
>> TLS. Can these initializers also go into .bss?
>
> The struct one already does. Compile it, obj2asm it, and you'll see it there.

Ah, I see it now. Sorry for the noise!
January 18, 2012
Am 27.12.2011, 03:42 Uhr, schrieb Marco Leise <Marco.Leise@gmx.de>:

> Am 21.12.2011, 07:11 Uhr, schrieb Walter Bright <newshound2@digitalmars.com>:
>
>> On 12/20/2011 5:52 PM, Marco Leise wrote:
>>> Ok, I jumped on the band wagon to early. Personally I only had this problem with
>>> classes and structs.
>>>
>>> struct Test {
>>> byte arr[1024 * 1024 *10];
>>> }
>>>
>>> and
>>>
>>> class Test {
>>> byte arr[1024 * 1024 *10];
>>> }
>>>
>>> both create a 10MB executable. While for the class, init may contain more data
>>> than just that one field, I don't see the struct adding anything or going into
>>> TLS. Can these initializers also go into .bss?
>>
>> The struct one already does. Compile it, obj2asm it, and you'll see it there.
>
> Ah, I see it now. Sorry for the noise!

It is back again! The following struct in my main module increases the executable size by 10MB with DMD 2.075:

struct Test {
	byte abcd[10 * 1024 * 1024];
}

It seems not to do so with *both* of these declarations, that create static arrays in the module:

byte abcd[10 * 1024 * 1024];
__gshared byte abcd[10 * 1024 * 1024];