Earlier quoted context omitted.
I suppose that depends upon where you’re coming from. Many, many languages have an sprintf-style construct of one form or another, so I think it’s actually much more familiar to most people to have a placeholder with an optional formatter. To each their own, though.
Well, let's take the TIOBE index as a rough indicator of popularity: https://www.tiobe.com/tiobe-index/ Java, C/C++/Objective-C/Go (I'm lumping them up because they're basically C + C NextGens), Matlab, SQL, ASM don't have them. Everything else, has them. On the list of languages that don't have it, Java is planning to add it, I don't see the C family to change because it's very conservative, and the others are domai…
C# 8: Switch expressions
81–90 of 124 posts
Re: C# 8: Switch expressions
#82Earlier quoted context omitted.
For some time, I've thought that the direction of C#'s evolution makes a lot of sense if you look at as the designers' effort to cope with Haskell envy (pattern matching, type inference (which is really just class inference), and monad comprehensions). But, it makes almost complete sense if you instead look at it as coping with Lisp envy. I'm still amazed that they managed to sneak in function literals and FEXPRs (Li…
I don't think it's Lisp envy. They're porting stuff from F#, which as far as I know is from the ML family.
"Confessions of a Used Programming Language Salesman, Getting the Masses Hooked on Haskell"
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72....
Re: C# 8: Switch expressions
#83I am not sure I like the path c# is going down. For years the language has been trying to evolve from being aesthetic and easy to understand and read. With the functional implementations and patterns I believe the language is trying to embrace too much. This is not specific to the swith expression in this context but in general. You can write C# in too many forms and I don't believe that's really good.
I think I agree. I used to write a lot of C# v2 and loved it. There didn't seem to be anything 'missing'. Each version since then has added nice things but are they really necessary? Now the language looks huge and complicated and because of that, I'm not sure I'd ever want to use it again.
Re: C# 8: Switch expressions
#84This might be better titled "C# 8: switch expressions" (edit: it was previously "statement", as the author's post is titled). Or actually, to bait a few more hn clicks (and provide a fuller description): "Pattern matching in C# 8 with switch expressions"
This might be better titled "changing things for the sake of changing things and appealing to the programming language geeks". The new syntax is not intuitive, not more readable, just a bit more terse.
Also, there is an elegance to the functional style of pattern matching. And C# has been incorporating a lot of functional paradigms for more than a decade now which may initially feel "out of place" but ultimately benefited the language greatly.
Re: C# 8: Switch expressions
#85Earlier quoted context omitted.
This change was definitely inspired by F# (or ML ultimately). It's far from the first feature to be brought over. Look at async/await, usable tuples, lambda functions, range syntax, etc.
AFAICT, this is kind of true for a lot of F#: F# is where they do the experimentation, C# is where they do the more heavily engineered "fast" version.
Re: C# 8: Switch expressions
#86"+" => ((Func )(() => { Log("addition"); return a + b; }))(), This is incredibly ugly. Why couldn’t it be “+” => {stuff}
That is ugly. What he's doing is creating an anonymous function which takes no parameters and returns an int. That's what a Func is, and then he is executing that function, that's the () bit after })) He could write it nicer as: "+" => Add(), Where he defines add as int Add() => a + b; He's just doing too much inline, 99% of C# developers would not write code as he has done there. Its' the bloggers code style that is…
It's two short lines.
The problem is that he's writing a small but more than one line bit of code, so the overhead of the anonymous function is just as big as the code itself, and arguably more complex.
Re: C# 8: Switch expressions
#87Earlier quoted context omitted.
In TypeScript, this can be achieved using an assertion to the never type. I don't think it exists in C#, though.
They aren't real guarantees in TypeScript, because the type system doesn't guarantee anything about the actual values that are flowing through the system. i.e. you have to code everything in TypeScript and make sure everyone follows the best practices.
Re: C# 8: Switch expressions
#88I am not sure I like the path c# is going down. For years the language has been trying to evolve from being aesthetic and easy to understand and read. With the functional implementations and patterns I believe the language is trying to embrace too much. This is not specific to the swith expression in this context but in general. You can write C# in too many forms and I don't believe that's really good.
However, when it comes to modern C# and memory management I also think that readability suffers a lot. Memory management on that level is well known to the professional C/C++ folks but most of us are just overloaded with it.
Re: C# 8: Switch expressions
#89Earlier quoted context omitted.
I think I agree. I used to write a lot of C# v2 and loved it. There didn't seem to be anything 'missing'. Each version since then has added nice things but are they really necessary? Now the language looks huge and complicated and because of that, I'm not sure I'd ever want to use it again.
C# 2 did not have Linq. Linq is the best feature ever.
That's been the case for the majority of supposed "new features" in C# for at least the past 8 years or so -- LINQ, inline variables, anonymous functions, string literals etc. It's all just syntactic sugar on top of existing features.
Re: C# 8: Switch expressions
#90Earlier quoted context omitted.
C# 2 did not have Linq. Linq is the best feature ever.
Actually, adding LINQ to C# did not introduce any new functionality at all. Everything you can do in LINQ you could already accomplish in C# without LINQ. Yes, I suppose someone could say that the older code was uglier, but it already had the same capabilities as LINQ. That's been the case for the majority of supposed "new features" in C# for at least the past 8 years or so -- LINQ, inline variables, anonymous functi…