-
Consider adding a new operator keyword "isnt" or "isnot" which acts as the converse of "is". "is" is used like this:
coding the converse must be done currently like this:
whereas this is much easier on the eye:
|
Beta Was this translation helpful? Give feedback.
Replies: 83 comments
-
I see this isnt the place to submit feature requests, clsoing this. |
Beta Was this translation helpful? Give feedback.
-
@Korporal This is now the place to open discussion on feature requests, so you can reopen this if you want. |
Beta Was this translation helpful? Give feedback.
-
As suggested, I'm reopening this. |
Beta Was this translation helpful? Give feedback.
-
I like |
Beta Was this translation helpful? Give feedback.
-
Exactly, if the designers felt is necessary to add "is" supporting its converse seems like a natural step. |
Beta Was this translation helpful? Give feedback.
-
I would like And I would against Please don't add more keyword |
Beta Was this translation helpful? Give feedback.
-
It's really cringe inducing watching Mads' video on C# 7.0 and seeing Unrelated- |
Beta Was this translation helpful? Give feedback.
-
Related- Negetive pattern by @alrz |
Beta Was this translation helpful? Give feedback.
-
@Thaina: |
Beta Was this translation helpful? Give feedback.
-
@phi1010 In my case I was differentiate between
What I propose is not to separate In many language they add operator by combine multiple symbol without space. Such as javascript Unlike what you try to do |
Beta Was this translation helpful? Give feedback.
-
Whitespace is an awful delineation of syntax. Not everyone programs using monospace fonts or with whitespace glyphs enabled. |
Beta Was this translation helpful? Give feedback.
-
@HaloFour I agree with you but the root cause itself came from Hejlsberg himself to select I always feel wrong that we have word as operator instead of symbol. But now it's too late to argue about that But in the same sense. While we cannot write |
Beta Was this translation helpful? Give feedback.
-
What is the relationship to #246 ? |
Beta Was this translation helpful? Give feedback.
-
@Thaina: The way the language is currently structured, I expect to be able to insert additional spaces at any position between two lexical tokens (literals, operators made of special characters, and words such as keywords, variables, method names, etc.). It is somewhat obvious that it is not a good idea to separate |
Beta Was this translation helpful? Give feedback.
-
@mattwar |
Beta Was this translation helpful? Give feedback.
-
@lachbaer you cannot use the variables in the code if they are never definitely assigned. |
Beta Was this translation helpful? Give feedback.
-
Well, there are two possibilities. 1st, ignore the identifiers completely ; 2nd assign the default value in case of a (negative) match. Btw, what happens with the variables of a standard pattern when there is no match and the scope is the enclosing block? |
Beta Was this translation helpful? Give feedback.
-
@mattwar I think the intent is that the negated pattern is precisely the negation of the normal pattern, so that for the expression |
Beta Was this translation helpful? Give feedback.
-
@gafter you are right. My mind was boggled by the negation and I couldn't think clearly. |
Beta Was this translation helpful? Give feedback.
-
Assigned to default values or assigned to the same values as if The latter makes a bit more sense to me, because that way |
Beta Was this translation helpful? Give feedback.
-
Here's a list of possible usages of 1. if, while:if not(xxx){}
while not(xxx){}
do {} while not(xxx); There are many discussions of this feature:
Basically I vote for HaloFour's opinion in #568, allowing negation prefix operator 2. is:if (a is not xxx){} //-> if not(a is xxx){}, same to `while`
var notok = a is not xxx; Actually as you can see, 3. switch:switch (obj) {
case Euro(var amount): [...]
case USDollar(var amount): [...]
case not LocalCurrency: [...] // it's not Euro, nor USDollar, but is a currency: skip this block
case decimal: [...]
default: [...]
} This is useful when we want to filter a specific derived type among multiple ones. switch(creature) {
case Animal a when !(a is Cat): [...]
//with `not` we can write this:
case not Cat: [...]
} The use of switch(creature) {
case Animal a when !(a is Cat || a is Dog || a is Fish): [...]
//with `not`, some other enhancement must be done to filter multiple derived types:
case not Cat Dog Fish: [...]
//or
case not Cat, Dog, Fish: [...]
//or
case not Cat not Dog not Fish: [...]
//or
case not Cat nor Dog nor Fish: [...]
//or
case not Cat || Dog || Fish: [...]
//or
case not Cat | Dog | Fish: [...]
} Looks like the 1st or 2nd solution is most acceptable:
The difference between 1st and 2nd is, the using of comma makes code more intuitive to read. So, giving up support filter multiple derived types or make another enhancement, we have to face one. One more question of using switch(weekday) {
case DayOfWeek.Monday: [...]
case not DayOfWeek.Sunday, DayOfWeek.Saturday: [...] //workday besides monday goes here
} void foo(int number) {
switch(number) {
case 10: [...]
case int k when k > 20: [...] //I have words to say about this `int`... XD
case not 1, 3, 4: [...] // 2, 5-9, 11-20 goes here
default: [...] // 1, 3, 4 goes here
}
} 4. catch:try
{}
catch (AnimalException ex) not CatException
{}
//or, for filtering multiple derived Exception types:
catch (AnimalException ex) not CatException, DogException
{} In my opinion, There is a notable question is: the filtered Excetption types MUST be derived from which was caught. The compiler can make a check of this. Think about this: //Exception -> AnimalException -> CatException
//Exception -> ArgumentException -> ArgumentNullException
try
{}
catch (ArgumentException ex) not AnimalException
{}
catch (ArgumentException ex) not CatException
{} Since an Of course there is equivalent for now, using try
{}
catch (AnimalException ex) when (!(ex is CatException))
{}
catch (AnimalException ex) when (!(ex is CatException || ex is DogException))
{} 5. where (Generic type constraints):A new idea of static class MyExtensions
{
public static void AsSomething<T>(this IEnumerable<IEnumerable<T>> arg) { }
public static void AsSomething<T>(this IEnumerable<T> arg) { } where T : not IEnumerable<> // <-- use of not constraint
//or
public static void AsSomething<T>(this IEnumerable<T> arg) { } where T : !IEnumerable<> // <-- use of ! constraint
}
// Resolves to AsSomething<T>(this IEnumerable<IEnumerable<T>> arg)
new[] { new[] { 1 } }.AsSomething();
// Resolves to AsSomething<T>(this IEnumerable<T> arg) { } where T : IEnumerable<>
new[] { new { FirstName = "Joe", LastName = "Smith" } }.AsSomething(); |
Beta Was this translation helpful? Give feedback.
-
Hi @qaqz111 1, 2: Conditional operators and loops
3. Pattern matchingFor pattern matching it is confusing and not helping at all. object x = 1.0;
switch (x)
{
case int i: break;
case not double d: break;
case not string s: break;
default: break;
} For the 4. Exception filtersThere is no need to invent another syntax for exception filters. Existing syntax will work and look completely fine: catch (Exception ex) when (ex not OutOfMemoryException) 5. Generic type constraintsGeneric type constraints are helpful when you need to know how you can use a constrained object. How can this constraint help you use variable void Foo<T>(T obj) where T : not String |
Beta Was this translation helpful? Give feedback.
-
Why don't we just add do {} until like vb? it's much more understandable IMHO. do
{
// stuff
}while(!(someBoolExpr))
do
{
// stuff
}until(someBoolExpr) |
Beta Was this translation helpful? Give feedback.
-
There's already a propsal exploring: |
Beta Was this translation helpful? Give feedback.
-
Indeed, once again I refer to PL/I
But C# cannot undergo huge grammar changes at this point (no language could). |
Beta Was this translation helpful? Give feedback.
-
As mentioned above:
I've got a PR on an low-impact impl-strategy, and Aleksey is championing the feature. |
Beta Was this translation helpful? Give feedback.
-
@sleepyboyy your comment was in violation of our CoC and was deleted. Any such future violations will result in a ban. We value your interaction, as long as it is courteous and productive. If you'd like to discuss, you can contact us at [email protected] |
Beta Was this translation helpful? Give feedback.
-
This is a bit useful, but not very useful |
Beta Was this translation helpful? Give feedback.
-
As an extension to the pattern-matching constructs in C# 9.0, we are adding a See https://github.com/dotnet/csharplang/blob/master/proposals/patterns3.md |
Beta Was this translation helpful? Give feedback.
As an extension to the pattern-matching constructs in C# 9.0, we are adding a
not
pattern and a type pattern. As a result,is not
will act like a new operator as you request.See https://github.com/dotnet/csharplang/blob/master/proposals/patterns3.md