Re: [Vala] Null Coalescing Assignment Operator

2017-05-28 Thread Al Thomas via vala-list
> From: Guillaume Poirier-Morency 
> Sent: Sunday, 28 May 2017, 16:59
> Subject: Re: [Vala] Null Coalescing Assignment Operator

> Le dimanche 28 mai 2017 à 10:20 +0200, Ulink a écrit :
> > > thing = thing ? create ();
> > 
> > I think you meant
> > 
> > thing = thing ?? create ();

> Yeah, my mistake! Evan actually pointed that out first on IRC.

> > Edward seems lazy and don't want to write "thing" two times ;-)

> What I think we need is an Elvis accessor to turn:

>C? c = null;
>var a = thing_a ();
> if (a != null) {
> var b = thing_b ();
> if (b != null) {
> c = thing_c ();
> }
> }

> into:


>var c = thing_a ()?.thing_b ()?.thing_c ();

I think it's better just to give your variables sensible defaults and
avoid the whole null things as much as possible. So use an empty string
for a customer without an email address and so on. Look up the computer
scientist Tony Hoare and why he thinks nulls were his billion dollar 

mistake! :)

I think the ?. notation is often referred to as the safe navigation operator.
As you say there is also the Elvis operator, ?:, when used as a binary
operator and ? : used as a ternary operator. And of course ?? used as a
null coalescing operator. If programmers aren't using this kind of symbolic
logic regularly it can be hard to recall precisely what is supposed to be
happening and read existing code. It's kind of like the combination of key
presses needed to exit vim when it suddenly pops up on a newly installed
Unix system. Take a look at this for a mildly amusing read:
https://stackoverflow.blog/2017/05/23/stack-overflow-helping-one-million-developers-exit-vim/

As far as the null safe navigation operator goes here are some interesting
counterpoints:
http://enterprisecraftsmanship.com/2015/05/11/3-misused-of-operator-in-c-6/

Al
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Null Coalescing Assignment Operator

2017-05-28 Thread Guillaume Poirier-Morency
Le dimanche 28 mai 2017 à 10:20 +0200, Ulink a écrit :
> > thing = thing ? create ();
> 
> I think you meant
> 
> thing = thing ?? create ();

Yeah, my mistake! Evan actually pointed that out first on IRC.

> 
> Edward seems lazy and don't want to write "thing" two times ;-)

What I think we need is an Elvis accessor to turn:

   C? c = null;
var a = thing_a ();
if (a != null) {
var b = thing_b ();
if (b != null) {
c = thing_c ();
}
}

into:

var c = thing_a ()?.thing_b ()?.thing_c ();

> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
-- 
Guillaume Poirier-Morency 

Étudiant au baccalauréat en informatique à l'Université de Montréal
Stagiaire de recherche à l'IRIC

Mon blog: https://arteymix.github.io/
Clé PGP: B1AD6EA5

signature.asc
Description: This is a digitally signed message part
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Null Coalescing Assignment Operator

2017-05-28 Thread Ulink
> thing = thing ? create ();

I think you meant

thing = thing ?? create ();

Edward seems lazy and don't want to write "thing" two times ;-)
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Null Coalescing Assignment Operator

2017-05-27 Thread Guillaume Poirier-Morency
What's wrong with:

thing = thing ? create ();

Le samedi 27 mai 2017 à 16:46 -0700, Edward Hennessy a écrit :
> This snippet shows a common implementation of lazy initialization:
> 
>   if (thing == null)
>   {
>   thing = create();
>   }
> 
> 
> It would be nice to have a concise form using a null coalescing
> operator, like:
> 
>   thing ??= create();
> 
> 
> Would a null coalescing assignment operator be a reasonable addition
> to Vala?
> 
> Ed
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
-- 
Guillaume Poirier-Morency

Étudiant au baccalauréat en informatique à l'Université de Montréal
Stagiaire de recherche à l'IRIC

Mon blog: https://arteymix.github.io/
Mon projet de coopérative: https://pittoresque.github.io/
Clé PGP: B1AD6EA5


signature.asc
Description: This is a digitally signed message part
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Null Coalescing Assignment Operator

2017-05-27 Thread Edward Hennessy
This snippet shows a common implementation of lazy initialization:

if (thing == null)
{
thing = create();
}


It would be nice to have a concise form using a null coalescing operator, like:

thing ??= create();


Would a null coalescing assignment operator be a reasonable addition to Vala?

Ed
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list