D vs Java as a first programming language

Alexander Panek alexander.panek at brainsware.org
Tue Sep 30 05:36:46 PDT 2008


The way I learned programming wasn’t quite perfect. We started with C++, 
writing C-like programs and went on to C# to write user interfaces by 
clicking around in Visual Studio. I’m just glad I found D pretty early, 
because it actually taught me programming.. or rather, I taught myself 
programming by exploring D. The D community and its open, positive 
attitude also had quite a big influence on me.

Thus, I think D would be a very good first language. Given that it 
sports a C-like syntax and includes so many paradigms, there’s lots of 
stuff to explore. Also, a “hello world” program is pretty easy to 
explain, as it only contains a very small set of constructs.

import tango.io.Stdout;

void main() {
	Stdout("Hello world!");
}

- import statement
- function declarations (main is a function after all)
- function calls
- string literals
- compilation :) (I’d just use rebuild to keep it easy for beginners)

Further, I would gradually add more things to this program, starting 
with function parameters!

import tango.io.Stdout;

void main(char[][] args) {
	Stdout.formatln("Hello, {}", args[1]);
}

- passing parameters to the program
- function parameters
- arrays
- passing parameters to functions

Next step would be to check args in some ways and explain flow controls 
that way, and so on.

You could well extend that to any paradigm you can find in D, given that 
you don’t skip anything that a paradigm builds on.

Best regards,
Alex



More information about the Digitalmars-d mailing list