February 27, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Remo | On 2014-02-27 14:27, Remo wrote: > > Apparently C# will get it in the next version. > http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-last-c-is-getting-sometimes-called-the-safe-navigation-operator.aspx > > > What do you think how well would this work in D2 ? I like it. -- /Jacob Carlborg |
February 27, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Thursday, 27 February 2014 at 20:49:59 UTC, deadalnix wrote:
> On Thursday, 27 February 2014 at 13:27:14 UTC, Remo wrote:
>>
>> Apparently C# will get it in the next version.
>> http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-last-c-is-getting-sometimes-called-the-safe-navigation-operator.aspx
>>
>> What do you think how well would this work in D2 ?
>
> Chaining . operation is a code smell to begin with, and having
> everything nullable is dubious as well. This is fixing a problem
> that shouldn't exists to begin with.
+1
Please no.
|
February 27, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | On Thu, 27 Feb 2014 16:20:47 -0500, Peter Alexander <peter.alexander.au@gmail.com> wrote: > On Thursday, 27 February 2014 at 20:49:59 UTC, deadalnix wrote: >> On Thursday, 27 February 2014 at 13:27:14 UTC, Remo wrote: >>> >>> Apparently C# will get it in the next version. >>> http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-last-c-is-getting-sometimes-called-the-safe-navigation-operator.aspx >>> >>> What do you think how well would this work in D2 ? >> >> Chaining . operation is a code smell to begin with, and having >> everything nullable is dubious as well. This is fixing a problem >> that shouldn't exists to begin with. > > +1 > > Please no. Yes. Taken from the example: parent?.child?.child?.child Given no context, this may make sense. But with context, likely you have verified beforehand the answers to some, if not all, of these question marks. However, even with that, I can't help but expect there should be a way to do this in D without changing the language. Something like: ifnull(parent).child.child.child -Steve |
February 27, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Thu, 27 Feb 2014 16:45:11 -0500, Steven Schveighoffer <schveiguy@yahoo.com> wrote: > ifnull(parent).child.child.child brain fart... ifvalid(parent).child.child.child -Steve |
February 27, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Thursday, 27 February 2014 at 20:49:59 UTC, deadalnix wrote:
> On Thursday, 27 February 2014 at 13:27:14 UTC, Remo wrote:
>>
>> Apparently C# will get it in the next version.
>> http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-last-c-is-getting-sometimes-called-the-safe-navigation-operator.aspx
>>
>> What do you think how well would this work in D2 ?
>
> Chaining . operation is a code smell to begin with ...
No, it's not a code smell at all and most of this religious OOP/OOD bullshit has been debunked by now.
|
February 27, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Thursday, 27 February 2014 at 21:49:20 UTC, Steven Schveighoffer wrote:
> On Thu, 27 Feb 2014 16:45:11 -0500, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
>
>> ifnull(parent).child.child.child
>
> brain fart...
>
> ifvalid(parent).child.child.child
>
> -Steve
What you want is a maybe monad, and we can do that with D metaprogramming capabilities already.
|
February 28, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Thu, 2014-02-27 at 20:49 +0000, deadalnix wrote: > On Thursday, 27 February 2014 at 13:27:14 UTC, Remo wrote: > > > > Apparently C# will get it in the next version. http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-last-c-is-getting-sometimes-called-the-safe-navigation-operator.aspx > > > > What do you think how well would this work in D2 ? > > Chaining . operation is a code smell to begin with, and having everything nullable is dubious as well. This is fixing a problem that shouldn't exists to begin with. >From the responses, this is clearly an emotive issue, but chaining . operations and using fluent interfaces is only a code smell to those people who think it is a code smell. Many people think exactly the opposite and that not using chaining where is can be used is a code smell. Groovy has had safe dereferencing for a long time, as have other dynamic languages, C# is coming very late to this game. Any design decision for D needs to look wider than the C# debate, theoretical examples and philosophizing, to actual use in real situations by languages that have chosen to realize this idea. My experience from Groovy, which is relatively limited in that I am not involved in end-client applications only in maintaining and developing Groovy, GPars and Gant, indicates that it is a very helpful tool, analogous to the whole Maybe/Option stuff in pure functional languages. Groovy is now able to probe the issue of whether this operation is as useful/applicable in a statically compiled context as in a dynamic context since the @TypeChecked and @CompileStatic AST transforms allow Groovy to be a static language as Java, Scala, Ceylon, Kotlin are, as well as being a dynamic language as JRuby, Jython, Clojure are. No results as yet though as the experiments have not been explicitly tried. Thus there is no explicit data to reflect on. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
February 28, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Thursday, 27 February 2014 at 20:49:59 UTC, deadalnix wrote:
> On Thursday, 27 February 2014 at 13:27:14 UTC, Remo wrote:
>>
>> Apparently C# will get it in the next version.
>> http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-last-c-is-getting-sometimes-called-the-safe-navigation-operator.aspx
>>
>> What do you think how well would this work in D2 ?
>
> Chaining . operation is a code smell to begin with
It is? Why?
|
February 28, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Friday, 28 February 2014 at 09:24:23 UTC, John Colvin wrote:
> On Thursday, 27 February 2014 at 20:49:59 UTC, deadalnix wrote:
>> On Thursday, 27 February 2014 at 13:27:14 UTC, Remo wrote:
>>>
>>> Apparently C# will get it in the next version.
>>> http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-last-c-is-getting-sometimes-called-the-safe-navigation-operator.aspx
>>>
>>> What do you think how well would this work in D2 ?
>>
>> Chaining . operation is a code smell to begin with
>
> It is? Why?
I would also like to understand why this is a code smell. I'm completely on the fence but would love to hear arguments either way.
|
February 28, 2014 Re: Safe Navigation Operator “?.” for D2 ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Friday, 28 February 2014 at 09:24:23 UTC, John Colvin wrote:
>> Chaining . operation is a code smell to begin with
>
> It is? Why?
If a system is well-designed, then "null" state either means something (and needs to be explicitly handled) or is not possible.
?. provides simple and easy way to write a sloppy code that does not tell the reader if resulting code flow for null case was intentional. Also it is very easy to get accustomed to use ?. everywhere instead of . and get broken logic instead of NullPointerException for cases when pointer is wrongly assumed to never be null.
|
Copyright © 1999-2021 by the D Language Foundation