View mode: basic / threaded / horizontal-split · Log in · Help
December 08, 2011
Re: Comma operator = broken design
> 
> Why is this operator still kept around?

No offense, but I find it strange/funny that you even ask why! :)

Have you never used comma in for loops???
December 08, 2011
Comma operator = broken design
> This is, honestly, ridiculous. On most European keyboard 
> layouts, comma is on the same key as semicolon.
Modern shells usually allow to use several keyboard layouts, 
switching between them as you need. You may want to add US 
keyboard layout (selected layout is maintained per-window).
December 08, 2011
Re: Comma operator = broken design
On 08.12.2011 05:52, bcs wrote:
> On 12/07/2011 08:49 AM, Alex Rønne Petersen wrote:
>> I really do not see the value in allowing such syntax in the first
>> place. I've been told that one argument was that generated code might
>> use it, but I have no idea why it would be needed. Furthermore, this
>> operator makes it very hard to introduce Python-style tuples in the
>> language.
>
> IIRC the generated code argument was actually made with regards to the
> compiler doing internal rewriting of the AST. If I'm remembering
> correctly, this make it even weaker as, at that point, there is no
> reason that the form of the AST need match the syntax.

Worth noting that the comma operator inside the compiler is not the same 
as the one in the language. It supports declarations, in a way that D 
doesn't. You can't write this in normal D, for example:

   (int x; , x = 2);

But that's what the compiler does internally.

The "compiler uses it internally" argument isn't valid at all.
December 08, 2011
Re: Comma operator = broken design
On Thu, 08 Dec 2011 11:17:48 +0200, Dejan Lekic <dejan.lekic@gmail.com>  
wrote:

>
>>
>> Why is this operator still kept around?
>
> No offense, but I find it strange/funny that you even ask why! :)
>
> Have you never used comma in for loops???
>

Not sure if it is that relevant for D, but good point.

for(auto i=beg(), e=end(); i!=e; ++i)
for(auto i, j, k;; ++i, ++k)
...
December 08, 2011
Re: Comma operator = broken design
On Thu, 08 Dec 2011 12:17:20 -0000, so <so@so.so> wrote:

> On Thu, 08 Dec 2011 11:17:48 +0200, Dejan Lekic <dejan.lekic@gmail.com>  
> wrote:
>
>>
>>>
>>> Why is this operator still kept around?
>>
>> No offense, but I find it strange/funny that you even ask why! :)
>>
>> Have you never used comma in for loops???
>>
>
> Not sure if it is that relevant for D, but good point.
>
> for(auto i=beg(), e=end(); i!=e; ++i)
> for(auto i, j, k;; ++i, ++k)
> ...

It's kinda amusing that this thread appeared just as we had a case of this  
here at work.  The developer accidentally coded something like...

if (function(..), FALSE)
{
}

Accidentally adding the ", FALSE" /after/ the ) instead of as a new  
parameter to the function.

(note; This was in C++ with default parameter values so the function can  
in fact take 1-4 args).

When I pointed this out, he said "how does that even compile" and was  
completely unaware of the existence of the comma operator, nor (once I  
explained it) did he realise it was in any way related to the comma used  
in for loops.  People simply don't think of them as being the same thing  
at all.  Instead, people learn the comma syntax as a special  
characteristic of the for loop, and use it nowhere else.

I think the comma operator is of little benefit (except where used in a  
for loop) and it is a source of bugs and we'd be better off without it.   
Even if it means porting C/C++ requires modification, or existing D (I  
doubt very much of it) breaks.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
December 08, 2011
Re: Comma operator = broken design
On Thu, 08 Dec 2011 18:02:11 +0200, Regan Heath <regan@netmail.co.nz>  
wrote:

> When I pointed this out, he said "how does that even compile" and was  
> completely unaware of the existence of the comma operator, nor (once I  
> explained it) did he realise it was in any way related to the comma used  
> in for loops.  People simply don't think of them as being the same thing  
> at all.  Instead, people learn the comma syntax as a special  
> characteristic of the for loop, and use it nowhere else.

Not that related but my all time favorite is still:

type a = a + 2; // compiles with no errors, no warnings, no explosions  
(that i know of)
December 08, 2011
Re: Comma operator = broken design
> Ahem. So are you suggesting that (a,b) means a tuple everywhere but in a
> for loop, where it is used to separate two statements?

If we use the comma operator only for tuples, there needn't to be a 
special case for loops:

for(x, y = 0 , 100; x < y ; x, y += 1,-1) { ... }
December 08, 2011
Re: Comma operator = broken design
>
> type a = a + 2; // compiles with no errors, no warnings, no 
> explosions (that i know of)

If "type" has the default initialiser, then what is the problem?
December 08, 2011
Re: Comma operator = broken design
On Thu, 08 Dec 2011 19:25:10 +0200, Dejan Lekic <dejan.lekic@gmail.com>  
wrote:

>>
>> type a = a + 2; // compiles with no errors, no warnings, no explosions  
>> (that i know of)
>
> If "type" has the default initialiser, then what is the problem?

What does it do in both C and D context?
1. It does different things.
2. C version even worse because of debug/release difference.
3. If D still does this, it violates the B-D rule (either does the same  
thing or doesn't compile at all. Actually there are many things violate  
this rule...)

type a; // even this simple code violates B-D rule.

What is the use case?
. Is there any?
. If there is not any you think, but still compiler allows it, it  
generates nothing but bugs (from experience :) ).

Question should be, why does it exist at all?
December 08, 2011
Re: Comma operator = broken design
On 12/08/2011 05:02 PM, Regan Heath wrote:
> On Thu, 08 Dec 2011 12:17:20 -0000, so <so@so.so> wrote:
>
>> On Thu, 08 Dec 2011 11:17:48 +0200, Dejan Lekic
>> <dejan.lekic@gmail.com> wrote:
>>
>>>
>>>>
>>>> Why is this operator still kept around?
>>>
>>> No offense, but I find it strange/funny that you even ask why! :)
>>>
>>> Have you never used comma in for loops???
>>>
>>
>> Not sure if it is that relevant for D, but good point.
>>
>> for(auto i=beg(), e=end(); i!=e; ++i)
>> for(auto i, j, k;; ++i, ++k)
>> ...
>
> It's kinda amusing that this thread appeared just as we had a case of
> this here at work. The developer accidentally coded something like...
>
> if (function(..), FALSE)
> {
> }
>
> Accidentally adding the ", FALSE" /after/ the ) instead of as a new
> parameter to the function.
>
> (note; This was in C++ with default parameter values so the function can
> in fact take 1-4 args).
>
> When I pointed this out, he said "how does that even compile" and was
> completely unaware of the existence of the comma operator, nor (once I
> explained it) did he realise it was in any way related to the comma used
> in for loops. People simply don't think of them as being the same thing
> at all. Instead, people learn the comma syntax as a special
> characteristic of the for loop, and use it nowhere else.
>
> I think the comma operator is of little benefit (except where used in a
> for loop) and it is a source of bugs and we'd be better off without it.
> Even if it means porting C/C++ requires modification, or existing D (I
> doubt very much of it) breaks.
>

Phobos would break, for example. And some of my code too.
1 2 3 4 5 6
Top | Discussion index | About this forum | D home