TimK:

> I have a little (private) project in C++ and was thinking that I should give D
> a chance (especially since it's not exactly new).

Welcome, and I suggest you to use D V.1 language still, because it's simpler to 
learn and its compilers have less bugs. The latest LDC and DMD are OK, I prefer 
LDC on Ubuntu and DMD on Windows, plus something to automate building (because 
the D1 compiler is not able to find modules by itself as Java does). Eventually 
D2 will be debugged and refined enough to be used by novices too. Hopefully it 
will not take too much time. You can of course play with D2 too (DMD only), but 
you can find some bugs.


> So I have a class TPerson where the declaration is in the header file and the
> definition in the cpp-source file. Naturally a defined function looks
> something like this:
> 
> void TCharacter::DoSomething(int x){...}
> 
> I do this for several reasons:
> - The class would get really awkward to read through and understand, with all
> the code in it - so I usually just put the declaration and the documentation
> for public functions into it.
> - a programmer who just wants to understand the class doesn't care about the
> implementation.
> 
> Now I tried to make a class in D, too, following this style.
> Unfortunately that doesn't work and I couldn't find a working alternative in
> the documentation.
> 
> Is this not possible in D?

Steven Schveighoffer has already told you most things. Generally when you 
change language it's better to use its specific idioms even if you don't 
like/understand them, because a well designed language is an organic thing, its 
parts are designed to be fit to each other. So what's bad and good is often 
language-specific.

I've read people call D a Java++, or to define it a tidy C++, but in practice 
there are several differences between D and C++, for example the garbage 
collector changes many things.

In D classes/structs have their methods written inside. The indentation helps 
the programmer see the grouping. In a module you can add related classes, if 
they aren't too much long.

Bye,
bearophile

Reply via email to