assignment: left-to-right or right-to-left evaluation?
schveiguy at yahoo.com
Mon May 11 08:34:51 PDT 2009
On Mon, 11 May 2009 11:26:36 -0400, Jarrett Billingsley
<jarrett.billingsley at gmail.com> wrote:
> On Mon, May 11, 2009 at 11:07 AM, Steven Schveighoffer
> <schveiguy at yahoo.com> wrote:
>>>> mydic[x] = mydic[y] = mydic[z] = mydic.length;
>> auto tmp = mydic.length;
>> mydic[x] = tmp;
>> mydic[y] = tmp;
>> mydic[z] = tmp;
>> That sucks. We have to remember, there are reasons why we stopped
>> having to
>> use assembly :)
> Funny, I vastly prefer the latter to the former. Having more than one
> thing happen on one line is very difficult to read after having
> written it, for me.
So I take it if you have many function calls, or chained function calls,
you split them out into separate lines? :P
auto tmp1 = gun(123);
auto tmp2 = fun(tmp1);
I look at chained assignment as no different.
Even if order of operations was defined as left to right, I'd still prefer
auto tmp = mydic.length;
mydic[x] = mydic[y] = mydic[z] = tmp;
I use assignment chaining all the time in C# Forms when I'm
disabling/enabling a set of controls. e.g.:
checkBox1.Enabled = textField1.Enabled = textField2.Enabled =
textField3.Enabled = true;
It seems pretty straightforward to me...
More information about the Digitalmars-d