How does D improve design practices over C++?

Christopher Wright dhasenan at gmail.com
Tue Nov 4 18:51:17 PST 2008


Denis Koroskin wrote:
> On Tue, 04 Nov 2008 07:13:24 +0300, Tony <tonytech08 at gmail.com> wrote:
> 
>> Let me be facetious with Janderson's list plz...
>>
>> "Janderson" <ask at me.com> wrote in message
>>> - More restrictive casting
>>
>> Ouch!! I prefer to slice bread with a knife rather than having a 
>> machine do it. (Bad analogy, but y'all get the point).
>>
> 
> No, I don't get your point. Do you mean that you don't use C++ casts 
> either (dynamic cast, int->float casts etc)? Why comment, then?

I think it's more to do with casts that the compiler wouldn't consider 
possible (like integer to a struct {int}) but the programmer knows is safe.

I would generally prefer to avoid casts for this. It's more future proof 
and safer:

struct Foo
{
	int value;
	static Foo opCall(int v)
	in
	{
		assert (v < 5_000_000); // db can't handle more than that
	body
	{
		...
	}
}

I grant that it's slower, but I really don't care about efficiency 
except in extreme cases (4MB executable for a simple example, for instance).



More information about the Digitalmars-d mailing list