D vs Java as a first programming language
Bartosz Milewski
bartosz at relisoft.com
Tue Sep 30 12:53:53 PDT 2008
If there was no D, I would argue for Java as the first language.
However, D has a well defined subset (called SafeD) which is almost
isomorphic to Java, except that it doesn't force OO on you (main is not
an object, writeln is not anybody's method, you don't have to box
integers, etc.).
When you introduce classes, you don't have to worry about
private/public. This comes later, when you teach modules (separate
source files). Even types are easier to teach because of some built-in
type inference (the keyword "auto"). So SafeD has a very gentle learning
curve.
D's standard library is quite adequate for teaching basic data
structures and algorithms. It's also very easy to write a programs that
list directories, read and write files, etc.
The only major problem with D is the lack of good programming/debugging
environment. There's nothing that explains the functioning of a program
better than single-stepping through it under a symbolic debugger.
--Bartosz
Nicolas Sicard wrote:
> Hi,
>
> I am new to D, and I think I have discovered a programming language
> close to my ideal one...
>
> On the web site, it is said: "Who D is Not For [...] As a first
> programming language - [...] Java is more suitable for beginners.".
> Is this based on experience?
>
> I am a teacher in a field where my students don't know what a
> programming language is! I need a language for a first approach of
> programming. I would say that Pascal, or BASIC even if a bit outdated,
> or even D would fit, but not Java.
>
> I can imagine my first lesson with Java:
>
> public class HelloWorld {
> public static void main(String[] args) {
> System.out.print("Hello world!");
> }
> }
>
In D it's simpler. Simpler even than in C (no need for \n):
import std.stdio;
void main()
{
writeln("Hello world!");
}
From which you can progress easily to:
writeln("The number is: ", 16);
Although, how this works is a bit of advance magic ;-)
> I would have to explain what a class is. What a method is. What a public
> or private visibility means. What a static method is. What the dots in
> "System.out.print" mean... :) Then how to compile it. Why you can't run
> it without a virtual machine. A virtual what?
>
> It seems the main argument why Java is a good first language is that it
> lacks complexity (namely C++ complexity). I think it also lacks
> simplicity for absolute beginners. D can be both simple and complex, and
> it shares other features with Java that could make it a language for
> beginners: object-oriented, no pointers necessary, garbage collection,
> strict type checking, portable...
>
> What feature would make D a worse choice than Java for a first language?
>
> Nicolas
More information about the Digitalmars-d
mailing list