C# interview

Denis Koroskin 2korden at gmail.com
Tue Oct 7 06:42:13 PDT 2008


On Tue, 07 Oct 2008 16:42:45 +0400, Bill Baxter <wbaxter at gmail.com> wrote:

> On Tue, Oct 7, 2008 at 9:39 PM, Adam D. Ruppe  
> <destructionator at gmail.com> wrote:
>> On Tue, Oct 07, 2008 at 02:21:23PM +0200, Don wrote:
>>> My point is simply that:
>>>
>>> Object o;
>>>
>>> is almost always an error, and I think that making it illegal would
>>> catch the #1 trivial bug in D code.
>>
>> I agree here. When I first started with D, I would write that almost
>> every time I was working with an object, and it would segfault without
>> fail.
>>
>> In C++, writing Object o; is quite common, and as a C++ user coming to  
>> D,
>> it took me a while to get away from that habit. I'm sure other C++ users
>> have had the same experience.
>>
>> This change definitely seems like a good idea. If it breaks existing  
>> code,
>> it is easy enough to add the = null if you need it, so there is little  
>> cost
>> and I think a decent gain.
>
> I think most of my bugs of this ilk come from aggregates:
>
> class Foo {
>     this() {
>         // oops forgot to init x here!
>     }
>
>     // lots of stuff
>     //...
>
> private:
>     Member x;
> }
>
> --bb

Yeah, compiler should catch these. You should mark your Member as nullable  
to explicitly say that you won't initialize it in ctor.



More information about the Digitalmars-d mailing list