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 '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.
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.
What is going on here? |
Here's what's different between the above and a regular switch statement:
- The switch keyword comes after the value in the switch statement (the "o" above), and before the brackets.
- We are no longer using the case keyword at all, simply replacing it all with a lambda syntax.
- default becomes _.
- Each "case" is an expression, with the result of the expression will be what is returned.
- Oh, and after each "case" statement is a comma now.
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.
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.
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 |
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.
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.
ReplyDeleteCompletely agree with you.
Deletei 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
ReplyDeleteor
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
ReplyDeletei 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
I was diagnosed as HEPATITIS B carrier in 2013 with fibrosis of the
ReplyDeleteliver 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.
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
ReplyDeleteHelp That Really Work Fast,
permanent solution to herpes
Robinsonbuckler11 (@) gmail.com..............................