www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Spec#, nullables and more

reply bearophile <bearophileHUGS lycos.com> writes:
Don:

 bearophile wrote:
 ...
 http://d.puremagic.com/issues/show_bug.cgi?id=5081


 As was pointed out in a recent post, the return value of a pure function 
 is guaranteed to be unique, so could be allowed to implictly cast to 
 immutable. I'm planning a patch for that soon, to see how well it works 
 in practice.

Right, that's the bug 5081 :-) It works with strong pure. It's a simple but very nice idea that avoids some casts.
 But I don't think that would work for non-nulls. I don't think the two 
 situations have a great deal in common.

I see, they may have different solutions too. Bye and thank you, bearophile
Nov 06 2010
next sibling parent Christopher Bergqvist <chris digitalpoetry.se> writes:
--00163631046f7ec8d9049460618c
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Does D have anything comparable to C++ references =E0 la "void
nullCheckLessFunction(const std::string& notNullStr) {...}" or does it only
have the equivalent of "void nullCheckingRequired(const std::string*
mightByNullStr) {...}"?

--00163631046f7ec8d9049460618c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8">Do=
es D have anything comparable to C++ references =E0 la &quot;void nullCheck=
LessFunction(const std::string&amp; notNullStr) {...}&quot; or does it only=
 have the equivalent of &quot;void nullCheckingRequired(const std::string* =
mightByNullStr) {...}&quot;?

--00163631046f7ec8d9049460618c--
Nov 06 2010
prev sibling next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Sat, 06 Nov 2010 14:06:20 +0300, Christopher Bergqvist  =

<chris digitalpoetry.se> wrote:

 Does D have anything comparable to C++ references =C3=A0 la "void
 nullCheckLessFunction(const std::string& notNullStr) {...}" or does it=

 only
 have the equivalent of "void nullCheckingRequired(const std::string*
 mightByNullStr) {...}"?

void nullCheckLessFunction(ref const(string) notNullStr) { .. }
Nov 06 2010
prev sibling parent Christopher Bergqvist <chris digitalpoetry.se> writes:
--0016364d30a5e5327d049461a7a1
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Sat, Nov 6, 2010 at 12:23 PM, Denis Koroskin <2korden gmail.com> wrote:

 On Sat, 06 Nov 2010 14:06:20 +0300, Christopher Bergqvist <
 chris digitalpoetry.se> wrote:

  Does D have anything comparable to C++ references =E0 la "void
 nullCheckLessFunction(const std::string& notNullStr) {...}" or does it
 only
 have the equivalent of "void nullCheckingRequired(const std::string*
 mightByNullStr) {...}"?

void nullCheckLessFunction(ref const(string) notNullStr) { .. }

I made two comparison snippets between D & C++. http://ideone.com/VPzz6 (D) http://ideone.com/HzFRB (C++) I feel like C++ is one small step ahead of D in this respect. It's not possible to trust that C++ references are non-null, but at least they serve as concise documentation of the expected contents and tend to make surrounding code perform the null-check up front before dereferencing from pointer to C++ reference. --0016364d30a5e5327d049461a7a1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On Sat, Nov 6, 2010 at 12:23 PM, Denis Koroskin = <span dir=3D"ltr">&lt;<a href=3D"mailto:2korden gmail.com">2korden gmail.co= m</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margi= n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <div><div></div><div class=3D"h5">On Sat, 06 Nov 2010 14:06:20 +0300, Chris= topher Bergqvist &lt;<a href=3D"mailto:chris digitalpoetry.se" target=3D"_b= lank">chris digitalpoetry.se</a>&gt; wrote:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Does D have anything comparable to C++ references =E0 la &quot;void<br> nullCheckLessFunction(const std::string&amp; notNullStr) {...}&quot; or doe= s it only<br> have the equivalent of &quot;void nullCheckingRequired(const std::string*<b= r> mightByNullStr) {...}&quot;?<br> </blockquote> <br></div></div> void nullCheckLessFunction(ref const(string) notNullStr) { .. }<br> </blockquote></div><br><div>I made two comparison snippets between D &amp; = C++.</div><div><br></div><div><a href=3D"http://ideone.com/VPzz6">http://id= eone.com/VPzz6</a>=A0(D)</div><div><a href=3D"http://ideone.com/HzFRB">http= ://ideone.com/HzFRB</a>=A0(C++)</div> <div><br></div><div>I feel like C++ is one small step ahead of D in this re= spect. It&#39;s not possible to trust that C++ references are non-null, but= at least they serve as concise documentation of the expected contents and = tend to make surrounding code perform the null-check up front before derefe= rencing from pointer to C++ reference.</div> --0016364d30a5e5327d049461a7a1--
Nov 06 2010