3 ms·
> New in C# 6! Enables a concise syntax for calling static methods without type qualification. Essentially you still have to put your functions in a class, but
by maxlybbert 11y ago
> New in C# 6! Enables a concise syntax for calling static methods without type qualification.
Essentially you still have to put your functions in a class, but you're allowed to call them without the class (if desired). Kind of like "free functions" in C.
I like C#, but it looks like the team is running out of ideas. Or, perhaps, they realized that the "everything must go in a class" mantra was a bad idea.
- runfaster2000 11y agoYou might take a look at the C# 7 design notes: https://github.com/dotnet/roslyn/issues/created_by/MadsTorgersen https://github.com/dotnet/roslyn/issues/created_by/MadsTorge...
- edgyswingset 11y agoI think you're underestimating the power of static includes. A benefit is being able to add a dialect of sorts to your codebase to give it some functional flair. One person took this to the extreme[0]. [0] https://github.com/louthy/language-ext https://github.com/louthy/language-ext
- maxlybbert 11y agoOr the people who thought "everything must be attached to a class" were overestimating the value of that idea.
- Moto7451 11y agoI don't think it's that they've run out of ideas, it's that they're being picky with what they implement as C# is fairly modern but also fairly mature. This isn't like the C++ revolution of the past few years where they've been adding new, interesting, (and sometimes dramatically different) features to a decades old language. Regardless, this change is very handy. Even if "everything must go in a class" is a bad idea (I think it's fine), the end result of this change, from the library consumer's standpoint, is the same as having functions defined outside a class but within a namespace. It's a great pragmatic change that doesn't rock the boat much. In line with that are the other mostly minor but time saving changes like simplified null coalescing. public static string Truncate(string value, int length) { return value?.Substring(0, Math.Min(value.Length, length)); } In previous versions this looks like: public static string Truncate(string value, int length) { return value != null ? value.Substring(0, Math.Min(value.Length, length)) : null; } Not a huge change, but a very handy one to have.
- maxlybbert 11y agoI recognize that this particular change is meant as a convenience. But I'm not the person who put the exclamation mark in the part that I quoted from the article. And it makes me laugh that one feature they specifically call out is the ability to do what programming languages could do in, say, 1958 ( https://en.wikipedia.org/wiki/ALGOL_58 https://en.wikipedia.org/wiki/ALGOL_58 ).
- amyjess 11y agoThis is the same as Java's "import static" functionality, which has been around since Java 5. At least in Java-land, it's considered bad style to use this for anything other than constants.