6 ms·
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,
by jmnicolas 8y ago
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.
- arethuza 8y agoActually, I think it is rather intuitive and readable - but then again I programmed in lisp for years.
- noblethrasher 8y agoFor 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 (Linq), a metaobject system (dynamic + DLR), a limited form of call/cc (aysnc/await), first-class metaprogramming (Roslyn -- albeit more in the style of Smalltalk rather than Lisp), and a REPL.
- oblio 8y agoI don't think it's Lisp envy. They're porting stuff from F#, which as far as I know is from the ML family.
- noblethrasher 8y agoWell, to be clear, I was being tongue-in-cheek when calling it "envy". I just mean that C# looks messy from the point-of-view of an ML-wannabe, but pretty elegant as an aspiring Lisp. And I say this as someone that is fluent in F# and prefers functional programming in the style of ML rather than that of Lisp.
- falcrist 8y agoThis 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.
- moomin 8y agoAFAICT, 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.
- falcrist 8y agoThat seems to be true at least to some extent. However, there are some noteworthy parts of the two languages that seem to be intentionally different. For example, F# optimizes tail recursion while C# doesn't.
- deleted 8y ago[deleted]
- pjmlp 8y agoLINQ actually came from Haskell. "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.868&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72....
- chrismeller 8y agoThis actually seems to be somewhat of a trend in C# as of late. Ever since they introduced lambdas, really. While I use them every day, my favorite is still “replacing” String.Format with string literals. Shorter, sure, but less intuitive particularly for people coming from another language. You can do roughly the same thing in PHP with backticks, but most people avoid them for the same reasons. I’m not sure how I feel about the trend as a whole. As long as I can continue using the old methods as well I suppose I don’t have much room to complain, but sometimes it does feel like we’re just changing for the sake of change and that’s usually a bad indicator.
- maxxxxx 8y agoI think string interpolation is one of the best things they did to C#. String.Format is pretty error prone.
- kolbe 8y agoI'm on your side. I've found very little use for most improvements since C# 4, but I always use literals now. Things like value tuples and string literals are huge improvements to my code's readability and flow.
- wongarsu 8y agoUsing switch as an expression makes sense, just like using if as an expression (often written as a?b:c) does. It makes it obvious that all you are doing is changing one variable, and it makes initialising constants a lot cleaner. Once you start making switch expressions, the break keyword makes no sense. And with pattern matching the case keyword technically wouldn't be nessesary for normal switch statements already, might as well drop it for the new syntax. I find this completely reasonable, and I think it's very readable, especially compared to the closest equivalents: putting a single switch in a function and calling that, or using nested tertiary operators: const sqlOp = op switch { "&&" => "AND", "||" => "OR", _ => throw new NotSupportedException() } vs function getSqlOp(string op) { switch op { case "&&": return "AND"; case "||": return "OR"; default: throw new NotSupportedException(); } } // ... far away const sqlOp = getSqlOp(op); vs const sqlOp = op=="&&" ? "AND" : op=="||" ? "OR" : throw new NotSupportedException();
- kibwen 8y agoThe break keyword in switch statements makes sense only if the programmer considers switch as a syntax sugar for goto, which are the semantics in C. Once you have a language that doesn't use goto but that still requires breaking each switch case, the only rationale is inertia for people familiar with C. (That said, C# does have goto, right?)
- wongarsu 8y agothe break keyword in switch statements also allows fallthrough, allowing for a terser way to write state machines, at the cost of making the whole construct less intuitive and readable. In a switch expression of course that is moot since break is a statement, and statements can't appear in expressions.
- kibwen 8y agoThe thrust of my above comment is largely about how the idea "enabling fallthrough" demonstrates how poorly the switch statement is usually taught: most people have an intuitive grasp of it as an alternative to if/else if, when in truth it's sugar for a jump table. Break exists to prevent fallthrough rather than enable it! And indeed fallthrough isn't useless, though decades of long experience has demonstrated that it is the wrong default, and newer languages like Go do better by making break the default and having a dedicated fallthrough keyword for when you want it.
- eckza 8y agoMore like the trend of “bolting everything they’ve ever heard on to the language spec”. This is a half-assed, syntactically ugly implementation of case statements in functional languages like Elm or Haskell - the point of which is to cover all possible executions of a branch explicitly, to prevent runtime errors.
- porpoisely 8y agoIt's not simply a matter of "uncomfortable" syntactic sugar. It's a fundamental change from a statement to an expression. 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.