D vs Java

Roberto Mariottini Roberto_member at pathlink.com
Mon Mar 20 01:50:19 PST 2006


In article <dvhohr$asa$1 at digitaldaemon.com>, Walter Bright says...
>
>I'm no expert on Java programming, but I get this question a lot: "What 
>compelling reason does D have that would entice a Java programmer to switch 
>to D?"

Very few, I think.
I've thought about it, and in the end I think Java has some good points that
can't  be beaten so esily:

- Compile once and run everywhere. I write, compile and test my program with my
Windows PC, then download it in a Linux-based CN, a VxWorks-based terminal and a
WinCE one (last two with an ARM processor). The application works the same on
the 4 platform, the user doesn't notice. You only have to care for a few things,
like case sensitiveness for file names, or not using the latest whistles & bells
not present in that particularily old VM.

- Swing. Once you get used to it, you think you can't work without it. It's
extremely flexible, making possible to write a 5-lines GUI for a quick hack, or
a big application with custom appearence. And it can scale down to little
targets, as a StrongArm 133MHz with 32 MB of RAM, with some effort.

- The library. You can make almost everything with the base standard library.
It's big, but it works. Here in Italy we say: "non capita, ma se capita..." ("it
won't happen, but if it happens..."), so from a programmer's point of view, more
is better.

Java is slower, but who cares? My customers don't know I use Java, they don't
notice the 30 ms delay in menu showing. CPU intensive parts are JIT compiled, so
the overall overhead of the VM results in an impercettible delay in GUI
responsiveness. My GUIs are still faster than their users.

Something that D can do and Java don't is system programming. Pointers,
assembler, the full C api, and so on are something the system programmer would
keep handy.
What D has, that Java don't, is a better language. More complex, but more
powerful. Something I miss in Java:

- the version{} construct
- properties
- switch-case with strings
- RAII
- array slices
- the 'ditto' keyword in javadoc
- true typedefs (if only they worked in D...)
- I think in the long period I will use contracts
- maybe I'll use opApply() with foreach

D templates are better than Java generics (and than C++ templates), but I don't
write Java generics everyday (nor C++ templates), I mostly use them. Their use
is similar, so I don't think it will add something to D.

Ciao

---
http://www.mariottini.net/roberto/



More information about the Digitalmars-d mailing list