140 points · by chokolad · 11y ago · 79 comments
I love the human style Microsoft has taken on in the past few years.
Lambdas, null conditionals, LINQ, compile-time generics, etc, none of these features on their own are all that amazing, but when you add them all up it just makes for a more pleasant experience.
Most of my time is spent in Java, building an Android app right now, and C#, building services, and I constantly feel like I'm doing battle with Java's syntax (it's interesting to me that the new Android Studio compresses lambda-like classes, like runnable, to look like lambdas).
In other words, LINQ should have been a library, not a language feature. (In my ideal world. It is possible that someone with better info could see such a move as a terrible mistake.)
I do agree though that LINQ seems to hint at and start evolving C# into a different semi-functional kind of language, and what we're stuck now with is a language with one foot in both worlds. Hopeful another language will come along one day and chisel out those ideas into a more pure form. (and I'm not meaning a pure functional language like for instance F#)
I kinda wish they'd put more thought and energy into some tidy way of doing error checking, pre-conditions etc. locating and avoiding bugs is still one of the main concerns in any project and not enough are done to help with that. There are extensions but they are all a little clunky or require too much effort.
If they did that correctly I think it could be a game changer on par with Linq and rx
You need at least the Premium edition for the required tools.
Update: On second thought, I think Code Contracts were already available on the free Visual Studio 2013 Community edition: https://visualstudiogallery.msdn.microsoft.com/1ec7db13-3363...
Ideal language for me is somewhere between C# and F#. C# is moving there (but F# doesn't).
Before I knew what lambdas were JS was hard to read too, and before I learned inheritance both Java and C# were confusing messes.
And what would F# need to move to? You can type out the types now, you can do all the OO of C#. The only thing I can think you mean is as add curly braces around functions and classes, which wouldn't make it objectively easier to read, just more familiar to some C# developers. Unless you mean add higher kinded types, but that would move it closer to Haskell.
GRR TOO MANY OPERATORS! Also syntax, and stuff.
But I don't use c# so I've no real skin in the game. Just trying to help get things out of everyone's system.
var someVar = class1.class2.SomeProp;
would return null, even if class1 was null. I have a hard time coming up with cases where you actually would want to force an exception. I realize however they reason for the new operator since they might not want to change how existing code works...
In many cases you can guarantee that the sub-property is not null and you can safely access the value. I think the proposed operator `.?` is the perfect solution and gives you the flexibility to decide what you can guarantee and how you want to access the sub-property.
But value types are a good point, either it could then set it to default(T) or not set it at all, but it kinda has to be default(T) because null makes most sense for reference types. Might give some unexpected behavior if it variables are set to 0 because of a null reference
# authenticator == null
if (authenticator.getSessionError(session) == null) {
# Assumed session is okay, actually the bug is null authenticator
}You get the feeling though many of these problems comes down to null's largely being a language defect in itself which should have been adressed differently
I'm most excited about being able to watch the result of lambda functions while debugging (not mentioned here), should make things much easier.
> int? length = customers?.Length; // null if customers is null
Surely, a primitive int cannot be null (at least in Java).
Thanks; this shows how rusty my C# skills have become.
C# has improved fairly rapidly. I haven't done it professionally in some time now and I feel like I don't have a good handle on the full language anymore.
I'm somewhat concerned the language is getting too "big", but I'm not sure it's at that point yet. They keep adding solid features.
(implemented with as a macro AFAIK)
C# already has a ton of those, the most prominent so far are extension methods.
Foo.Blergh()
can be implemented by a class that offers
static void Blergh(this Foo foo) {}
and the compiler will just replace the call above, looking like a specific thing Foo can do with
SupportingClass.Blergh(thatFooInstance)
I'd say the nameof() implementation is most likely similar and will just replace the name of the local symbol with the symbol itself, during the compilation.
Yes, nameof is compile-time. Similarly, the ?. generates code (a "? :" or if statement) and so does the string interpolation (a call to string.Format).
I've even sketched an outline of a talk of the c# language features that are "just" sugar. e.g. walking through a statement like
var evens = numbers.Where(x => x % 2 == 0);
and showing what it looks like without the compile-time sugar features like the lambda, extension method use of "Where", "var" inference, etc.Of interest I suppose to just-beyond-beginner devs
I highly recommend reading through https://roslyn.codeplex.com/discussions/570551 and the other four revisions of the nameof() spec, they do a very good job at explaining the tradeoffs of each design.
That will clean up quite a bit of my code.
I'm missing a line that says
using static Math.Sqrt; using System.Math;
System.Math is a static class, not a namespace. It doesn't import a single static method, it imports the entire class.However, in the italicized note, you can see they changed their minds after releasing the preview. It's going to be "using static", but they didn't update the example. It will still operate on the entire class and not an individual method though.
It's easy to mess up a null check, but it's equally easy to find the bug and fix it.
It's easy to mess up a string format, but it's equally easy to find the bug and fix it.
It's easy to mess up a chain of Rx event streams and when you do--you're out of luck buddy. Have fun debugging that.
Async rewriting for error handling does solve a really difficult problem, but there are much deeper problems with using C# for the kind of imperative threading code where that problem comes up. I wouldn't write that in C#, that's certain.
Don't get me wrong: I like that syntax change--I'm all for shorter, cleaner code. But I've moved on from C# because it was ineffective for solving hard problems like multithreading, scaling, networking, crypto. Eliminating a few if statements doesn't fix that.