I'm a VB.NET programmer who also knows some C#. I've recently come across lambda expressions which in VB can look like this:
a = Function() b + c
However in C# they look like this:
a => b + c;
(Which, to me, looks a lot like a bizarre pointer expression from C)
The problem is that when reading C# code I mentally parse the operators into english words. So a = b + c;
becomes "add b and c and assign to a". However I have no mental translation in my built in parser for the for the =>
operator yet so a => b + c;
becomes either "a equals pointer to b and c" which makes no sense or "a is a lambda of b and c" which is dreadful.
I'm sure that the language creators meant for that operator to stand for a concept and that concept should be able to be reduced to a single word or very short phrase.
So what is the intended English translation for the =>
operator?
p.s. Note that I've tried to make the examples to be as simple as possible so as not to get bogged down in the specifics.
All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side hold the expression or statement block. The lambda expression x => x * 2 is read "x goes to 2 times x." This reduced the no.
The expression num => num * 5 is a lambda expression. The => operator is called the "lambda operator". In this example, num is an input parameter to the anonymous function, and the return value of this function is num * 5 . So when multiplyByFive is called with a parameter of 7 , the result is 7 * 5 , or 35 .
You have your example slightly wrong.
This VB code
a = Function()
Return b + c
End Function
looks like this in C#:
Func<int> a = () => b + c;
The problem with the suggestion of calling =>
"returns" is that this doesn't work with lambdas that don't return anything:
For example:
Action a = () => Console.WriteLine("Test");
If you call =>
"returns" in that scenario, it would be a bit confusing, I think.
Generally, the term used for =>
is "goes to" but some people say "maps to" or (in the case of lambdas that are used as predicates) "such that".
My personal preference is "maps to" (as suggested in the very first reply to the OP!).
How about 'a returns b plus c'?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With