D vs Java as a first programming language

Sean Kelly sean at invisibleduck.org
Sun Sep 28 12:44:21 PDT 2008


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?

In my experience there is a prevailing belief that students have 
difficulty with low-level issues and so it's common to begin by teaching 
high-level programming and then go on to explain what's happening behind 
the scenes.  "The Art of Assembly Language," for example, teaches 
assembly via a higher-level meta-language for this reason, and the 
decision was made based on a great deal of experience teaching students 
assembly.

Personally however, I think this approach is a mistake.  Some students 
aren't willing to overlook the "magic" and focus on high-level logic at 
the outset.  Also, I think that it's important to teach good habits at 
the outset, because re-training later is much more difficult.  Teaching 
with Java, for example, may be convenient in that it obscures most of 
the irrelevant details that plague C++ programmers--pointer errors, 
etc--but at the same time the students aren't given the opportunity to 
develop an understanding of issues that will be crucial to their success 
later on.

> 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!");
>         }
>     }
> 
> 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?

The typical approach to this tends to be "just put this stuff in the 
file and ignore it--I'll explain it later.  I never understood why this 
is considered a good teaching method :-)

> 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...

This is why I think D is a perfect teaching language.  It's possible to 
get very low-level by using inline assembler and writing C-style code, 
or to use objects, delegates, etc, all in the same language.  If I were 
teaching imperative programming and didn't care about the lack of 
published teaching materials I'd use D.

> What feature would make D a worse choice than Java for a first language?

Shaky debugger / IDE support and a lack of published documentation.  I 
suppose I could plug "Learn to Tango with D" here, but its target 
audience is really someone who knows at least one other imperative 
language.  An alternative would be to start with Pascal, C, or C++, 
depending on your preference of syntax, safety, and complexity.

Alternately, you could begin with a language like Lisp, Scheme, Haskell, 
Erlang, etc.  I can't see this being terribly successful if your class 
is full of would-be web designers, but it's a definite option if you're 
targeting BS Comp Sci. or Comp Engineering students.  I think it's 
generally a good idea to get a functional language in early, because 
students seem to have a lot more trouble learning them if they've 
already spent a year or two doing strictly imperative programming.


Sean



More information about the Digitalmars-d mailing list