Feature: "!==" assign if not equals #3744
Replies: 21 comments
-
Why is this necessary? What value does this provide except to make code trivially shorter? Making code shorter is not generally considered a sufficient goal. |
Beta Was this translation helpful? Give feedback.
-
This would look far too similar to the JavaScript |
Beta Was this translation helpful? Give feedback.
-
From API consumer perspective I'd expect setting property to be idempotent and (regardless of initial value or how many times I assign it) the end effect to be exactly the same - setting property value and nothing else. If it sets value and does stuff it should be If you have some internal logic bound to property setter that requires this kind of check (like |
Beta Was this translation helpful? Give feedback.
-
@theunrepentantgeek Are you sure you follow C# lang development? :) |
Beta Was this translation helpful? Give feedback.
-
@MgSam I think the team may have rejected more ideas for making things shorter than the ideas they shipped. That would mean that the relevant factor wasn't length in isolation. |
Beta Was this translation helpful? Give feedback.
-
@jnm2 A substantial portion of language design notes is the team agonizing over how to shave off every possible character.
All that said I'm not in favor of this proposal as I think the use case is exceptionally narrow and the operator confusing for the reason Cyrus stated. |
Beta Was this translation helpful? Give feedback.
-
I don't think reducing boilerplate is the same thing as agonizing over shaving off characters. It's not about the characters, it's about the readability. If it was about minimizing characters, it would go too far and actually diminish readability. Most of the things you mention are reducing active areas of pain and annoyance. Character count is incidental. |
Beta Was this translation helpful? Give feedback.
-
You say tomato and I say tomahto. "Enhancing readability" vs "shaving off characters" seems like semantics to me. I'm sure a Perl developer would tell you its the most readable language in the world.
My point is only that the C# team the past several years is highly motivated by reducing characters at all costs and the decisions the LDM has made make this pretty clear. Whether this is a good or bad thing is for the larger C# community to decide. |
Beta Was this translation helpful? Give feedback.
-
This is not the case. Of your list, the only one that hits in terms of decision making was
The decisions were not made with the motivation of reducing characters at all costs. |
Beta Was this translation helpful? Give feedback.
-
I disagree. I don't think
This was added for clarity and consistency. We already had all the other associated binary operators have both forms. So this was just smoothed out this special case. This was also not about saving characters, but about not repeating yourself. i.e. the primary goal is to not have to write redundant stuff. It turns out that not writing redundant things tends to make it shorter. But that's a consequence of the original desire (reducing redundancy) not reducing characters. |
Beta Was this translation helpful? Give feedback.
-
Your position has changed in teh very same post. IT started with " agonizing over how to shave off every possible character." to "reducing boilerplate". These are not the same things. 'Boilerplate' is dealing with lots of repetition that masks the signal with too much noise. The goal is to expose signal and reduce noise. THat doesn't at all mean shaving off characters. Indeed, it may introduce more characters, just with the desire of making you repeat them a lot less. It's the repetition and frequency of these patterns (no pun intended) that are not addressed, not just a desire to remove characters at all cost, or to shave off everything that coudl be possible shaved off. If the latter was a goal we would have a very different language and we would approach all design very differently. |
Beta Was this translation helpful? Give feedback.
-
It isn't. We could shave off tons of characters if that were a goal. Many (most?) are unnecessary in C# from a strict language-design perspective. However, they serve a ton of purpose in terms of clarity and code structure. Even the |
Beta Was this translation helpful? Give feedback.
-
yes, !== in javascript is very confusion, but we can exactly define its behavior in c#. |
Beta Was this translation helpful? Give feedback.
-
In JavaScript the operator The proposed use in C# for That's very very different @Flithor and extremely likely to cause confusion as developers move between languages. I believe that's why @CyrusNajmabadi made their comment. |
Beta Was this translation helpful? Give feedback.
-
How about |
Beta Was this translation helpful? Give feedback.
-
@Flithor Differences between languages are okay. What is not okay is if you have two completely different features that use the same syntax in the same context. The only one of your examples that gets close is |
Beta Was this translation helpful? Give feedback.
-
It's not about exactly defining the behavior. It's that in one language is a binary comparison operator and I'm the other is an assignment operator. JS and TS are too well known and ubiquitous for me to take one of their operators but find it an entirely different meaning. We could certainly use it as a comparison operator of some sort. For example, it could be a short hand for 'reference equals'. However, making it a shorthand for assignment is not going to happen. |
Beta Was this translation helpful? Give feedback.
-
It's still has "comparer" feathre! but not only comparer! |
Beta Was this translation helpful? Give feedback.
-
I don't know what that means. |
Beta Was this translation helpful? Give feedback.
-
If it really bothers you, this has less characters.
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
OR
Tired to write:
Beta Was this translation helpful? Give feedback.
All reactions