Jump to page: 1 24  
Page
Thread overview
What the hell is wrong with D?
Sep 19
jmh530
Sep 19
jmh530
Sep 19
jmh530
Communication was [Re: What the hell is wrong with D?]
Sep 19
nkm1
Sep 20
jmh530
Sep 20
B4s1L3
Sep 20
nkm1
[OT] Converting booleans to numbers
Sep 20
jmh530
Sep 20
nkm1
Sep 21
Mark
September 19
	writeln(x + ((_win[0] == '@') ? w/2 : 0));
	writeln(x + (_win[0] == '@') ? w/2 : 0);

The first returns x + w/2 and the second returns w/2!

WTF!!! This stupid bug has caused me considerable waste of time. Thanks Walter! I know you care so much about my time!

I assume someone is going to tell me that the compiler treats it as

writeln((x + (_win[0] == '@')) ? w/2 : 0);

Yeah, that is really logical! No wonder D sucks and has so many bugs! Always wants me to be explicit about the stuff it won't figure out but it implicitly does stuff that makes no sense. The whole point of the parenthesis is to inform the compiler about the expression to use. Not use everything to the left of ?.

Thanks for wasting some of my life... Just curious about who will justify the behavior and what excuses they will give.
September 19
On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote:
>
> 	writeln(x + ((_win[0] == '@') ? w/2 : 0));
> 	writeln(x + (_win[0] == '@') ? w/2 : 0);
>
> The first returns x + w/2 and the second returns w/2!
>
> WTF!!! This stupid bug has caused me considerable waste of time. Thanks Walter! I know you care so much about my time!
>
> I assume someone is going to tell me that the compiler treats it as
>
> writeln((x + (_win[0] == '@')) ? w/2 : 0);
>
> Yeah, that is really logical! No wonder D sucks and has so many bugs! Always wants me to be explicit about the stuff it won't figure out but it implicitly does stuff that makes no sense. The whole point of the parenthesis is to inform the compiler about the expression to use. Not use everything to the left of ?.
>
> Thanks for wasting some of my life... Just curious about who will justify the behavior and what excuses they will give.

Why do you claim that a bug in your code is a compiler bug? Check "Operator precedence" [1]. There is really no reason why the current precedence is less "logical" than what you're awaiting.

And try to think about things you're writing, nobody forces you to use D.

[1] https://wiki.dlang.org/Operator_precedence
September 19
On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote:
>
> Thanks for wasting some of my life... Just curious about who will justify the behavior and what excuses they will give.

Pretty sure it would be exactly the same thing in C...
September 19
On Tuesday, 19 September 2017 at 18:17:47 UTC, jmh530 wrote:
> On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote:
>>
>> Thanks for wasting some of my life... Just curious about who will justify the behavior and what excuses they will give.
>
> Pretty sure it would be exactly the same thing in C...

It is (and Java and C# and pretty much every other C style language though the nicer implicit conversion rules means it gets caught more easily). It is a big source of programmer mistakes. It comes up frequently in PVS Studio's open source analysis write ups.
September 19
On 09/19/2017 11:34 AM, Brad Anderson wrote:
> On Tuesday, 19 September 2017 at 18:17:47 UTC, jmh530 wrote:

>> Pretty sure it would be exactly the same thing in C...
>
> It is (and Java and C# and pretty much every other C style language
> though the nicer implicit conversion rules means it gets caught more
> easily). It is a big source of programmer mistakes. It comes up
> frequently in PVS Studio's open source analysis write ups.

Just a random Google find for some entertainment. :)


http://twistedoakstudios.com/blog/Post5273_how-to-read-nested-ternary-operators

  string result = i % 2 == 0 ? "a" : i % 3 == 0 ? "b" : i % 5 == 0 ? "c" : i % 7 == 0 ? "d" : "e";

Ali

September 19
On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote:
> I assume someone is going to tell me that the compiler treats it as
>
> writeln((x + (_win[0] == '@')) ? w/2 : 0);
>
> Yeah, that is really logical!

Yeah, I've been bitten by that in languages like C#. I wish D didn't follow in C#'s footsteps and chosen a different syntax: `()? :`

That way if there aren't any parentheses the compiler could throw out an error until you specify what the operating is working with. It would make for a little overhead but these complex ternary expressions can be confusing.
September 19
On Tuesday, 19 September 2017 at 18:51:51 UTC, Jesse Phillips wrote:
> On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote:
>> I assume someone is going to tell me that the compiler treats it as
>>
>> writeln((x + (_win[0] == '@')) ? w/2 : 0);
>>
>> Yeah, that is really logical!
>
> Yeah, I've been bitten by that in languages like C#. I wish D didn't follow in C#'s footsteps and chosen a different syntax: `()? :`
>
> That way if there aren't any parentheses the compiler could throw out an error until you specify what the operating is working with. It would make for a little overhead but these complex ternary expressions can be confusing.

Yes, it's not that they are confusing but illogical.

a + b ? c : d

in a complex expression can be hard to interpret if a and b are complex. The whole point of parenthesis is to disambiguate and group things. To not use them is pretty ignorant.

1 + 2 ? 3 : 4

That is ambiguous. is it (1 + 2) ? 3 : 4 or 1 + (2 ? 3 : 4)?

Well,

()?: is not ambiguous!

The D community preaches all this safety shit but when it comes down to it they don't seem to really care(look at the other responses like like "Hey, C does it" or "Hey, look up the operator precedence"... as if those responses are meaningful).

I'm just glad there is at least one sane person that decided to chime in... was quite surprised actually. I find it quite pathetic when someone tries to justify a wrong by pointing to other wrongs. It takes away all credibility that they have.









September 19
On Tuesday, 19 September 2017 at 19:16:05 UTC, EntangledQuanta wrote:
>
> ()?: is not ambiguous!
>
> The D community preaches all this safety shit but when it comes down to it they don't seem to really care(look at the other responses like like "Hey, C does it" or "Hey, look up the operator precedence"... as if those responses are meaningful).
>

I sympathize that it was a difficult to find problem. Happens to me a lot. Nevertheless, I pretty much never use ternary operators because Matlab was my first language was it doesn't have them. I'm always writing out if() { } else { }. So it's not really an error that happens for me.

The point that others and myself were making about C is that your initial post was very critical of D and Walter. Unduly, IMO. You were blaming D for the problem, when it turns out that in virtually every language that uses this syntax it works this way (and I checked like 10, just to be sure). Harshly criticizing Walter for something that is a generally accepted way of doing things across many programming languages is unreasonable. D never promised to be the greatest language ever whose users never ever write any buggy code at all. It's aims are a bit more limited than that.

There's an easy solution to your problem: use more parentheses with conditional ternary operators.
September 19
On 9/19/17 1:40 PM, EntangledQuanta wrote:

> The first returns x + w/2 and the second returns w/2!

Did you mean (x + w) / 2 or x + (w / 2)? Stop being ambiguous!

-Steve
September 19
On Tuesday, 19 September 2017 at 19:16:05 UTC, EntangledQuanta wrote:
> [snip]
>
> I'm just glad there is at least one sane person that decided to chime in... was quite surprised actually. I find it quite pathetic when someone tries to justify a wrong by pointing to other wrongs. It takes away all credibility that they have.

I have no doubt that had someone thought to propose addressing this when the language was new it would have been seriously considered and likely accepted (given how frequently this causes bugs). D tried to fix a lot of behavior from C that was bug prone but it didn't catch everything.

If you want to help, I suggest trying to come up with a DIP that addresses it while being conscious of how to avoid breaking an enormous amount of code. I suspect it's a hard and maybe impossible problem but if you are up for the challenge I'm sure your efforts would be welcome.
« First   ‹ Prev
1 2 3 4