My first D program

Shriramana Sharma samjnaa at gmail.com
Thu May 30 04:13:19 PDT 2013


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:

#! /usr/bin/rdmd
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?

-- 
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा


More information about the Digitalmars-d-learn mailing list