March 24, 2014
On Mon, 2014-03-24 at 12:44 +0000, bearophile wrote:
[…]
> I agree, 1-tuples in Python are tricky. Compare it with the clear Python list literal syntax:
> 
> []        => 0-length list
> [1]       => 1-length list
> [1, 2]    => 2-length list
> [1, 2, 3] => 2-length list

But note that:

[1,]       => 1-length list
[1, 2,]    => 2-length list
[1, 2, 3,] => 2-length list

Do not underestimate the power of allowed trailing commas.

-- 
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

March 24, 2014
If you are not ready to break the code for it, there is nothing to discuss. It is not something to compromise about - either kill it completely, or just let it be. Anything else will make things only worse.
March 24, 2014
On Monday, 24 March 2014 at 13:12:36 UTC, Dicebot wrote:
> If you are not ready to break the code for it, there is nothing to discuss. It is not something to compromise about - either kill it completely, or just let it be. Anything else will make things only worse.

And yes, no one so far has presented a code case where using comma expression is legitimate and not just trying to save few keystrokes by confusing the hell out of everyone else.
March 24, 2014
On Mon, 2014-03-24 at 13:00 +0000, w0rp wrote:
[…]
> 
> Consider the following.
> 
> >>> (1, 2)
> 
> (1, 2)
> 
> >>> (1)
> 
> 1
> 
> >>> (1 * (3 * 4,))
> 
> (-1, )
> 
> >>> (1 * (3 - 4,) * 2)
> 
> (-1, -1)
> 
> >>> foo = lambda : 3
> 
> >>> (
> ...     foo()
> ... )
> 
> 3
> 
> >>> (
> ...     foo(),
> ... )
> 
> (3, )
> 
> I see this kind of confusion happen often, and the convenient syntax becomes a burden.

The moral of the story is that if you want to avoid the situation Python
is in, then do not use ( and ) as delimiters for expressions and also
something else semantically different.

-- 
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

March 24, 2014
On Sunday, 23 March 2014 at 20:56:45 UTC, Andrei Alexandrescu wrote:
> Discuss: https://github.com/D-Programming-Language/dmd/pull/3399
>
> Andrei

The extensive use of binary comma operator that I had seen was in ctrace code.  (http://docs.oracle.com/cd/E24457_01/html/E22003/ctrace.1.html). ctrace takes C code and inserts printfs for each statement so that the flow and variables' value can be observed during its execution.

For example,

while ((c = getchar()) != EOF)

is written as

while ( ((c = getchar()), printf(fmt, c), c) != EOF)

- Sarath
March 24, 2014
On Monday, 24 March 2014 at 13:12:36 UTC, Dicebot wrote:
> It is not something to compromise about - either kill it completely, or just let it be. Anything else will make things only worse.

Indeed.
March 24, 2014
Russel Winder:

> But note that:
>
> [1,]       => 1-length list
> [1, 2,]    => 2-length list
> [1, 2, 3,] => 2-length list
>
> Do not underestimate the power of allowed trailing commas.

In Python it's ignored:

>>> [1,]
[1]
>>> [1, 2,]
[1, 2]
>>> [1, 2, 3,]
[1, 2, 3]

Bye,
bearophile
March 24, 2014
On 24/03/2014 13:10, monarch_dodra wrote:
> On Monday, 24 March 2014 at 12:43:22 UTC, Steven Schveighoffer wrote:
>> I have an allergic reaction to braces on the same lines :) Only place
>> I ever use them is when the whole function can fit on the same line.

+1, I wish we could write:
T fun() => result;

Discussion here:
https://d.puremagic.com/issues/show_bug.cgi?id=7176

> I get that "allergic reaction" :)
>
> But it does have its advantages in terms of robustness (accidental ";"),
> and scaling. For example, there are cases where "," can't be used:
>
> Type myType;
> if(cond)
>      {int dummy = 5; initialize(myType, dummy);}

Here I would just use several lines for better readability. I would only use the comma for simple expressions that don't depend on each other:

if (cond)
	x=5, y=6;

> As a general rule, I feel that "{}" is ugly, but that once they are
> there, no-one is going to break my code.

March 24, 2014
On Mon, 24 Mar 2014 11:35:38 -0000, monarch_dodra <monarchdodra@gmail.com> wrote:

> On Monday, 24 March 2014 at 10:57:45 UTC, Regan Heath wrote:
>> On Sun, 23 Mar 2014 20:56:25 -0000, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
>>> Discuss: https://github.com/D-Programming-Language/dmd/pull/3399
>>
>> Would it have any effect on:
>>
>> int *p, q;
>
> That's not a comma operator. So no.

That's my Q answered :)

> BTW, I'd *STRONGLY* urge you to write that as:
> int* p, q;
>
> since in D, both "p" and "q" are of type "int*", unlike in C.

I am well aware :p

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
March 24, 2014
On Mon, Mar 24, 2014 at 01:13:51PM +0000, Dicebot wrote:
> On Monday, 24 March 2014 at 13:12:36 UTC, Dicebot wrote:
> >If you are not ready to break the code for it, there is nothing to discuss. It is not something to compromise about - either kill it completely, or just let it be. Anything else will make things only worse.
> 
> And yes, no one so far has presented a code case where using comma expression is legitimate and not just trying to save few keystrokes by confusing the hell out of everyone else.

I vote to kill the comma operator.

The only actual legit use case I've seen so far is inside a for-loop, where IMO the syntax should just be special-cased. All other uses brought up so far fail to convince me about their merit -- they can all be rewritten in a style that's more readable, less error-prone, and more maintainable.  The objections all amount to "Oh no! You mean I have to actually type 2 extra brace characters to write code in the bad style I'm habitually used to writing?!", and "Oh no! I have to actually split up my multiple statements into actual multiple statements which is actually more readable for the poor sods who will have to maintain this code after I leave?!", both which utterly fail to convince me.

The only "indispensible" use of the comma operator that I've seen in my entire career is in IOCCC entries, where the whole point is to make the code obscure and non-obvious.

Not to mention, the fact that some people have been asking about whether "int x,y" will continue to be valid syntax shows that very few people even understand what the comma operator *is*, much less its subtle semantics, which is another strong sign that we should kill it with extreme prejudice. Of all the bad design decisions made in C and C++, the comma operator must be the most blatant one that D failed to shed. Kill it, I say.


T

-- 
People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird. -- D. Knuth