Which D features to emphasize for academic review article
Walter Bright
newshound2 at digitalmars.com
Tue Aug 14 14:12:38 PDT 2012
On 8/14/2012 3:31 AM, Mehrdad wrote:
> Then you get the best of both worlds:
>
> 1. You force the programmer to manually initialize the variable in most cases,
> forcing him to think about the default value. It's almost no trouble for
>
> 2. In the cases where it's not possible, the language helps the programmer catch
> bugs.
>
>
> Why the heck D avoids #1, I have no idea.
As I've explained before, user defined types have "default constructors". If
builtin types do not, then you've got a barrier to writing generic code.
Default initialization also applies to static arrays, tuples, structs and
dynamic allocation. It seems a large inconsistency to complain about them only
for local variables of basic types, and not for any aggregate type or user
defined type.
> It's one of the _major_ features of C# and Java that help promote correctness,
> and #1 looks orthogonal to #2 to me.
I know Java doesn't have default construction - does C#?
As for the 'rarity' of the error I mentioned, yes, it is unusual. The trouble is
when it creeps unexpectedly into otherwise working code that has been working
for a long time.
More information about the Digitalmars-d
mailing list