D vs Java as a first programming language

dsimcha dsimcha at yahoo.com
Sun Sep 28 09:06:17 PDT 2008


== Quote from Nicolas Sicard (dransic at free.fr)'s article
> 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!");
>          }
>      }
> 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

I second the vote for Python.  I would avoid toy languages like BASIC, etc.  I
think that most people are more motivated to learn something that is directly
practical and might be directly useful outside the classroom.  Python is unique in
that it's intuitive enough for beginners, but has enough cool stuff (metaclasses,
list comprehension, etc.) that those who do end up programming after your class
will not outgrow it fast. Heck, even "real programmers", such as Eric Raymond, use
and praise it.  My only real knock against it is performance, but that's not even
a problem in most cases.

I certainly agree that Java is a terrible beginner language (and not a
particularly good language period) because it makes you jump through too many
hoops to do simple things (see your own hello world example), and yet doesn't have
very many advanced features, such as metaprogramming, advanced programmers to play
with.

However, D has its own problems as a beginner language.  First, although it
doesn't seem like it to someone coming from C/C++, it's a fairly close to the
metal language.  Although it's relatively easy to avoid, there is undefined
behavior.  Integers can overflow. Static typing, while necessary for high
performance and of debatable value in catching errors, isn't the most intuitive
thing in the world for a novice programmer.  Furthermore both of the common ways
to make a statically typed language more flexible (templates, polymorphism) are
probably too advanced for a first course.  Lastly, D is still fairly young, and
the occasional compiler bug or need to roll your own <insert data
structure/algorithm for which there is no decent library yet here> requires having
some programming experience under your belt to deal with.

Having helped a few friends who were struggling with very simple (to anyone who's
been programming for a while) assignments, it seems to me that most of the time,
programming teachers fail to explain the most basic stuff because it seems too
obvious to someone who's been programming for a while.  For example, I've known
several people to whom the whole concept of nesting just didn't make sense until I
backed up the truck and actually explained it explicitly.  Furthermore, if the
syntax is complex, such as in a C++ class I took in high school, I've seen
students spend so much time at first thinking about the syntax that they can't
think about higher level concepts. Therefore, I think a language with simple
syntax and not too much excess stuff that makes it hard to illustrate the basics
is the way to go.



More information about the Digitalmars-d mailing list