|
I think the reason is so that there is less code on the page. Do more with less. Eventually in C# v45.6 we will be able to accomplish an entire line of code in the span of one character - a super character of sorts.
Here is a sample of what a simple "Hello World" console app might look like with C# v45.6.
a
|
|
|
|
|
Don't you mean:
public void a
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
I think you missed the point of my joke. Either that, or just wasn't funny to begin with, which is totally possible. No worries.
|
|
|
|
|
With people, we note them as "Jackass of all trades - Master of None".
Where's my damn QuickC ?
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
I can see the value in local functions but, I agree, that code could have been written for better readability.
Another one that doesn't quite sit well with me is the new Expression-bodied Members[^] and Throw Expressions. That just makes the code harder to understand if you're new to C#. This one depends more on understanding the convention being used instead of on the intent of the code.
modified 15-Sep-17 13:25pm.
|
|
|
|
|
I'm kinda meh about Expression-bodied Members since they seem limited to single statements. However, throw expressions are a bit of a wack-on-the-head. You don't expect to see them when encountered. Why not just have the called method on the left side throw an exception?
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
As far as I can tell, throw expressions only exist to make expression-bodied members work. Without them, you'd have to check for null and throw an ArgumentNullException , which would mean multiple lines, and therefore prevent you from using an expression body.
I'm sure some people will find a use for them. But I still much prefer using multi-statement bodies when there are multiple statements to execute.
And I'm not really a fan of using expression-bodied methods for properties with more than one accessor either.
public string Name
{
get => name;
set => name = value ?? throw new ArgumentNullException(nameof(value));
}
public string Name
{
get => name;
set
{
if (value == null) throw new ArgumentNullException(nameof(value));
name = value;
}
}
public string Name
{
get
{
return name;
}
set
{
if (value == null) throw new ArgumentNullException(nameof(value));
name = value;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Lambdas have become so important for the language that I don't see the issue with expression-bodied members. It's pretty easy to figure out what they mean even if you've never seen them before. But I can see the argument for "it wasn't needed so why add it?"
The throw expressions with a null-coalescing operator, however, is a very logical addition in my opinion. It just makes sense. That operator is great for two things: defaults on null and errors on null. Until now you couldn't do the second instead having to fall back on if(X == null) throw /*error*/ . Granted that isn't much boilerplate compared to the handler code that was simplified with ?. , but it just makes sense that ?? should make it unnecessary.
|
|
|
|
|
Oh, I can see the value in it, but like I said, someone new to this looks at that and goes "what the is THAT?!". I know this because I had three people who have some curly language experience come up, see this, and said that very thing.
|
|
|
|
|
I use what I need to get the job done - if it is that syntax and is readable and easy to maintain...
|
|
|
|
|
It's becoming like every other ms product: 90% of the features must be [at best] barely useful.
(feeling kind today - avoiding negatives.)
Signature not found error error: Unable to throw signature not found error.
|
|
|
|
|
Never used it exactly like this, no. But I've used it when using a lambda to satisfy a delegate/action/func parameter with at least one parameter of its own where I literally do not care about the lambda parameter. Ex. _ => { /*....*/ }
|
|
|
|
|
Dont know, pretty sure there is a C# forum for this question though.
|
|
|
|
|
If you refuse to pay your tv licence you get sent to prison where you can watch tv all day without needing one
|
|
|
|
|
And you get free food, medical care, and...
|
|
|
|
|
And....... have to fight over the remote?
|
|
|
|
|
..and free soap on the shower floor. I'd still prefer a decent hotel, can't see why people think it is a nice place to stay
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Soapbox!
... such stuff as dreams are made on
|
|
|
|
|
That's where this should have been in the first place.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Doesn't hurt as much if you do
|
|
|
|
|
But some bad mates. I like more to work with gentle and intelligent mates
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
and the opportunity to live in a gated community.
|
|
|
|
|
Pom Pey wrote: you can watch tv all day without needing one
Someone else is paying for the license, but I do understand the point you are making.
|
|
|
|
|
Yeah the government paying the government
|
|
|
|
|
So, remembering that this is soapbox material, what do you propose?
Ending the government?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|