Skip to main content

C# 8 is becoming too terse and it's going to backfire

I love working in C#, plain and simple. C# gets the job done, but - in it's latest preview, it's becoming too terse. Let me explain.

A C# logo (credit to https://www.techcentral.ie/c-roadmap-what-to-expect-in-c-8-0/)
A 'nifty logo don't you say?

Patterns

Have you ever heard of them? Well, besides software design patterns or if you are hungry, cookie patterns, there is something called pattern matching in C# 7 and it is pretty handy. If you've never used pattern matching before, you can check if a variable is of a certain type and assign this variable to a new variable in a single line. The example below explains how this will work.

is type pattern expression (credit to https://docs.microsoft.com/en-us/dotnet/csharp/pattern-matching#the-is-type-pattern-expression)
Using the is type pattern expression

Perhaps I haven't given it much thought to make use of this yet, but this feature out there and it makes sense. There really isn't any indication that we are assigning a variable in the code, we aren't using an equal sign or semi colon on the line, but still, it is an easy concept to learn. This new feature in C# 7 is not any more complicated than a ternary operator after you see it a few times. Good? Ok.

Let's take it one step further.

Patterns in switch statements

Let's look at the new feature coming out in C# 8, pattern matching in switch statements.

New switch syntax for patterns in c# 8 (credit to https://blogs.msdn.microsoft.com/dotnet/2019/01/24/do-more-with-patterns-in-c-8-0/)
What is going on here?

Here's what's different between the above and a regular switch statement:
  1. The switch keyword comes after the value in the switch statement (the "o" above), and before the brackets.
  2. We are no longer using the case keyword at all, simply replacing it all with a lambda syntax.
  3. default becomes _.
  4. Each "case" is an expression, with the result of the expression will be what is returned.
  5. Oh, and after each "case" statement is a comma now.

What is going on meme (credit to https://imgflip.com/memesearch?q=wtf)
What just happened... (and I'm not one to ever use memes, there must be something big going on here)

Let me preface that I love the work the Microsoft team is doing and making gains and strides with .NET Core and the C# language, but for this feature, I just can't understand how they thought of this syntax in C# 8.

It is believed, by the Microsoft team, that "[...] the switch statement is frankly rather clunky. It feels like the 5-decades-old language feature it is, with lots of ceremony."

Clunky? I'm sorry you have confused clunky with readable. I haven't heard one person complain about using a switch statement. Hold on a moment though, because as we talk about these patterns in switch statements now, "[...] the patterns are all of a sudden becoming the heaviest elements of the switch expression [...]".

Too heavy? I'm not comprehending this, I'm already having trouble with the terse syntax as is and now it is heavy too? In fact, let's simplify our above example using a property pattern to get rid of the when keyword and those double equal signs.

Using the property pattern in a switch statement (credit to https://blogs.msdn.microsoft.com/dotnet/2019/01/24/do-more-with-patterns-in-c-8-0/)
Using the property pattern in a switch statement

The above code conceptually (in my head; not technically correct) creates inline object initializers, and your object "o" has to match the object expression to return that result. If our object was of type Point and had an X and Y value of 0 would our result be "origin". (Read up on the var pattern if you want to know what the second line means).

Admittedly, this is cool - but is it practical? I suppose we'll have to see.

My fear

My fear of all of this terse language is the roadblock it makes for new developers, as well as splits the seasoned community. New developers will have to understand that now an underscore is a throwaway value in a switch statement, but can also be used within a variable name or elsewhere. The two forms of switch will be fundamentally different if you are using patterns or the old "ceremonious" way. Which switch statement is "better" - do you use one or the other? Oh, and don't forget that the new switch statement has commas after each expression!*

*Oh silly Microsoft...

I predict the seasoned developers will also face issues, albeit lesser, now that they can use two different switch statements. The syntax is more terse, so it requires more thought coding it. Perhaps another roadblock we will see is now I need to remember 2 forms of the switch statement, instead of just one. You may have different opinions than I, but I feel that the less tools we known in our belt very well will perform better than more tools in our belt that we know adequately.

Your thoughts?

How do you feel about this new feature? Does it feel like the ceremony has been lifted and now petal to the metal, er- code? Voice your opinions in this post or the official .NET blog.

Comments

  1. C# has always had a good sane balance in its language semantics not too verbose… and not filled with really stupid amounts c++ like syntax for doing things. So yeh don't like the direction much at all, its got c++ designed by bored committee stupidity written all over it.

    ReplyDelete
  2. i am ERIC BRUNT by name. Greetings to every one that is reading this testimony. I have been rejected by my wife after three(3) years of marriage just because another Man had a spell on her and she left me and the kid to suffer. one day when i was reading through the web, i saw a post on how this spell caster on this address AKHERETEMPLE@gmail.com have help a woman to get back her husband and i gave him a reply to his address and he told me that a man had a spell on my wife and he told me that he will help me and after 3 days that i will have my wife back. i believed him and today i am glad to let you all know that this spell caster have the power to bring lovers back. because i am now happy with my wife. Thanks for helping me Dr Akhere contact him on email: AKHERETEMPLE@gmail.com
    or
    call/whatsapp:+2349057261346










    i am ERIC BRUNT by name. Greetings to every one that is reading this testimony. I have been rejected by my wife after three(3) years of marriage just because another Man had a spell on her and she left me and the kid to suffer. one day when i was reading through the web, i saw a post on how this spell caster on this address AKHERETEMPLE@gmail.com have help a woman to get back her husband and i gave him a reply to his address and he told me that a man had a spell on my wife and he told me that he will help me and after 3 days that i will have my wife back. i believed him and today i am glad to let you all know that this spell caster have the power to bring lovers back. because i am now happy with my wife. Thanks for helping me Dr Akhere contact him on email: AKHERETEMPLE@gmail.com
    or
    call/whatsapp:+2349057261346










    ReplyDelete








  3. i couldn't believe that i would ever be re-unite with my ex-lover, i was so traumatize staying all alone with no body to stay by me and to be with me, but i was so lucky one certain day to meet this powerful spell caster Dr Akhere,after telling him about my situation he did everything humanly possible to see that my lover come back to me,indeed after casting the spell my ex-lover came back to me less than 48 hours,my ex-lover came back begging me that he will never leave me again,3 months later we got engaged and married,if you are having this same situation just contact Dr Akhere on his email: AKHERETEMPLE@gmail.com thanks very much sir for restoring my ex-lover back to me,his email: AKHERETEMPLE@gmail.com or call/whatsapp:+2349057261346
























    hindi ako makapaniwala na kailanman ay muling makiisa ako sa aking kasintahan, labis akong na-trauma sa pananatiling nag-iisa na walang katawan na manatili sa akin at makakasama ko, ngunit napakasuwerte ako sa isang tiyak na araw upang matugunan ito malakas na spell caster na si Dr Akhere, matapos sabihin sa kanya ang tungkol sa aking sitwasyon ginawa niya ang lahat ng makataong posible upang makita na ang aking kasintahan ay bumalik sa akin, sa katunayan matapos na ihagis ang spell ang aking dating kasintahan ay bumalik sa akin ng mas mababa sa 48 oras, dumating ang dating kasintahan ko. bumalik sa pagmamakaawa sa akin na hindi na niya ako pababayaan, 3 buwan mamaya kami ay nakipag-ugnay at nag-asawa, kung nagkakaroon ka ng parehong sitwasyong ito makipag-ugnay lamang kay Dr Akhere sa kanyang email: AKHERETEMPLE@gmail.com maraming salamat sa sir sa pagpapanumbalik ng aking dating kasintahan bumalik sa akin, ang kanyang email: AKHERETEMPLE@gmail.com o tumawag / whatsapp: +2349057261346

    ReplyDelete
  4. I was diagnosed as HEPATITIS B carrier in 2013 with fibrosis of the
    liver already present. I started on antiviral medications which
    reduced the viral load initially. After a couple of years the virus
    became resistant. I started on HEPATITIS B Herbal treatment from
    ULTIMATE LIFE CLINIC (www.ultimatelifeclinic.com) in March, 2020. Their
    treatment totally reversed the virus. I did another blood test after
    the 6 months long treatment and tested negative to the virus. Amazing
    treatment! This treatment is a breakthrough for all HBV carriers.

    ReplyDelete
  5. Increasing my knowledge in this field has been very helpful. Thank you for sharing. You can use this article to avoid Fake Instagram massages. This article is related to the topic of fake instagram chats. You can avoid them by reading it.

    ReplyDelete

  6. Help That Really Work Fast,

    permanent solution to herpes

    Robinsonbuckler11 (@) gmail.com..............................

    ReplyDelete

Post a Comment

Popular posts from this blog

UI redesigns are mostly a waste of time

To preface the article, I primarily work on, and prefer, back-end code. I've been involved in both web and software development for over 4 years now and worked with many front-end and back-end frameworks. New Twitter UI Before all of the UI designers that read this go out and riot and champion against me for saying UI redesigns are a waste of time, let me say that I do value design . I think at the bare minimum, a product or website needs to be usable , and if you possess a good eye and steady hand , you should feel compelled to create something that looks pleasing. David Just stop redesigning the UI all the time . UI redesigns, in my opinion, are a waste of time 95% of the time. Let me explain further. No one cares Come see our fresh new look ! What about our new  material design , come see! I'm sorry, but besides fixing the UI where it impacts the usability of your application, no one is raving about how a redesign makes the application any better.

[Fix] - ASUS PCE-AC68 adapter (no internet)

There seem to be a lot of problems with this adapter, even with such strong performance . Why so many issues? I'm not quite sure, but I needed to find a fix because I kept on losing wifi. The ASUS PCE-AC68 The fix Keeping it short - this is how I fixed the issue: Downloaded the driver for my OS from ASUS's support page -  https://www.asus.com/us/Networking/PCEAC68/HelpDesk_Download/ (in my case it was Windows 10 64-bit). Open Device Manager by holding the Windows key and pressing R, then typing "devmgmt.msc" and hitting Enter. (Don't worry, this isn't a scam . We are simply opening Window's Device Manager through the Microsoft Management Console snap-in .) Navigate to the yellow warning sign sitting under Network adapters and right click it. Select Update driver . Select Browse my computer for driver software  and choose the following path of the OS that you have installed on your computer. (The path for the driver on my computer was C

Logging into a website with Powershell

Powershell is great, and it's lately been my go-to shell while I'm working on Windows. Sorry command prompt I really don't do a lot of work in the shell, but I do like to play with low-level interfaces from time to time. The article is about Linux shells, but goes into good explanation about what a shell is if you don't know. Log into a website Today, I wanted to do something that I have never really tried before and that is logging into a website using Powershell . The concepts behind this are quite simple really, as Powershell has support to send HTTP requests  and that's usually all we need, unless the server has CSRF protections in place (which it should). We are going to attempt  to log in to my favorite website for buying socks, Absolute Socks : Is that a turkey?! In order to do that, we need to have a login. So if you don't already have an account on www.absolutesocks.com , go make one now. Viewing the login request On websites,