www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - My first D program

reply Shriramana Sharma <samjnaa gmail.com> writes:
Hello. I am new to D and come from some intermediate C/C++ plus some
Python programming background. I currently have DMD 2.062 installed on
my Kubuntu Raring 64-bit system.

1. Too big binary output?

OK so I wrote my first Hello World program:


import std.stdio ;
void main() {
	writeln ( "Namaste Prapancha!" ) ;
}

(so I'm a bit of a Sanskrit geek...) and when I save it as namaste.d,
do chmod +x and run ./namaste.d, all is fine and I get the output.

However I am somewhat taken aback to see the file size -- 335KiB for a
simple Hello World? The equivalent C/C++ programs compiled with Clang
without any -O options produce binaries of less than 10K!

2. No filename freedom?

Next I wanted to go to another example but I like to keep my practice
files in order, so I rename namaste.d to 01-namaste.d but I get the
error:

$ dmd 01-namaste.d
01-namaste.d: Error: module 01-namaste has non-identifier characters
in filename, use module declaration instead

Huh? Now my program *name* has to be a valid identifier in the
language? So I can't have my filename contain a hyphen-minus or start
with a digit, and only something like e01_namaste.d is permitted. Why
is this?

--=20
Shriramana Sharma =E0=AE=B6=E0=AF=8D=E0=AE=B0=E0=AF=80=E0=AE=B0=E0=AE=AE=E0=
=AE=A3=E0=AE=B6=E0=AE=B0=E0=AF=8D=E0=AE=AE=E0=AE=BE =E0=A4=B6=E0=A5=8D=E0=
=A4=B0=E0=A5=80=E0=A4=B0=E0=A4=AE=E0=A4=A3=E0=A4=B6=E0=A4=B0=E0=A5=8D=E0=A4=
=AE=E0=A4=BE
May 30 2013
parent reply "Regan Heath" <regan netmail.co.nz> writes:
On Thu, 30 May 2013 12:13:19 +0100, Shriramana Sharma <samjnaa gmail.com>  
wrote:

 Hello. I am new to D and come from some intermediate C/C++ plus some
 Python programming background. I currently have DMD 2.062 installed on
 my Kubuntu Raring 64-bit system.

 1. Too big binary output?

 OK so I wrote my first Hello World program:


 import std.stdio ;
 void main() {
 	writeln ( "Namaste Prapancha!" ) ;
 }

 (so I'm a bit of a Sanskrit geek...) and when I save it as namaste.d,
 do chmod +x and run ./namaste.d, all is fine and I get the output.

 However I am somewhat taken aback to see the file size -- 335KiB for a
 simple Hello World? The equivalent C/C++ programs compiled with Clang
 without any -O options produce binaries of less than 10K!
The D standard library is currently statically linked. This will change shortly/eventually.
 2. No filename freedom?

 Next I wanted to go to another example but I like to keep my practice
 files in order, so I rename namaste.d to 01-namaste.d but I get the
 error:

 $ dmd 01-namaste.d
 01-namaste.d: Error: module 01-namaste has non-identifier characters
 in filename, use module declaration instead

 Huh? Now my program *name* has to be a valid identifier in the
 language? So I can't have my filename contain a hyphen-minus or start
 with a digit, and only something like e01_namaste.d is permitted. Why
 is this?
As the error says "use module declaration instead". You need to add a "module namaste;" statement to the top of the file 01-namaste.d. D defaults the module name to the filename, but you can specify it when they differ. R -- Using Opera's revolutionary email client: http://www.opera.com/mail/
May 30 2013
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Shriramana Sharma:

 However I am somewhat taken aback to see the file size -- 
 335KiB for a
 simple Hello World? The equivalent C/C++ programs compiled with 
 Clang
 without any -O options produce binaries of less than 10K!
On Windows32 DMD produces binaries for small programs that are often half the size of binaries generated by similar small C++ programs compiled with G++ (about 300+ against 700+). D has a garbage collector, runtime type introspection (module info, type info, etc), run-time built-in operations on dynamic arrays (concat, append), associative arrays and some of their operations, a sort (but probably the built-in sort and reverse will be deprecated and later removed), exceptions, and more. All that needs space that's absent in the C++ binary. ------------------- Regan Heath:
 The D standard library is currently statically linked.  This 
 will change shortly/eventually.
And then you will need the GC somewhere to run it :-) Both static and dynamic linking have their advantages and disadvantages. I think Go has a storng preference for static linking. Bye, bearophile
May 30 2013
prev sibling parent Shriramana Sharma <samjnaa gmail.com> writes:
Thanks to all those who kindly replied.

On Thu, May 30, 2013 at 9:57 PM, Regan Heath <regan netmail.co.nz> wrote:
 The D standard library is currently statically linked.  This will change
 shortly/eventually.
Ah OK -- should have thought of that. So whatever is in libc.so or libstdc++.so doesn't get counted to the size of the C/C++ executables. Likewise we should have a libd.so I suppose. I am all for having shared runtime/stdlib. --=20 Shriramana Sharma =E0=AE=B6=E0=AF=8D=E0=AE=B0=E0=AF=80=E0=AE=B0=E0=AE=AE=E0= =AE=A3=E0=AE=B6=E0=AE=B0=E0=AF=8D=E0=AE=AE=E0=AE=BE =E0=A4=B6=E0=A5=8D=E0= =A4=B0=E0=A5=80=E0=A4=B0=E0=A4=AE=E0=A4=A3=E0=A4=B6=E0=A4=B0=E0=A5=8D=E0=A4= =AE=E0=A4=BE
May 30 2013