VALUABLE INFO (Was: Re: First D project - some observations)

Georg Wrede georg.wrede at nospam.org
Mon Feb 20 19:58:26 PST 2006


There's nothing as valuable as these first-time experiences with D!!!

We in this newsgroup are just too familiar with all dos don'ts of D, to
ever imagine what it looks like to new people.

Now that we (as always?) are approaching 1.0, stuff like this should be
examined with a _microscope_ to find all the things that put off new users.

For everyone that bothers to write here there has to be a thousand who
get the same feelings, and who broadcast them around in the office, and
over beer.


Mike wrote:
> Hi!
> 
> I wanted to share some observations of an experienced C++ programmer
> who has now spent his first 10-12 hours with D.
> 
> First a little history on my project: I'm currently building a small
> vm (nothing fancy) for a little hobby project I'm doing. The vm is
> already running in C++, I just need to build a little, C-ish script
> parser around that thing.
> 
> Anyway, I have a little declaration problem in C++. It's not the
> first time I have exactly this problem, and I solved it numerous
> times, but I'm getting tired of it, and more frustrated every time I
> have something like this.
> 
> class Block;
> 
> class Instruction { .. Block *MyScope; };
> 
> class Block : public Instruction { .. List<Instruction>
> MyInstructions; List<Symbol> MyLocalSymbols; Block *MyParent; };
> 
> Instruction needs to call Block to get it's symbols, Block has it's
> local symbols and gets undefined symbols from it's parent. If parent
> is NULL, this is the global block. Symbols can be variables or
> (nested) functions. That's the idea.
> 
> But Instruction can't call Block's member functions, because Block is
> just a forward declaration at that point. I'm so sick of those *#&$!#
> forward declarations. I stopped coding at that point, since I was
> frustrated, seeing myself AGAIN wasting hours with moving code
> around, inside and outside the class declaration to get that thing to
> compile. Ok, I could create a "symboltable" class and derive "block"
> from both "instruction" and "symboltable". But why? Why another class
> if it's just needed in one place anyhow? And: No wonder C++ needs 
> multiple inheritance!
> 
> So I decided to finally try out D. Downloaded latest versions of
> akIDE and DMD, and after about 30-45 minutes converting my ~500 lines
> C++ code to ~350 lines D code it ran exactly like before! Nice, I
> thought. So I've worked on that project yesterday and today and it
> went really well, so I feel the urge now to summarize my impressions
> so far:
> 
> On the plus side:
> 
> + No forward declarations/No header files
> 
> I think that's the singlemost important thing to me about D. I hate
> those forward declarations, really. I hate them more than header
> files, which I hate a great deal, after numerous hours of playing
> solitaire while recompiling, because I had to add a new member to a
> base class.
> 
> (And no more #incldue typos! :-)
> 
> + Case "string", == for strings
> 
> In that particular case of writing a parser this is a godsend, but I
> imagine this will come in handy in other areas as well. No more
> !strcmp.
> 
> + The ~ operator
> 
> Never again this:
> 
> char buf[200]; sprintf(buf, "Error in blabla function (dbg: x = %i)",
> x); throw new exception(buf);
> 
> Nice!
> 
> + No ; after class definition
> 
> This feels just natural.
> 
> + this/super
> 
> Great! Never again this: Long, descriptive class name with one hard
> to see typo, copy paste for three constructors and one descructor,
> compile, find out you made a typo. And makes it easier to change a
> class name, too.
> 
> And I found this to be quite natural from the start, I never
> accidentally wrote a constructor the C++ way.
> 
> + member initialization with =, rather than with initializer lists
> 
> Another great thing, especially for me. I can't remember how many
> times I actually tried to initialize members via the D syntax, just
> to find out - d'oh, C++ can't do that. Forgot that again! Fits much
> better into the overall feel of a C-ish language than those
> initializer lists.
> 
> + Dynamic Arrays
> 
> Yes!
> 
> + Garbage Collection
> 
> Yes! Yes! Yes!
> 
> On the - side:
> 
> - Hard to find odd crashes
> 
> I had some trouble, until I figured out that my program seemed to
> crash/exit immediatly whenever an exception was not caught. Couldn't
> the compiler catch errors like that? That was really annoying. The
> problems was that I had no idea about where the crash happened and it
> took quite some time to find it.
> 
> Another thing was that on of my functions (defined as bit)
> accidentally had one path out of it without a return statement.
> Immediate crash when calling that function, again no error from the
> compiler. Every C++-compiler (iirc) catched things like that. These
> crashes are hard to find, really. Especially when you're not used to
> looking for something like THAT.
> 
> - .length property can't be lvalue
> 
> MyIntArray.length++;
> 
> Why not?
> 
> - class instantiation is a bit confusing, at least for c++
> programmers
> 
> I intuitively expect something like
> 
> HelloWorldClass writehello; writehello.doIt();
> 
> NOT to crash the program. But, well, that's something I can life with
> :-)
> 
> - no "bool"
> 
> Can't there be an "alias bool bit;" built in?
> 
> Summary: --------
> 
> I think I will start porting my C++ project over to D, since it's
> just a hobby project, so I have time to do that. And D is nearly the
> language that I wish C++ to be, honestly (add bool and it is :-). The
> crashes I mentioned make me wonder, since it wouldn't be too hard to
> find them at compile time, anyhow, maybe it's just me, I haven't
> found the time to play with the compiler settings.
> 
> The things I brought up aren't really acedemic, but I like to get
> dirty while programming, change my design constantly because I just
> had that other idea that I NEED to try out. For that D seems to be
> just the right language. Very practical, I like that. Add to that
> about 7-8 years of frustration with C++ header files, forward
> declarations, externs, pointers to pointers and stuff, and I just
> have to say: D puts the fun back in programming! Thanks!
> 
> So, wish you guys a nice day and be sure to watch BSG tonight :-)
> 
> -Mike
> 
> 



More information about the Digitalmars-d mailing list