News for hackers. Stuff that matters.
Re:C# 8: Switch expressions by danielovichdk on Friday February 15, 2019 @11:46AM (#19172346)
I 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.

Re:C# 8: Switch expressions by oaiey on Friday February 15, 2019 @02:33PM (#19173976)
I would not take pattern matching as the right example. I learned pattern matching at the university and always missed it in C#. It is easy and straightforward. When you love lambdas and linq, so C# 3.0, pattern matching is easy.

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 by runT1ME on Friday February 15, 2019 @12:34PM (#19172853)
I agree. It has the flexibility of Scala without the extra power/abstractions Scalaa gives you. I don't love Scala's flexibility but I put up with it because of its power, the trade off isn't worth it for C# to me.
Re:C# 8: Switch expressions by dgritsko on Friday February 15, 2019 @11:55AM (#19172442)
> You can write C# in too many forms and I don't believe that's really good.

Why not? And what, exactly, defines "too many"?

Re:C# 8: Switch expressions by kminehart on Friday February 15, 2019 @12:01PM (#19172517)
I know people meme a lot about Go and "not having generics," but I really feel that a lot of the things left out of Go have benefitted it. I've never really been able to jump into a project without a lot of mental overhead. With Go, most code everywhere is written pretty idiomatically, making it easy to approach and read. I've heard similar things about C#, but my experience hasn't been as great.

This is a big problem in the JavaScript world in my opinion. So many different ways to solve common problems that it's difficult to approach. OP might be worried this could be happening to C#.

Re:C# 8: Switch expressions by BoiledCabbage on Friday February 15, 2019 @12:55PM (#19173052)
We could go with a language with just if statements, while statements, function calls and "return" and be extremely easy to jump into. :)

While a bit snarky I do think it is one of the fundamental problems with programming language innovation. No matter how smart we are, learning is effortful. And we frequently judge languages not by how productive it is, but by how quickly we can start feeling productive in it. Which often preferences familiar concepts over more powerful concepts.

There is a very long feedback loop in properly evaluating a language. At least 1-2 years. You need not just figure out how to do what you already know in the language, you need to learn the new way to think in the language. And that takes time and solving lots of problems. This is only sped up if the language's concepts are kept very similar to a language you already know.

We are the bottleneck that slows down language improvement. There is no way anyone can convince me that the hodgepodge of Algol derived languages is one of the best ways out there of writing code. But most new languages will be similar because the hurdles of trying to teach people anything else alongside the actual new interesting concepts of your language are too much of a blocker for any reasonable adoption.

Re:C# 8: Switch expressions by dgritsko on Friday February 15, 2019 @12:09PM (#19172602)
I suppose, but that seems like a natural consequence of C#'s desire to move the language "forward" in terms of implementing new features (such as switch expressions or non-nullable reference types) while also maintaining backwards compatibility (for example, you can still use the non-generic "ICollection" interface if you want to). Just a different set of priorities.
Re:C# 8: Switch expressions by flavio81 on Saturday February 16, 2019 @08:58AM (#19178563)
>I know people meme a lot about Go and "not having generics," but I really feel that a lot of the things left out of Go have benefitted it.

Yes, that's why we program in Brainf__k here: It only has the bare essentials and it's so easy to learn.

Re:C# 8: Switch expressions by azhenley on Friday February 15, 2019 @12:00PM (#19172505)
Perhaps he means something like Python's motto of "There should be one--and preferably only one--obvious way to do it."

https://www.python.org/dev/peps/pep-0020/

Re:C# 8: Switch expressions by goto11 on Saturday February 16, 2019 @05:55AM (#19178098)
I think all the new features are improvements, but I agree the language is getting big with many ways to do the same thing. I don't think MS will ever do a 'Python 3' and cut backwards compatibility.
Re:C# 8: Switch expressions by nordsieck on Friday February 15, 2019 @12:14PM (#19172652)
> Why not? And what, exactly, defines "too many"?

I think Scala was innovating in this respect before Kotlin ate its lunch (it may still be).

You could use Scala as everything between Java++ and Haskell--. Developers proficient in Java++ often had a difficult time understanding code written in Haskell--.

Re:C# 8: Switch expressions by JustSomeNobody on Friday February 15, 2019 @01:27PM (#19173382)
Language designers are not immune to the "code must change constantly otherwise it's abandonware" mentality of today's developers.
Re:C# 8: Switch expressions by kalekold on Friday February 15, 2019 @01:17PM (#19173265)
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 by oaiey on Friday February 15, 2019 @03:03PM (#19174212)
C# 2? The freshness of C# 3! The comfort improvements of C# 4, C# 5 and C# 6! And now the new freshness in C# 7.0.

I agree with other posters that this introduces a new style, but when I look at C# 2.0 I see a language I do not want to use anymore. It is old and clumsy. Like Java :)

Re:C# 8: Switch expressions by goto11 on Friday February 15, 2019 @02:10PM (#19173755)
C# 2 did not have Linq. Linq is the best feature ever.
Re:C# 8: Switch expressions by Invisig0th on Friday February 15, 2019 @02:35PM (#19173999)
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 functions, string literals etc. It's all just syntactic sugar on top of existing features.

Re:C# 8: Switch expressions by Dylan16807 on Friday February 15, 2019 @02:38PM (#19174020)
That's the general nature of a turing complete language. The purpose of every feature is making things less ugly.
Re:C# 8: Switch expressions by Invisig0th on Friday February 15, 2019 @02:54PM (#19174149)
I'd say it's more the general nature of Microsoft in this particular case. "There should be three different ways to do that" has been the case since Windows 3.1.
Re:C# 8: Switch expressions by goto11 on Saturday February 16, 2019 @04:56AM (#19177958)
There is no way you can implement Linq in C# 2.0. C# 2 does not have lambdas and expression trees, so you cannot write an expression which can either be compiled into regular code or into an expression tree depending on context.
Re:C# 8: Switch expressions by aragorn2 on Friday February 15, 2019 @08:34PM (#19176415)
IIRC, LINQ can be translated to C# 3.0 without LINQ, so I guess it is syntactic suger but for C# 3.0. To implement it in C# 2.0 one would need to replace expression trees with “home made” query specification classes. It would be a lot of work, it would not be standardized, and it would not be integrated in the language.

So the real new feature in C# 3.0 are the expression trees. LINQ is only one place where expression trees are used.

Re:C# 8: Switch expressions by contravariant on Friday February 15, 2019 @03:09PM (#19174250)
LINQ is surprisingly powerful when you start overloading SelectMany, as that allows you to implement Monads nicely.
Re:C# 8: Switch expressions by balfirevic on Friday February 15, 2019 @04:50PM (#19175038)
Do you know what "expression trees" are and how they relate to LINQ?