If you could make breaking changes to C#, what would you do?
-
@another_sam said in If you could make breaking changes to C#, what would you do?:
@dkf said in If you could make breaking changes to C#, what would you do?:
The naïve implementation would have to test each RE in order I guess
Would the compiler warn you if two regexes could match the same input? It seems to me that a switch is really only appropriate for mutually exclusive cases, and it's obvious that there's no way for the compiler to know if two cases expressed as regexes are mutually exclusive.
That issue exists with the pattern-matching form of
switch
added in C# 7, and they solve it by applying an ordering to the cases (the firstcase
that matches is executed). Technically this is a breaking change, but actually has zero effect on the standard form ofswitch
statements, as that form still enforces the mutual exclusivity.
-
@another_sam said in If you could make breaking changes to C#, what would you do?:
Would the compiler warn you if two regexes could match the same input?
I wouldn't expect it to; that'd be very difficult to determine in general.
-
@another_sam said in If you could make breaking changes to C#, what would you do?:
That's exactly what enums are supposed to be. An exhaustive list of values. An enum you can extend isn't an enum at all.
So then you're saying C# doesn't have any enums? Because right now you can cast any value that's the same backing type to an enum.
public enum Blah : int { Value = 1 } public class Class1 { private readonly Blah myBlah = (Blah)0; }
Useful for types like
HttpStatusCode
, where codes like HTTP 418 exist that aren't defined in the framework enumeration.Since you can already throw in more values by explicit cast, I don't see why you shouldn't be able to inherit from enums to create more useful "handles" from within your code. Classes referencing the base enum already need to deal with explicit casts of values they don't know; these would behave the same as far as they're concerned.
public enum MyHttpStatusCode : HttpStatusCode { IAmATeapot = 418 } public class Class1 { private readonly HttpStatusCode teapotResult = MyHttpStatusCode.IAmATeapot; }
-
@unperverted-vixen said in If you could make breaking changes to C#, what would you do?:
codes like HTTP 418
-
@pleegwat said in If you could make breaking changes to C#, what would you do?:
What if ORANGE contains a single statement, currently commented out for debugging?
In our codebase, that will break the build. Not due to commented out code, but due to a combination of Warnings as Errors and SonarQube balking at all commented out code.
Also, TODO comments break the build, because fuck you.
-
@maciejasjmj said in If you could make breaking changes to C#, what would you do?:
Also, TODO comments break the build, because fuck you.
That seems a little mean. FIXME comments, yes, I can see them doing that, but a little TODO…?
-
@dkf said in If you could make breaking changes to C#, what would you do?:
@maciejasjmj said in If you could make breaking changes to C#, what would you do?:
Also, TODO comments break the build, because fuck you.
That seems a little mean. FIXME comments, yes, I can see them doing that, but a little TODO…?
It's a linter warning (since I don't think the linter can output anything other than warnings), and that gets converted to an error. I'd even agree that leaving TODOs in upstream code is a code smell, but it even breaks the build during development, so if you wanted to mark a class as "needs fixing here and there" and - say - run unit tests? Fuck you, better remember not to actually include the word "TODO" in your TODO comments.
-
I know one guy who used single letter
namespacespackage names (This was Java), e.g. 'T.h.i.s.i.s.m.y.n.a.m.e.s.p.a.c.e'He also made EVERYTHING private access and used reflection for everything, from creating instances to calling methods.
He flunked out of school as he never figured out why those things were a bad idea. I think the school is now using his code as an example of how NOT to do things.
-
- Remove the garbage collector and memory safety
- Remove exceptions
- Implicit conversions between enums and integers, void * and longs.
-
@wharrgarbl said in If you could make breaking changes to C#, what would you do?:
- Remove the garbage collector and memory safety
- Remove exceptions
- Implicit conversions between enums and integers, void * and longs.
"Breaking changes" doesn't mean "changes that leave the language broken when they're applied".
-
@maciejasjmj said in If you could make breaking changes to C#, what would you do?:
@wharrgarbl said in If you could make breaking changes to C#, what would you do?:
- Remove the garbage collector and memory safety
- Remove exceptions
- Implicit conversions between enums and integers, void * and longs.
"Breaking changes" doesn't mean "changes that leave the language broken when they're applied".
*cough* Project Jigsaw *cough*
-
@wharrgarbl said in If you could make breaking changes to C#, what would you do?:
- Remove the garbage collector and memory safety
- Remove exceptions
- Implicit conversions between enums and integers, void * and longs.
Any deleted data must be backed up to the cloud and shared before deletion.
Filed Under: I can too guys!
-
@maciejasjmj Ew. I much prefer our approach where we ignore warnings during the actual build, but have a unit test which verifies the build actually goes without warnings. And the debug build. And the
-O0
build, cause I've had people manage to break that separately.You still can't merge with warnings, cause of the one failing test. But you can do stuff locally, and verify things work.
-
@blakeyrat said in If you could make breaking changes to C#, what would you do?:
switch( peeps as all People ) // No idea what this syntax would look like
How about no extra syntax? The compiler already knows peeps is of type People, which is an enum.
-
@unperverted-vixen said in If you could make breaking changes to C#, what would you do?:
So then you're saying C# doesn't have any enums?
Yeah, pretty much. C# enums are as useful as a bunch of constant ints, which is not an enumeration at all. Like I said before, C/C++ programmers with no imagination.
Java got a lot of things wrong but Java's enums are pretty good.
-
@wharrgarbl said in If you could make breaking changes to C#, what would you do?:
Remove the garbage collector and memory safety
Remove exceptions
Implicit conversions between enums and integers, void * and longs.You're a weak-arse troll. If you want to write in C, just write in C.
-
@another_sam said in If you could make breaking changes to C#, what would you do?:
C# enums are as useful as a bunch of constant ints, which is not an enumeration at all.
-
@raceprouk said in If you could make breaking changes to C#, what would you do?:
You can add extension methods to enums.
That's... interesting. Not sure it's a good idea, but it's interesting. Now how about doing polymorphism with it?
-
@another_sam said in If you could make breaking changes to C#, what would you do?:
@raceprouk said in If you could make breaking changes to C#, what would you do?:
You can add extension methods to enums.
That's... interesting. Not sure it's a good idea, but it's interesting. Now how about doing polymorphism with it?
Can you suggest a good use case?
-
@raceprouk said in If you could make breaking changes to C#, what would you do?:
Can you suggest a good use case?
For polymorphism? Yes, many.
-
@another_sam said in If you could make breaking changes to C#, what would you do?:
@raceprouk said in If you could make breaking changes to C#, what would you do?:
Can you suggest a good use case?
For polymorphism? Yes, many.
Maybe you could post some?
-
@raceprouk said in If you could make breaking changes to C#, what would you do?:
Maybe you could post some?
I could but it's late and I need to get to bed. Have you heard of the strategy pattern?
-
@another_sam said in If you could make breaking changes to C#, what would you do?:
I could but it's late and I need to get to bed.
Then post in the morning
@another_sam said in If you could make breaking changes to C#, what would you do?:
Have you heard of the strategy pattern?
Probably, but I'd have to look it up to be sure.
-
@dkf said in If you could make breaking changes to C#, what would you do?:
Wild ideas time: extend
switch
to allow it to be able to use regular expressions to match strings, as opposed to just literals as at the moment. I'm not sure how the syntax would look :) but maybe like this spitballed mess:switch (theString) using regexps { case /abc.*def/: DoSomething(); break; case /ghi(.{3,5})jkl/ -> (match, submatch): // capturing the sub-expression DoSomethingElse(submatch); break; }
The naïve implementation would have to test each RE in order I guess — someone smart might be able to make a cleverer way in some cases — but it's the sort of thing that would make quite a lot of parsing tasks much less annoying.
switch { case regexp.MustCompile(`abc.*def`).MatchString(theString): DoSomething() case regexp.MustCompile(`ghi(.{3,5})jkl`).MatchString(theString): DoSomethingElse(regexp.MustCompile(`ghi(.{3,5})jkl`).FindStringSubmatch(theString)[1]) }
Or if you don't want to be horribly inefficient:
// Somewhere in the global scope var abcdef = regexp.MustCompile(`abc.*def`) var ghijkl = regexp.MustCompile(`ghi(.{3,5})jkl`) // In the function if abcdef.MatchString(theString) { DoSomething() } else if match := ghijkl.FindStringSubmatch(theString); match != nil { DoSomethingElse(match[1]) }
-
@ben_lubar For fuck's sake, Ben,
C#
is in the title of the thread.
-
@heterodox said in If you could make breaking changes to C#, what would you do?:
@ben_lubar For fuck's sake, Ben,
C#
is in the title of the thread.I'm just pointing out that everyone is suggesting features from Go be added to C#.
-
@ben_lubar said in If you could make breaking changes to C#, what would you do?:
I'm just pointing out that everyone is suggesting features from Go be added to C#.
No. Nobody's suggesting those, because none of us know Go. Nobody here likes Go, except when used in the phrase "Go away Ben Lubar."
Seriously though, nobody's going to say "Go doesn't have any good ideas in it" because that's ridiculous. The problem is: Go also has a lot of really shitty ideas in it.
That's the bit we have trouble with. C# might not be pushing enough envelopes to make you happy, but it also doesn't have anything that's just really shitty and stupid. Go has at least a couple of those, despite having an opportunity to learn from C#.
EDIT: wait you're a liar anyway. The clarification of when Exceptions clear their stack track can't possibly be in Go because Go doesn't have exceptions. Pfft.
-
@blakeyrat said in If you could make breaking changes to C#, what would you do?:
@ben_lubar said in If you could make breaking changes to C#, what would you do?:
I'm just pointing out that everyone is suggesting features from Go be added to C#.
No. Nobody's suggesting those, because none of us know Go. Nobody here likes Go, except when used in the phrase "Go away Ben Lubar."
Seriously though, nobody's going to say "Go doesn't have any good ideas in it" because that's ridiculous. The problem is: Go also has a lot of really shitty ideas in it.
That's the bit we have trouble with. C# might not be pushing enough envelopes to make you happy, but it also doesn't have anything that's just really shitty and stupid. Go has at least a couple of those, despite having an opportunity to learn from C#.
EDIT: wait you're a liar anyway. The clarification of when Exceptions clear their stack track can't possibly be in Go because Go doesn't have exceptions. Pfft.
Go has the benefit of its equivalent of
catch
running inside the stack of whatever threw the exception:
-
@ben_lubar said in If you could make breaking changes to C#, what would you do?:
Go has the benefit of its equivalent
Is that like British English or something? WTF.
@ben_lubar said in If you could make breaking changes to C#, what would you do?:
catch running inside the stack of whatever threw the exception:
So it does have Exceptions? If so your code sample certainly doesn't demonstrate any.
-
@blakeyrat Also why the fuck did you bait me into talking about Go? Fuck you. Talk about C#.
-
@blakeyrat said in If you could make breaking changes to C#, what would you do?:
If so your code sample certainly doesn't demonstrate any.
Do I need to make it a named type?
-
@ben_lubar No, you need to stop using Go.
-
@zecc said in If you could make breaking changes to C#, what would you do?:
@blakeyrat said in If you could make breaking changes to C#, what would you do?:
switch( peeps as all People ) // No idea what this syntax would look like
How about no extra syntax? The compiler already knows peeps is of type People, which is an enum.
No, because the current behavior of allowing inexhaustive switches is also good. We need something. Maybe just a symbol like *.
-
@pie_flavor said in If you could make breaking changes to C#, what would you do?:
@zecc said in If you could make breaking changes to C#, what would you do?:
@blakeyrat said in If you could make breaking changes to C#, what would you do?:
switch( peeps as all People ) // No idea what this syntax would look like
How about no extra syntax? The compiler already knows peeps is of type People, which is an enum.
No, because the current behavior of allowing inexhaustive switches is also good. We need something. Maybe just a symbol like *.
switch on all (peeps)
?
-
@dreikin if that were the
turn
keyword instead ofswitch
, that'd be right up @Perverted_Vixen 's alley ()
-
@pie_flavor said in If you could make breaking changes to C#, what would you do?:
No, because the current behavior of allowing inexhaustive switches is also good. We need something. Maybe just a symbol like *.
You can add an empty default branch.
If you already have a non-empty default branch, then it's either already doing what you want done in the new "non-exhausted" cases, or it isn't and you need to add new empty branches for these cases anyway.
Or... I'm posting late at night, missing something, and will regret this tomorrow.
-
@zecc said in If you could make breaking changes to C#, what would you do?:
@pie_flavor said in If you could make breaking changes to C#, what would you do?:
No, because the current behavior of allowing inexhaustive switches is also good. We need something. Maybe just a symbol like *.
You can add an empty default branch.
If you already have a non-empty default branch, then it's either already doing what you want done in the new "non-exhausted" cases, or it isn't and you need to add new empty branches for these cases anyway.
Or... I'm posting late at night, missing something, and will regret this tomorrow.Why should I have to type
case _: break;
no matter what? This isn't Rust. Safety should be the extra work, not unsafety.
-
Not exactly about breaking changes, but since we're talking about new feature we want to add to C#, I'd like to bring the rant in my comment here to attention.
I sincerely hope that when the language team decides what to be added in the future version, take a more serious look on how it'll impact the readability of code and don't just add them based on "some other language have it" basis.
"Efficiency to type" is rarely a bottleneck to development speed because after all, we need to think before we type. On the other hand, lacking "efficiency to read" will cause all kinds of maintainability problem, make beginners difficult to pick up the language, and make the code more error prone.
-
@cheong If you're using
string interpolationformatted strings and your code is less readable, then don't usestring interpolationformatted strings. Instead, use a more suitable tool, likeStringBuilder
.
-
@raceprouk String interpolation is neat, but can be horribly over-used. Making a message to print to the logger with some variables simply inserted? Fine. Making an XML document or SQL query with complex substitutions? NOPEnopenope!
-
@cheong I love formatted strings and use them all the time in C#. If you overuse them (as in your example), sure, they're pretty shit. Use all things in moderation. Readability seems more like your problem than the language's. If your use of a new feature will make your code unreadable, you're probably not exploring the right use case.
-
@dkf said in If you could make breaking changes to C#, what would you do?:
Making an XML document
XDocument
, orXmlDocument
if you're a traditionalist.@dkf said in If you could make breaking changes to C#, what would you do?:
SQL query with complex substitutions
Ooh, spoilt for choice here, but ultimately, it's either LINQ to SQL, or
DbCommand
.
-
@raceprouk said in If you could make breaking changes to C#, what would you do?:
@cheong If you're using
string interpolationformatted strings and your code is less readable, then don't usestring interpolationformatted strings. Instead, use a more suitable tool, likeStringBuilder
.But with code written by others, when you need to modify it, suggestion an alternative way don't help a lot.
Much like the situation when you're given some code to debug, you found the offending part is complex RegEx string, and you can't even figure out what the RegEx is supposed to match for.
-
@cheong said in If you could make breaking changes to C#, what would you do?:
But with code written by others, when you need to modify it, suggestion an alternative way don't help a lot.
Nothing's stopping you rewriting the original code. Sometimes that's necessary.
@cheong said in If you could make breaking changes to C#, what would you do?:
Much like the situation when you're given some code to debug, you found the offending part is complex RegEx string, and you can't even figure out what the RegEx is supposed to match for.
Then find out the original requirements, and write new code that matches them.
-
@raceprouk said in If you could make breaking changes to C#, what would you do?:
@cheong said in If you could make breaking changes to C#, what would you do?:
But with code written by others, when you need to modify it, suggestion an alternative way don't help a lot.
Nothing's stopping you rewriting the original code. Sometimes that's necessary.
Meh... that depends on how your team works.
Some people think "learning the language" is the responsibility of developers. "Not able to read it" is not valid reason to rewrite the code. And btw, not able to read them correctly also mean you're not qualified to rewrite it because you have no way to guarantee the new version of code is functionally identical to the previous version.
@cheong said in If you could make breaking changes to C#, what would you do?:
Much like the situation when you're given some code to debug, you found the offending part is complex RegEx string, and you can't even figure out what the RegEx is supposed to match for.
Then find out the original requirements, and write new code that matches them.
Be able to find the original requirement of code is such a rare luxury, that except for new projects, none of the companies I've worked for so far have it.
-
@cheong said in If you could make breaking changes to C#, what would you do?:
Some people think "learning the language" is the responsibility of developers.
It is, otherwise how are those developers going to do their jobs?
@cheong said in If you could make breaking changes to C#, what would you do?:
"Not able to read it" is not valid reason to rewrite the code.
Are you kidding me? That's one of the best reasons to rewrite code!
-
@raceprouk said in If you could make breaking changes to C#, what would you do?:
Are you kidding me? That's one of the best reasons to rewrite code!
If you genuinely can't work out what it's doing then it's super hard to rewrite it and be sure you've caught all the edge cases. Clearly, in an ideal world you'd have unit tests to help verify, and enough time to do it properly. In the real world, the unclear code is usually just a distraction on the way to finding the real issue you're trying to fix, and you're already a day behind on your estimate so stopping to refactor something peripherally related isn't a priority
-
@raceprouk said in If you could make breaking changes to C#, what would you do?:
@cheong said in If you could make breaking changes to C#, what would you do?:
Some people think "learning the language" is the responsibility of developers.
It is, otherwise how are those developers going to do their jobs?
So the learning curve of the language becomes much steeper than it should have been.
@cheong said in If you could make breaking changes to C#, what would you do?:
"Not able to read it" is not valid reason to rewrite the code.
Are you kidding me? That's one of the best reasons to rewrite code!
Some people think the (condition) ? (true value) : (false value) syntax difficult to read. Now if one of your staff propose to rewrite it into traditional if (condition) ... else .... syntax, would you approve it?
-
@cheong said in If you could make breaking changes to C#, what would you do?:
So the learning curve of the language becomes much steeper than it should have been.
If you can find a developer who can use a language they haven't learnt, I'll show you a conman.
@cheong said in If you could make breaking changes to C#, what would you do?:
Some people think the (condition) ? (true value) : (false value) syntax difficult to read. Now if one of your staff propose to rewrite it into traditional if (condition) ... else .... syntax, would you approve it?
While I wouldn't necessarily give explicit approval, I'm not gonna stop them. After all, once a ternary gets even slightly past trivial, it's almost always better written as an
if...else
anyway.
-
@cheong said in If you could make breaking changes to C#, what would you do?:
"Efficiency to type" is rarely a bottleneck to development speed because after all, we need to think before we type. On the other hand, lacking "efficiency to read" will cause all kinds of maintainability problem, make beginners difficult to pick up the language, and make the code more error prone.
Why I'm for mandatory braces and semicolons.