www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - nullable done right, was #Spec

reply BLS <windevguy hotmail.de> writes:
The following code does not fail at compile-time or run-time because the 
if statement proves that the call is safe:
class Foo

     def bar(s as String?)
         if s  # same as "if s is not nil"
             print Utils.countChars(s, c'x')


Please note the question mark "?" on String? forces a compile time check.

--As a side note
The sample snippet is written Cobra (not Boo).. CLR NET.
Cobra's DBC is heavily influenced by D !

Bearophile could be interested; so here the link

http://cobra-language.com/docs/quality/
Bjoern
Nov 07 2010
parent Jimmy Cao <jcao219 gmail.com> writes:
--e0cb4e6ff1f5c4504d04947d0abf
Content-Type: text/plain; charset=ISO-8859-1

On Sun, Nov 7, 2010 at 2:53 PM, BLS <windevguy hotmail.de> wrote:

 The following code does not fail at compile-time or run-time because the if
 statement proves that the call is safe:
 class Foo

    def bar(s as String?)
        if s  # same as "if s is not nil"
            print Utils.countChars(s, c'x')


 Please note the question mark "?" on String? forces a compile time check.

 --As a side note
 The sample snippet is written Cobra (not Boo).. CLR NET.
 Cobra's DBC is heavily influenced by D !

 Bearophile could be interested; so here the link

 http://cobra-language.com/docs/quality/
 Bjoern

I've played with Cobra before, and I agree that Cobra does it very well. I hope that D allows non-nullable types so that those seg faults/access violations can be prevented/caught easily at compile-time. (for the sake of increasing the self-documenting ability of code, the safety of code, and even the quality code, as described in the link above) --e0cb4e6ff1f5c4504d04947d0abf Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div>On Sun, Nov 7, 2010 at 2:53 PM, BLS=A0<span dir=3D"ltr">&lt;<a href=3D= "mailto:windevguy hotmail.de">windevguy hotmail.de</a>&gt;</span>=A0wrote:<= br><blockquote class=3D"gmail_quote" style=3D"margin-top: 0px; margin-right= : 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; bord= er-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: = 1ex; "> The following code does not fail at compile-time or run-time because the if= statement proves that the call is safe:<br>class Foo<br><br>=A0 =A0def bar= (s as String?)<br>=A0 =A0 =A0 =A0if s =A0# same as &quot;if s is not nil&qu= ot;<br>=A0 =A0 =A0 =A0 =A0 =A0print Utils.countChars(s, c&#39;x&#39;)<br> <br><br>Please note the question mark &quot;?&quot; on String? forces a com= pile time check.<br><br>--As a side note<br>The sample snippet is written C= obra (not Boo).. CLR NET.<br>Cobra&#39;s DBC is heavily influenced by D !<b= r> <br>Bearophile could be interested; so here the link<br><br><a href=3D"http= ://cobra-language.com/docs/quality/" target=3D"_blank">http://cobra-languag= e.com/docs/quality/</a><br>Bjoern<br></blockquote></div><div><br></div>I&#3= 9;ve played with Cobra before, and=A0I agree that Cobra does it very well.<= div> <br></div><div>I hope that D allows non-nullable types so that those seg fa= ults/access violations can be prevented/caught easily at compile-time.</div=
<div>(for the sake of increasing the self-documenting ability of code, the=

<br> <br></div> --e0cb4e6ff1f5c4504d04947d0abf--
Nov 07 2010