|
That kind of humor wheel fall flat on it's face. Not that off fendered or anything like that, but . . . wait . . .
A question: is a carburetor what a woman calls it when someone who talks incessantly about their vehicles 'down shifts' on her?
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 |
|
|
|
|
|
return _(); IEnumerable<TSource> _() {...}
Found this on MoreLinq, it actually took an SO lookup for me to realize they were use a local method with an "anonymous" name.
In this context, the underscore is just an arbitrary name for a local function (which is a new feature introduced in C# 7.0). If you prefer, you could replace the underscore by a more descriptive name.
C# is starting to look more like Ruby/Python.
The explanation is useful though:
By the way, the reason for having two methods here is so that, in case any argument is null, ArgumentNullException will be thrown immediately when DistinctBy is called instead of when the result is enumerated (due to the presence of the yield return statement).
Though, putting this on the same line...I agree with what others wrote.
|
|
|
|
|
The more they add to the language, the more I look at it and think it's time to rip it apart and create D# or whatever. Some of this seems to have been added to please one person who might use it, instead of being a general solution to a widespread problem. Can't see how this makes maintenance easier at all...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Maintenance? Are you joking?
These 'features' only exist to lengthen the feature list of upcoming new versions, to give some guys something to pontificate over and, most importantly, keep the fanbois drooling in anticipation.
Who cares what it's actually good for?
The user can't update the up: we update it for them (Choice in the CP poll)
|
|
|
|
|
OriginalGriff wrote: Can't see how this makes maintenance easier at all...
You can probably find people making the same argument for every feature ever introduced since v1.0!
I assume you don't use anonymous methods[^] either? Because manually writing a private class to represent a closure makes maintenance so much easier.
In this specific instance, they should have given the local function a more meaningful name than "_ ". But ignoring that, there's no real benefit to sticking with the previous version[^], which had a private static "Impl" method that was only called from the main method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 15-Sep-17 11:30am.
|
|
|
|
|
I use anonymous methods - when they are appropriate - but that abortion is just bad code. It's lazy and doesn't make anything easier on the poor sod who has to work on it.
And I have noticed that the people who throw this kind of thing together are always far too busy to fix it six months later when the bug reports come in ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Richard Deeming wrote: class
Classes? Are you insane? These little buggers are nightmare for maintenance. You don't need anything more than assembler, you're just trying to be hip.
|
|
|
|
|
Richard Deeming wrote: You can probably find people making the same argument for every feature ever introduced since v1.0!
Version 1.0 of C you mean.
Or perhaps version 1.0 of Fortran/Algol/Cobol.
Richard Deeming wrote: Because manually writing a private class to represent a closure makes maintenance so much easier
And easier to read also. And those one liners make debugging a snap as well.
|
|
|
|
|
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[^]
|
|
|
|