November 28, 2011
On Mon, 28 Nov 2011 21:12:32 +0200, Kagamin <spam@here.lot> wrote:

> In Java separation is done with interfaces. I think it is right.

For Java, yes.
November 28, 2011
On 11/28/2011 3:41 AM, Alexey Veselovsky wrote:
> ok. What about:
>
> struct Foo {
>      int a;
>      int b;
>      // 100 more fields
>      ...
>      void foo();
> }
>
> Did I must write in implementation all this 100+ fields in implementation?

Yes. (Unless you decide to use the PIMPL idiom.)
November 28, 2011
On 11/28/2011 4:00 AM, Alexey Veselovsky wrote:
> ok. I just removed from test.di all non public entities.
>
> // D import file generated from 'test.d'
> module test;
> public
> {
>      void foo();
>
>      struct Boo
>      {
>          public
>          {
>              void boo();
>          }
>      }
> }
>
> Now, let's build it:
> $ dmd test.di test.d main.d
> test.d: Error: module test from file test.d conflicts with another
> module test from file test.di
>
> di file not specification, but just another version of implementation?

You cannot compile with both the di and d file.


> Compiler doesn't know anything about "specification" files. So, he
> did't check specification&implementation conformance.

Yes, that's correct.
November 28, 2011
so Wrote:

> On Mon, 28 Nov 2011 21:12:32 +0200, Kagamin <spam@here.lot> wrote:
> 
> > In Java separation is done with interfaces. I think it is right.
> 
> For Java, yes.

Java, D or C++, classes and structs are not a separation. Want a real separation? See COM: it doesn't even have notion of a field.
November 28, 2011
Walter:

> On 11/28/2011 4:00 AM, Alexey Veselovsky wrote:
> > Compiler doesn't know anything about "specification" files. So, he did't check specification&implementation conformance.
> 
> Yes, that's correct.

And this is positive because?

See also Timon answer: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=150164

Bye,
bearophile
November 28, 2011
bearophile Wrote:

> And this is positive because?

You say it as if it's negative.
November 29, 2011
On 11/28/2011 12:37 PM, Kagamin wrote:
> so Wrote:
> 
>> http://cpp-next.com/archive/2011/11/having-it-all-pythy-syntax/
> 
> o.O
> 
> overload a lambda?

....And now I see what all the hype is about with D's template system.
Good lord.  I've never really looked at C++ templates before.
0.0
November 29, 2011
Am 28.11.2011, 14:42 Uhr, schrieb Maxim Fomin <maxim@maxim-fomin.ru>:

> 2011/11/28 Marco Leise <Marco.Leise@gmx.de>:
>> Am 28.11.2011, 11:02 Uhr, schrieb Jude <10equals2@gmail.com>:
>>
>>>> I tried to write a lib and a project, which used that lib
>>>> separately, but came to conclusion that the best choice it to pull
>>>> lib code to project one. And it is not a biggest problem, because
>>>> dmd produces 700 kb executable for hello word program.
>>>
>>> what..?
>>>
>>> I don't know how you are managing to get 700kb for hello world...
>>> mine clocks in a 283.7kb with dmd with no optmizations, and holy crap
>>> 1.6MB for same file with gdmd.
>>>
>>> WTF is going on there I wonder...?
>>
>> *drum roll*
>>
>> 148,2 kB (dmd 2.054, Linux)
>>
>> *tadaa*
>>
>> - 8< - - - - - - - - - - - - - - - - - - -
>> import std.stdio;
>>
>> void main() {
>>        writeln("Hello, world!");
>> }
>> - 8< - - - - - - - - - - - - - - - - - - -
>>
>
> ------
> import std.stdio;
>
> class dummy
> {
> 	this() { writeln("ctor");}
> 	~this() { writeln("dtor"); }
> }
>
> void main()
> {
> 	auto dm = new dummy();
> }
> -------
>
> dmd main.d -o
> 377,9 kb
> It is not 700 as i told, but yesterday i upgraded to 2.056. But
> definitely i saw that it produces 700 kb elf for a small program.
> Anyway, is 400 kb for dummy program too much?

Be aware that classes and structs have .init blocks that can grow huge if you declare large static arrays in them. So the source code may be small, but the executable bloats. And every template instantiation adds to it as well. I think even just using writeln with different parameters all over the place adds up, but thats a vague guess.
November 29, 2011
Kagamin Wrote:

> bearophile Wrote:
> 
> > And this is positive because?
> 
> You say it as if it's negative.


For me it is negative as what I understood from this discussion is that contrary to what is described in TDPL, D modules are not ready to prime time.

At least at the level Modula-2(3), Ada, Delphi, .Net, among others, offer modules.
November 29, 2011
On 29/11/11 2:12 AM, Marco Leise wrote:
> Am 28.11.2011, 14:42 Uhr, schrieb Maxim Fomin <maxim@maxim-fomin.ru>:
>
>> 2011/11/28 Marco Leise <Marco.Leise@gmx.de>:
>>> Am 28.11.2011, 11:02 Uhr, schrieb Jude <10equals2@gmail.com>:
>>>
>>>>> I tried to write a lib and a project, which used that lib
>>>>> separately, but came to conclusion that the best choice it to pull
>>>>> lib code to project one. And it is not a biggest problem, because
>>>>> dmd produces 700 kb executable for hello word program.
>>>>
>>>> what..?
>>>>
>>>> I don't know how you are managing to get 700kb for hello world...
>>>> mine clocks in a 283.7kb with dmd with no optmizations, and holy crap
>>>> 1.6MB for same file with gdmd.
>>>>
>>>> WTF is going on there I wonder...?
>>>
>>> *drum roll*
>>>
>>> 148,2 kB (dmd 2.054, Linux)
>>>
>>> *tadaa*
>>>
>>> - 8< - - - - - - - - - - - - - - - - - - -
>>> import std.stdio;
>>>
>>> void main() {
>>> writeln("Hello, world!");
>>> }
>>> - 8< - - - - - - - - - - - - - - - - - - -
>>>
>>
>> ------
>> import std.stdio;
>>
>> class dummy
>> {
>> this() { writeln("ctor");}
>> ~this() { writeln("dtor"); }
>> }
>>
>> void main()
>> {
>> auto dm = new dummy();
>> }
>> -------
>>
>> dmd main.d -o
>> 377,9 kb
>> It is not 700 as i told, but yesterday i upgraded to 2.056. But
>> definitely i saw that it produces 700 kb elf for a small program.
>> Anyway, is 400 kb for dummy program too much?
>
> Be aware that classes and structs have .init blocks that can grow huge
> if you declare large static arrays in them. So the source code may be
> small, but the executable bloats. And every template instantiation adds
> to it as well. I think even just using writeln with different parameters
> all over the place adds up, but thats a vague guess.

A couple of other things I noticed that can massively bloat your code using DMD:

Range case statements:

switch(c)
{
    case 0: .. case 255:
        foo();
        break;
}

Expands to

if(c == 0) goto L1;
if(c == 1) goto L1;
if(c == 2) goto L1;
...
if(c == 255) goto L1;
etc.

Which means you also get a horrible O(n) algorithm for something that should be a couple of compares. Why DMD does this is beyond me. There's a few function in Phobos that are massively bloated due to this (I've filed a bug report before anyone asks).

----

Global float arrays can bloat executables as well:

__gshared int[1_000_000] thisGoesInBss; // barely adds anything
__gshared float[1_000_000] thisGoesInData; // adds 4MB to exec

float arrays are initialised to NaN in D (in C they init to 0.0f), so they can't go in the .bss section (unless you explicitly init to 0.0f).