digitalmars.D.learn - What the hell is wrong with D?
- EntangledQuanta (15/15) Sep 19 2017 writeln(x + ((_win[0] == '@') ? w/2 : 0));
- Eugene Wissner (8/24) Sep 19 2017 Why do you claim that a bug in your code is a compiler bug? Check
- jmh530 (3/5) Sep 19 2017 Pretty sure it would be exactly the same thing in C...
- Brad Anderson (6/12) Sep 19 2017 It is (and Java and C# and pretty much every other C style
- =?UTF-8?Q?Ali_=c3=87ehreli?= (7/13) Sep 19 2017 Just a random Google find for some entertainment. :)
- Patrick Schluter (14/27) Sep 22 2017 So I checked for all the languages listed: C, C#, Java,
- Patrick Schluter (14/27) Sep 23 2017 So I checked for all the languages listed: C, C#, Java,
- Brad Anderson (5/17) Sep 26 2017 It's not quite as big of a deal as it seems because of the RTL
- Jesse Phillips (9/13) Sep 19 2017 Yeah, I've been bitten by that in languages like C#. I wish D
- EntangledQuanta (19/34) Sep 19 2017 Yes, it's not that they are confusing but illogical.
- jmh530 (19/24) Sep 19 2017 I sympathize that it was a difficult to find problem. Happens to
- Brad Anderson (12/17) Sep 19 2017 I have no doubt that had someone thought to propose addressing
- jmh530 (19/24) Sep 19 2017 Changing the operator precedence would certainly lead to enormous
- Jesse Phillips (20/24) Sep 19 2017 jmh530 points out why you're met with such non-agreement of the
- EntangledQuanta (61/86) Sep 19 2017 I'm not open to discussion because it is not a discussion. There
- Jesse Phillips (39/59) Sep 20 2017 That isn't how it went down, you attacked then justification was
- Steven Schveighoffer (3/4) Sep 19 2017 Did you mean (x + w) / 2 or x + (w / 2)? Stop being ambiguous!
- Jack Applegame (3/7) Sep 20 2017 The best answer. :D
- Neia Neutuladh (7/10) Sep 19 2017 Yeah, it sucks to have bugs like this crop up. I have enough
- rikki cattermole (2/14) Sep 19 2017 Agreed, no surprises is the best surprise!
- nkm1 (10/16) Sep 19 2017 There are two issues there; operator precedence and booleans
- EntangledQuanta (6/22) Sep 19 2017 Your an idiot, I know about how operator precedence works far
- Jonathan M Davis (5/29) Sep 19 2017 Please try to be civil. It's fine if you're unhappy about some aspect of...
- jmh530 (4/8) Sep 19 2017 He seemed to be threatening the guy's life over operator
- EntangledQuanta (6/16) Sep 19 2017 Are you an idiot? Seriously, you must be. You just want to create
- EntangledQuanta (7/37) Sep 19 2017 But, of course, It's ok for him to come me an idiot. Let me
- B4s1L3 (5/10) Sep 19 2017 You should swallow your ego a bit. In first place you've made an
- nkm1 (3/8) Sep 19 2017 Ok, you win. I see now that you're very smart :)
- Azi Hassan (5/7) Sep 20 2017 A general rule of thumb when it comes to operator precedence is
- Timon Gehr (36/38) Sep 20 2017 Actually, it is useful enough to have a Wikipedia page:
- jmh530 (13/20) Sep 20 2017 While it's also possible to do this with filter, this is what I'd
- nkm1 (20/36) Sep 20 2017 Mmmm... "The notation was originally introduced by Kenneth E.
- Jonathan M Davis (12/16) Sep 20 2017 I think that most of us would agree with you, but the last time it was
- Timon Gehr (22/52) Sep 21 2017 It's actually straightforward. This C code is obfuscated:
- Steven Schveighoffer (6/12) Sep 21 2017 This seems way easier for me to grok, and is how I would write it.
- Steven Schveighoffer (5/21) Sep 21 2017 Of course, without bugs :)
- Timon Gehr (8/32) Sep 21 2017 This is a good alternative, maybe arrange it like this:
- Steven Schveighoffer (5/12) Sep 21 2017 Hm... I suppose you would do that work at the beginning of dfs, like you...
- Mark (3/19) Sep 21 2017 I would rather use an explicit function for such use cases:
- Tristan B. Kildaire (3/24) Oct 04 2017 When you get too angry about the little things in life. "There are
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.
Sep 19 2017
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
Sep 19 2017
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...
Sep 19 2017
On Tuesday, 19 September 2017 at 18:17:47 UTC, jmh530 wrote:On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote: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.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...
Sep 19 2017
On 09/19/2017 11:34 AM, Brad Anderson wrote:On Tuesday, 19 September 2017 at 18:17:47 UTC, jmh530 wrote: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"; AliPretty sure it would be exactly the same thing in C...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.
Sep 19 2017
On Tuesday, 19 September 2017 at 18:34:13 UTC, Brad Anderson wrote:On Tuesday, 19 September 2017 at 18:17:47 UTC, jmh530 wrote:Javascript, C++, PHP, Perl and D. All have the same order of precedence except, as always the abomination of all languages: C++ (kill it with fire). C++ is the only language that has the ternary operator have the same precedence than the assignment operators. This means a>=5?b=100:b=200; will compile in C++ but not in all the other languages. That's one reason why it irritates me when people continuously refer to C and C++ as if it was the same thing (yes I mean you Walter and Andrei). Even PHP and Perl got it right, isn't that testament of poor taste Bjarne?. :-)On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote: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.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...
Sep 22 2017
On Tuesday, 19 September 2017 at 18:34:13 UTC, Brad Anderson wrote:On Tuesday, 19 September 2017 at 18:17:47 UTC, jmh530 wrote:Javascript, C++, PHP, Perl and D. All have the same order of precedence except, as always the abomination of all languages: C++ (kill it with fire). C++ is the only language that has the ternary operator have the same precedence than the assignment operators. This means a>=5?b=100:b=200; will compile in C++ but not in all the other languages. That's one reason why it irritates me when people continuously refer to C and C++ as if it was the same thing (yes I mean you Walter and Andrei). Even PHP and Perl got it right, isn't that testament of poor taste Bjarne?. :-)On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote: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.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...
Sep 23 2017
On Saturday, 23 September 2017 at 20:43:36 UTC, Patrick Schluter wrote:Javascript, C++, PHP, Perl and D. All have the same order of precedence except, as always the abomination of all languages: C++ (kill it with fire). C++ is the only language that has the ternary operator have the same precedence than the assignment operators. This means a>=5?b=100:b=200; will compile in C++ but not in all the other languages. That's one reason why it irritates me when people continuously refer to C and C++ as if it was the same thing (yes I mean you Walter and Andrei). Even PHP and Perl got it right, isn't that testament of poor taste Bjarne?. :-)It's not quite as big of a deal as it seems because of the RTL associativity for both of them but still a very weird thing at face value.
Sep 26 2017
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!`()? :` 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.
Sep 19 2017
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: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.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!`()? :` 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.
Sep 19 2017
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.
Sep 19 2017
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.
Sep 19 2017
On Tuesday, 19 September 2017 at 20:00:40 UTC, Brad Anderson wrote: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.Changing the operator precedence would certainly lead to enormous breakage. Most use of the ternary operator is something like result = a > b ? x : y; and what he wants is to be forced to say result = (a + b) ? x : y; instead of result = a + b ? x : y; The problem is that addition/multiplication is above logical operators in the operator precedence. So if you were to do something like move conditional ternary above addition/multiplication, then you also move it above logical operators and you'd have to use result = (a > b) ? x : y; instead of result = a > b ? x : y; which kind of defeats the purpose.
Sep 19 2017
On Tuesday, 19 September 2017 at 19:16:05 UTC, EntangledQuanta wrote: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).jmh530 points out why you're met with such non-agreement of the issue. You're not open do discussion of why it is implemented in the fashion it is. Instead it is an attack on the community and Walter as though there is no logical reason it is implemented in the way that it is. Sure you can express that it is illogical to have made that choice, but that requires first know what used to make that decision. For example one of the original principles for D was: If it looks like C it should have the same semantics or be a compiler error (note this was not completely achieved) Now if we look at other languages we see, they implement it the same as C or they don't implement it at all. Just based on this it would make sense to choose to implement it like C if it is desired to have. The suggestion I made fulfills this, but it also slightly defeats one purpose of the operator, being terse. We also now need to keep backwards compatibility, this fails.
Sep 19 2017
On Tuesday, 19 September 2017 at 22:11:44 UTC, Jesse Phillips wrote:On Tuesday, 19 September 2017 at 19:16:05 UTC, EntangledQuanta wrote:I'm not open to discussion because it is not a discussion. There is no point. What could would it do to explain the short commings? You see the responses, the mentality. People think doing something wrong is valid because it was done. Two wrongs don't make a right no matter how you justify it. When someone takes on the task of doing a job and pretends the results to a community then refuse to accept responsibility for the failure to do the job properly and perpetuate ignorance(invalid logic that creates confusing, wastes peoples times, etc) then they deserve to be criticized, it's a two way street. When they then make up excuses to try to justify the wrong and turn it in to a right, they deserved to be attacked. It not just a harmless mistake. Peoples lives could be a jeopardy, but do they care? Do they REALLY care? Of course not. They don't see it as a significant issue. Simply learn how D works exactly and you'll be fine! Of course, for someone that programs in about 20 different languages regularly, having logical consistency is important. It's one thing to say "Well, I made a mistake, lets try to remedy it the best we can" than to say "Well, too bad, we can't break backwards compatibility!". People want to perpetuate insanity(which is what being illogical is).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).jmh530 points out why you're met with such non-agreement of the issue. You're not open do discussion of why it is implemented in the fashion it is. Instead it is an attack on the community and Walter as though there is no logical reason it is implemented in the way that it is.Sure you can express that it is illogical to have made that choice, but that requires first know what used to make that decision.No, it doesn't logic is not based on circumstances, it's based on something that is completely independent of us... which is why it is called logic... because it is something we can all agree on regardless of our circumstances or environment... it is what math and hence all science is based on and is the only real thing that has made steady progress in the world. Illogic is what all the insanity is based on... what wars are from, and just about everything else, when you actually spend the time to think about it, which most people don't.For example one of the original principles for D was: If it looks like C it should have the same semantics or be a compiler error (note this was not completely achieved) Now if we look at other languages we see, they implement it the same as C or they don't implement it at all. Just based on this it would make sense to choose to implement it like C if it is desired to have. The suggestion I made fulfills this, but it also slightly defeats one purpose of the operator, being terse. We also now need to keep backwards compatibility, this fails.Again, two wrongs don't make a right. What is the point of reimplementing C exactly as C is done? There is already a C, why have two? Was the whole point of D not to improve upon C? Doesn't D claim to be a "better C"? So, if you are claiming that the choice for the ternary operator's issue of ambiguity was to be consistent with C then that directly contradicts the statements that D is suppose to be safer and better. I'm fine with this AS long as it is clearly stated as such and people don't try to justify or pretend that it is a good thing, which is exactly the opposite of what they. Most are followers of the cult and cannot make any rational decision on their own but simply parrot the elders. So, when they do that, I have no desire or reason to be logical with them(again, it takes two to tango). For example, you have been rational, so I will be rational with you. To be rational, you must argue logically which you have done. Even though you haven't really argued the issue(of course, I didn't state it clear on purpose because this isn't really a discussion thread... I knew that the trolls/cult members would spew there stupid shit so I was just trolling them. Of course, I always hope that there would be some light in the tunnel, which you provided a glimmer... still all meaningless, nothing will change, at least not with the cult members, but someone that is not so brainwashed might be semi-enlightened if they implement their own language and not make the same mistakes). e.g., my attack is on the claims that D attempts to be *safe* and a *better C* and yet this(the ternary if) is just another instance of them contradicting themselves. Presenting something as safer when it is not gives the perception of safety and can actually be more dangerous than the original.
Sep 19 2017
On Wednesday, 20 September 2017 at 02:34:50 UTC, EntangledQuanta wrote:When they then make up excuses to try to justify the wrong and turn it in to a right, they deserved to be attacked.That isn't how it went down, you attacked then justification was provided.for someone that programs in about 20 different languages regularly, having logical consistency is important.Could you imagine if D didn't allow you to learn how ternary is implemented? when you switched to one of those 19 other languages you'd expect it to work like D and make that catastrophic life threatening mistake you speak of. But at last D followed logical consistency across languages so you can make the mistake once, learn, and apply it to all the other environments you're using.No, it doesn't logic is not based on circumstances, it's based on something that is completely independent of us... which is why it is called logic... because it is something we can all agree on regardless of our circumstances or environment... it is what math and hence all science is based on and is the only real thing that has made steady progress in the world. Illogic is what all the insanity is based on... what wars are from, and just about everything else, when you actually spend the time to think about it, which most people don't.I will claim that it is illogical to make decisions ignoring environment and circumstances. For example, science heavily leverages environment (e.g. all objects fall at the same rate; environment: vacuum) (e.g. matter can neither be created nor destroyed; environment: not within a atomic explosion) (e.g. ...; environment: anything not quantum mechanics) (e.g. this satellite will follow this trajectory; environment: forces acting upon the satellite)Again, two wrongs don't make a right. What is the point of reimplementing C exactly as C is done?I don't think there were any unjust or dishonest actions being done. Just an FYI the phrase isn't intended to be applied to all meanings of 'wrong'. you are reading D code you will understanding the semantics and the semantics will remain the same if you copy code from your language into D.e.g., my attack is on the claims that D attempts to be *safe* and a *better C* and yet this(the ternary if) is just another instance of them contradicting themselves. Presenting something as safer when it is not gives the perception of safety and can actually be more dangerous than the original.Safe to Walter has always been 'memory safe' but to you point of broader safety lets take my ()?: syntax and breaking backwards compatibility here is unsafe. q > a / (3 + 4) ? 0 : q; This compiles today, it will also compile with the new syntax; the semantics would be completely different. This is a calculation running in production for a space shuttle to Mars. Before the launch they upgrade the compiler and this new calculation causes the shuttle to land in Florida off the coast of Minneapolis. Backwards compatibility is important to safety just as following the majority. To ignore the environment you're working is illogical.
Sep 20 2017
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
Sep 19 2017
On Tuesday, 19 September 2017 at 19:54:02 UTC, Steven Schveighoffer wrote:On 9/19/17 1:40 PM, EntangledQuanta wrote:The best answer. :DThe 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
Sep 20 2017
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!Yeah, it sucks to have bugs like this crop up. I have enough trouble remembering operator precedence, so I end up using parentheses everywhere and pretending the ternary operator doesn't exist. I also tend to break up complex expressions a lot. It's just safer, and usually clearer.
Sep 19 2017
On 19/09/2017 9:22 PM, Neia Neutuladh wrote:On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote:Agreed, no surprises is the best surprise!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!Yeah, it sucks to have bugs like this crop up. I have enough trouble remembering operator precedence, so I end up using parentheses everywhere and pretending the ternary operator doesn't exist. I also tend to break up complex expressions a lot. It's just safer, and usually clearer.
Sep 19 2017
On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote: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 ?.There are two issues there; operator precedence and booleans (_win[0] == ' ') being a valid operands to +. If someone is too stupid to learn how precedence works, they should consider a different career instead of blaming others. OTOH, booleans converting to numbers is a very questionable feature. I certainly have never seen any good use for it. This is just an unfortunate legacy of C, which didn't even have booleans for a long time.
Sep 19 2017
On Tuesday, 19 September 2017 at 21:17:53 UTC, nkm1 wrote:On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote:Your an idiot, I know about how operator precedence works far more than you do. Wanna bet? how much? Your house? your wife? Your life? It's about doing things correctly, you seem to fail to understand, not your fault, can't expect a turd to understand logic.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 ?.There are two issues there; operator precedence and booleans (_win[0] == ' ') being a valid operands to +. If someone is too stupid to learn how precedence works, they should consider a different career instead of blaming others. OTOH, booleans converting to numbers is a very questionable feature. I certainly have never seen any good use for it. This is just an unfortunate legacy of C, which didn't even have booleans for a long time.
Sep 19 2017
On Wednesday, September 20, 2017 02:16:16 EntangledQuanta via Digitalmars-d- learn wrote:On Tuesday, 19 September 2017 at 21:17:53 UTC, nkm1 wrote:Please try to be civil. It's fine if you're unhappy about some aspect of how D works and want to discuss it, but we do not condone personal attacks here. - Jonathan M DavisOn Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote:Your an idiot, I know about how operator precedence works far more than you do. Wanna bet? how much? Your house? your wife? Your life? It's about doing things correctly, you seem to fail to understand, not your fault, can't expect a turd to understand logic.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 ?.There are two issues there; operator precedence and booleans (_win[0] == ' ') being a valid operands to +. If someone is too stupid to learn how precedence works, they should consider a different career instead of blaming others. OTOH, booleans converting to numbers is a very questionable feature. I certainly have never seen any good use for it. This is just an unfortunate legacy of C, which didn't even have booleans for a long time.
Sep 19 2017
On Wednesday, 20 September 2017 at 02:36:50 UTC, Jonathan M Davis wrote:Please try to be civil. It's fine if you're unhappy about some aspect of how D works and want to discuss it, but we do not condone personal attacks here. - Jonathan M DavisHe seemed to be threatening the guy's life over operator precedence. Ridiculous...
Sep 19 2017
On Wednesday, 20 September 2017 at 02:57:21 UTC, jmh530 wrote:On Wednesday, 20 September 2017 at 02:36:50 UTC, Jonathan M Davis wrote:Are you an idiot? Seriously, you must be. You just want to create drama instead of supply an actual logical argument(which I read your argument and it is pathetic). Show me where I threatened the guys life! Fucking moron. You must be some TSA goon or DHS wannabe.Please try to be civil. It's fine if you're unhappy about some aspect of how D works and want to discuss it, but we do not condone personal attacks here. - Jonathan M DavisHe seemed to be threatening the guy's life over operator precedence. Ridiculous...
Sep 19 2017
On Wednesday, 20 September 2017 at 02:36:50 UTC, Jonathan M Davis wrote:On Wednesday, September 20, 2017 02:16:16 EntangledQuanta via Digitalmars-d- learn wrote:But, of course, It's ok for him to come me an idiot. Let me quote, not that it matters, since you are biased and a hypocrite: ">> > If someone is too stupid to learn how precedence works, theyOn Tuesday, 19 September 2017 at 21:17:53 UTC, nkm1 wrote:Please try to be civil. It's fine if you're unhappy about some aspect of how D works and want to discuss it, but we do not condone personal attacks here. - Jonathan M DavisOn Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta wrote:Your an idiot, I know about how operator precedence works far more than you do. Wanna bet? how much? Your house? your wife? Your life? It's about doing things correctly, you seem to fail to understand, not your fault, can't expect a turd to understand logic.[...]There are two issues there; operator precedence and booleans (_win[0] == ' ') being a valid operands to +. If someone is too stupid to learn how precedence works, they should consider a different career instead of blaming others. OTOH, booleans converting to numbers is a very questionable feature. I certainly have never seen any good use for it. This is just an unfortunate legacy of C, which didn't even have booleans for a long time.But when I call him an idiot, I'm put in the corner. I see how it works around here. What a cult!should consider a different career instead of blaming others."
Sep 19 2017
On Wednesday, 20 September 2017 at 02:16:16 UTC, EntangledQuanta wrote:Your an idiot, I know about how operator precedence works far more than you do. Wanna bet? how much? Your house? your wife? Your life? It's about doing things correctly, you seem to fail to understand, not your fault, can't expect a turd to understand logic.You should swallow your ego a bit. In first place you've made an error. Just recognize this error, it's not so serious finally. You are discrediting yourself for nothing.
Sep 19 2017
On Wednesday, 20 September 2017 at 02:16:16 UTC, EntangledQuanta wrote:Your an idiot, I know about how operator precedence works far more than you do. Wanna bet? how much? Your house? your wife? Your life? It's about doing things correctly, you seem to fail to understand, not your fault, can't expect a turd to understand logic.Ok, you win. I see now that you're very smart :)
Sep 19 2017
A general rule of thumb when it comes to operator precedence is that when in doubt, add parenthesis. On Wednesday, 20 September 2017 at 02:16:16 UTC, EntangledQuanta wrote:Your an idiot, YourHuh.
Sep 20 2017
On 19.09.2017 23:17, nkm1 wrote:... OTOH, booleans converting to numbers is a very questionable feature. > I certainly have never seen any good use for it. ...Actually, it is useful enough to have a Wikipedia page: https://en.wikipedia.org/wiki/Iverson_bracket Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { if (a<0 || a >= data.length) return; if (b<0 || b >= data[a].length) return; if (data[a][b] == c) return; data[a][b] = c; foreach(i; 0 .. 4){ dfs(a + (i==0) - (i==1), b + (i==2) - (i==3)); } } dfs(i, j); } unittest { import std.algorithm, std.conv, std.array; .map!(to!(dchar[])).array; }
Sep 20 2017
On Wednesday, 20 September 2017 at 19:25:58 UTC, Timon Gehr wrote:On 19.09.2017 23:17, nkm1 wrote:While it's also possible to do this with filter, this is what I'd probably most often use it for. import std.algorithm : sum; void main() { bool[] x = [true, false, true]; int[] y = [1, 2, 3]; y[] = x[] * y[]; assert(sum(y[]) == 4); } It would be nice to be able to do: assert(sum(x[] * y[]) == 4);... OTOH, booleans converting to numbers is a very questionable feature. > I certainly have never seen any good use for it. ...Actually, it is useful enough to have a Wikipedia page: https://en.wikipedia.org/wiki/Iverson_bracket [snip]
Sep 20 2017
On Wednesday, 20 September 2017 at 19:25:58 UTC, Timon Gehr wrote:Actually, it is useful enough to have a Wikipedia page: https://en.wikipedia.org/wiki/Iverson_bracketMmmm... "The notation was originally introduced by Kenneth E. Iverson in his programming language APL". APL... yeah :) Programmers didn't like it, did they. Anyway, that seems to be explicit notation, analogous to (cond ? 1 : 0).Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { if (a<0 || a >= data.length) return; if (b<0 || b >= data[a].length) return; if (data[a][b] == c) return; data[a][b] = c; foreach(i; 0 .. 4){ dfs(a + (i==0) - (i==1), b + (i==2) - (i==3)); } } dfs(i, j); }I don't agree it's a good use. Actually, that seems quite obfuscated to me. Consider: foreach (point; [[1, 0], [-1, 0], [0, 1], [0, -1]]) { dfs(a + point[0], b + point[1]); } Finds some random 10 programmers and ask them what's easier to understand... Also, in my experience (in C and C++) it is extremely rare for programmers to use booleans in arithmetic. So even if in some situation you would have to replace this thing with more verbose (i == 0 ? 1 : 0), it's no big deal. OTOH, booleans being numbers is a source of some bugs (just like other cases of weak typing). Not a ton of bugs, but the utility of implicit conversion to numbers is so unnoticeable that I'm sure it's just not worth it.
Sep 20 2017
On Wednesday, September 20, 2017 21:13:58 nkm1 via Digitalmars-d-learn wrote:OTOH, booleans being numbers is a source of some bugs (just like other cases of weak typing). Not a ton of bugs, but the utility of implicit conversion to numbers is so unnoticeable that I'm sure it's just not worth it.I think that most of us would agree with you, but the last time it was serious discussed, Walter couldn't be convinced. Based on more recent discussions with him, he did seem to now agree that we're probably too liberal with how many implicit conversions we allow, but I don't know which ones specifically he'd be willing to do differently if we didn't care about breaking code. But since breaking code would definitely be a problem with any implicit conversion that was removed, I doubt that it would be easy to talk him into making any changes to the implicit conversions now even if you could get him to agree that we ideally would. - Jonathan M Davis
Sep 20 2017
On 20.09.2017 23:13, nkm1 wrote:Well, you can trust me that it is. ;)Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { if (a<0 || a >= data.length) return; if (b<0 || b >= data[a].length) return; if (data[a][b] == c) return; data[a][b] = c; foreach(i; 0 .. 4){ dfs(a + (i==0) - (i==1), b + (i==2) - (i==3)); } } dfs(i, j); }I don't agree it's a good use.Actually, that seems quite obfuscated to me.It's actually straightforward. This C code is obfuscated: #define C , #define S(X) "Fizz"X"Buzz" int main(){ char j[]="00",*k=j+1,*g[]={k,S(C),S()}; while(':'-*j) ++*k>'9'&&++*j&&(1<:*g=j:>='0'), puts(g[!((*j+*k)%3)|2*(3==*k%5)]); return 0; } (And yet, you are probably able to guess what it does.)Consider:(I had considered that.)foreach (point; [[1, 0], [-1, 0], [0, 1], [0, -1]]) { dfs(a + point[0], b + point[1]); }void floodFill(dchar[][] data,dchar c,int i,int j) nogc { I.e., I'd possibly call this a bad use of array literals. ;) (The fix is to initialize a static array of static arrays.) Also, it's not really a point, rather, it's a delta.Finds some random 10 programmers and ask them what's easier to understand...Personally, I think it is a tie as both are obvious.Also, in my experience (in C and C++) it is extremely rare for programmers to use booleans in arithmetic. So even if in some situation you would have to replace this thing with more verbose (i == 0 ? 1 : 0), it's no big deal.I didn't say it was.OTOH, booleans being numbers is a source of some bugs (just like other cases of weak typing). Not a ton of bugs, but the utility of implicit conversion to numbers is so unnoticeable that I'm sure it's just not worth it.So am I, but I wasn't commenting on trade-offs, only the view that there are no good uses.
Sep 21 2017
On 9/21/17 11:06 AM, Timon Gehr wrote:...foreach(i; 0 .. 4){ dfs(a + (i==0) - (i==1), b + (i==2) - (i==3)); }So am I, but I wasn't commenting on trade-offs, only the view that there are no good uses.This seems way easier for me to grok, and is how I would write it. dfs(a + 1, 0); dfs(a - 1, 0); dfs(0, b + 1); dfs(0, b - 1); -Steve
Sep 21 2017
On 9/21/17 11:48 AM, Steven Schveighoffer wrote:On 9/21/17 11:06 AM, Timon Gehr wrote:Of course, without bugs :) dfs(a + 1, b); dfs(a - 1, b); dfs(a, b + 1); dfs(a, b - 1); -Steve....foreach(i; 0 .. 4){ dfs(a + (i==0) - (i==1), b + (i==2) - (i==3)); }So am I, but I wasn't commenting on trade-offs, only the view that there are no good uses.This seems way easier for me to grok, and is how I would write it. dfs(a + 1, 0); dfs(a - 1, 0); dfs(0, b + 1); dfs(0, b - 1);
Sep 21 2017
On 21.09.2017 17:53, Steven Schveighoffer wrote:On 9/21/17 11:48 AM, Steven Schveighoffer wrote:It was the same bug in every copy. Impressive! ;)On 9/21/17 11:06 AM, Timon Gehr wrote:Of course, without bugs :) .......foreach(i; 0 .. 4){ dfs(a + (i==0) - (i==1), b + (i==2) - (i==3)); }So am I, but I wasn't commenting on trade-offs, only the view that there are no good uses.This seems way easier for me to grok, and is how I would write it. dfs(a + 1, 0); dfs(a - 1, 0); dfs(0, b + 1); dfs(0, b - 1);dfs(a + 1, b); dfs(a - 1, b); dfs(a, b + 1); dfs(a, b - 1); -SteveThis is a good alternative, maybe arrange it like this: dfs(a + 1, b); dfs(a, b + 1); dfs(a - 1, b); dfs(a, b - 1); Just need to make sure no code is duplicated. (For example, there could be more work to do in each loop iteration, and then you'd need to use a local function.)
Sep 21 2017
On 9/21/17 3:24 PM, Timon Gehr wrote:This is a good alternative, maybe arrange it like this: dfs(a + 1, b); dfs(a, b + 1); dfs(a - 1, b); dfs(a, b - 1);Yes, better!Just need to make sure no code is duplicated. (For example, there could be more work to do in each loop iteration, and then you'd need to use a local function.)Hm... I suppose you would do that work at the beginning of dfs, like you check the limits? -Steve
Sep 21 2017
On Wednesday, 20 September 2017 at 19:25:58 UTC, Timon Gehr wrote:Actually, it is useful enough to have a Wikipedia page: https://en.wikipedia.org/wiki/Iverson_bracket Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { if (a<0 || a >= data.length) return; if (b<0 || b >= data[a].length) return; if (data[a][b] == c) return; data[a][b] = c; foreach(i; 0 .. 4){ dfs(a + (i==0) - (i==1), b + (i==2) - (i==3)); } } dfs(i, j); }I would rather use an explicit function for such use cases: int delta(bool x) { return x == true ? 1 : 0; }
Sep 21 2017
On 2017/09/19 19:40, 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.When you get too angry about the little things in life. "There are people dying in the world and this angers you, chill".
Oct 04 2017