July 15, 2014
On Tuesday, 15 July 2014 at 08:01:40 UTC, Meta wrote:
> Spot the bug:
>
> template flattenedType(R, uint depth = uint.max)
> if (isInputRange!R)
> {
> 	static if (depth > 0)
> 	{
> 		static if (!isInputRange!(typeof(R.init.front)))
> 		{
> 			alias flattenedType = typeof(R.init.front, depth - 1);
> 		}
> 		else
> 		{
> 			alias flattenedType = flattenedType!(typeof(R.init.front), depth - 1);
> 		}
> 	}
> 	else
> 	{
> 		alias flattenedType = typeof(R.init.front);
> 	}
> }
>
> I'll give you a hint: the bug causes flattenedType!R to always returned uint.

Nuh uh...The comma operator is too valuable to loose...
July 15, 2014
Jane Doe:

> So, you wanna nerf everything that could produce the wrong behavior?

A smarter question is: How to reduce the number of bugs in D code decreasing the language functionality only very little, and keeping the language handy (or making it even more handy)?


> There is nothing in this example that shows the comma operator is evil.

Typeof takes an argument, but two were given:

typeof(R.init.front, depth - 1)

The fact that in truth only one argument was given is caused by the comma operator that has both the semantics of sequence (when you define multiple variables, multiple enum items, multiple function arguments, multiple template arguments, and so on), and the not often useful semantics of sequencing of expressions with side effects, plus keeping the result of the last one.

If you restrict the usage of commas, disallowing that second semantics, that code causes a compilation error.

The idea of killing the comma operator was discussed at length in past threads. I suggest to deprecate it, and eventually open the syntax to better usages (tuples and pattern matching, making D quite more handy than now).

Bye,
bearophile
July 15, 2014
> The reason for getting rid of it is because it's borderline useless. It causes more accidental bugs than it enables deliberate uses.

I find the comma op useful somemtimes. This example shows absolutely nothing of comma wrongdoing. If anything, there could be a warning for passing signed value to unsigned argument (that caught me, not comma).
July 15, 2014
On 7/15/14, Jane Doe via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> Should be reduce the speed limit to 5mph because cars
> can kill people?

No but maybe we should reduce the number of different accounts a single person can use to troll around these forums.
July 15, 2014
On Tue, Jul 15, 2014 at 05:03:21PM +0000, Martin Krejcirik via Digitalmars-d wrote:
> >The reason for getting rid of it is because it's borderline useless. It causes more accidental bugs than it enables deliberate uses.
> 
> I find the comma op useful somemtimes.

Example?


T

-- 
Don't drink and derive. Alcohol and algebra don't mix.
July 15, 2014
On Tue, Jul 15, 2014 at 04:52:34PM +0000, Israel Rodriguez via Digitalmars-d wrote: [...]
> Nuh uh...The comma operator is too valuable to loose...

Please cite an example where it is "valuable"?


T

-- 
Without outlines, life would be pointless.
July 15, 2014
Martin Krejcirik:

> I find the comma op useful somemtimes.

Please shows us all the cases you can think of (or coming from your own code, or coming from the Web) where you think it's useful.


> This example shows absolutely nothing of comma wrongdoing.

See my precedent answer.


> If anything, there could be a warning for passing signed value to unsigned argument (that caught me, not comma).

That's an OffTopic battle, for another day :-)

Bye,
bearophile
July 15, 2014
On Tuesday, 15 July 2014 at 17:09:14 UTC, H. S. Teoh via Digitalmars-d wrote:
> On Tue, Jul 15, 2014 at 04:52:34PM +0000, Israel Rodriguez via Digitalmars-d wrote:
> [...]
>> Nuh uh...The comma operator is too valuable to loose...
>
> Please cite an example where it is "valuable"?
>
>
> T

Yes please, I legitimately can't think of any use case. I don't understand why was this was ever introduced to D? What is the use?
July 15, 2014
On Tuesday, 15 July 2014 at 17:26:12 UTC, Tofu Ninja wrote:
> Yes please, I legitimately can't think of any use case. I don't understand why was this was ever introduced to D? What is the use?

C compatibility as far as I know.
July 15, 2014
>
> Example?
>

For loop with multiple variables and various one liners of questionable utility aside:

import std.stdio;

bool funk()
{
    static int count;
    return ++count > 1 ? true : false;
}

void main()
{
    bool flag = false;
    if (flag && funk)
        writeln("a");
    else if (flag=true, flag && funk)
        writeln("b");
    else if (flag && funk)
        writeln("c");
}