Click here to Skip to main content
15,906,081 members

Survey Results

For the C# devs: expression body or old school functions?

Survey period: 21 Feb 2022 to 28 Feb 2022

Do you prefer the expression body public override string ToString() => "I am an object"; or the traditional public override string ToString() { return "I am a string"; }?

OptionVotes% 
I prefer the shortened expression body syntax13717.13
I prefer traditional functions31639.50
It depends on the situation18122.63
I don't care8911.13
I'd never heard of expression body definitions779.63



 
GeneralGeez, you could have come up with a simpler example Pin
Marc Clifton22-Feb-22 9:43
mvaMarc Clifton22-Feb-22 9:43 
GeneralI hate the proliferation of arrow functions throughout the language Pin
Dan Neely22-Feb-22 8:36
Dan Neely22-Feb-22 8:36 
GeneralRe: I hate the proliferation of arrow functions throughout the language Pin
Kate-X25722-Feb-22 22:12
Kate-X25722-Feb-22 22:12 
GeneralThank you traditionalists Pin
James Lonero22-Feb-22 6:43
James Lonero22-Feb-22 6:43 
GeneralRe: Thank you traditionalists Pin
Ravi Bhavnani22-Feb-22 7:43
professionalRavi Bhavnani22-Feb-22 7:43 
GeneralRe: Thank you traditionalists Pin
den2k8822-Feb-22 8:15
professionalden2k8822-Feb-22 8:15 
GeneralRe: Thank you traditionalists Pin
DanM222-Feb-22 9:59
DanM222-Feb-22 9:59 
GeneralThere goes using => for something useful... Pin
Kirk 1038982122-Feb-22 2:45
Kirk 1038982122-Feb-22 2:45 
Generalwhat I care about is why ToString being overridden Pin
maze321-Feb-22 23:58
professionalmaze321-Feb-22 23:58 
GeneralHold on ... lemme search through my [codeCp] database ... Pin
RedDk21-Feb-22 6:49
RedDk21-Feb-22 6:49 
Generalwhy is => preferred over {} for those write the code to be interpreted - compiled ? Pin
MarcusCole683321-Feb-22 5:35
professionalMarcusCole683321-Feb-22 5:35 
GeneralRe: why is => preferred over {} for those write the code to be interpreted - compiled ? Pin
trønderen21-Feb-22 7:17
trønderen21-Feb-22 7:17 
GeneralRe: why is => preferred over {} for those write the code to be interpreted - compiled ? Pin
#realJSOP21-Feb-22 23:42
professional#realJSOP21-Feb-22 23:42 
GeneralRe: why is => preferred over {} for those write the code to be interpreted - compiled ? Pin
J. Frank Reeves22-Feb-22 2:37
J. Frank Reeves22-Feb-22 2:37 
GeneralRe: why is => preferred over {} for those write the code to be interpreted - compiled ? Pin
jochance22-Feb-22 5:22
jochance22-Feb-22 5:22 
Right? Some of the "best" work I've done probably involved cutting the total number of lines by a significant percentage. It's always been a ridiculous metric, but I haven't witnessed it ever being used.

RE: the expression body poll

When it is simple like the example, the "old school" syntax isn't making things any more clear for anyone at all really, unless they just haven't been introduced to expression body. This is not expression body's fault. No logic 1-liners mean there's just no reason or need to chew up screen space with the more verbose way of doing it.

I knee-jerk answered the poll that it depends, but thinking more, expression body is probably just the way to go here.

Even where the verbosity of "old school" makes more sense for readability, what should be happening in that scenario in pretty much all cases is an expression body that calls such an "old school" function.

Maybe before we were all doing so much dependency injection and unit testing this was not objectively answerable. Taking those into account though, expression body is a clear winner. FWIW, ReSharper seems to think so also.
GeneralRe: why is => preferred over {} for those write the code to be interpreted - compiled ? Pin
Member 1044734222-Feb-22 6:34
Member 1044734222-Feb-22 6:34 
GeneralPinheads Pin
lucanor21-Feb-22 1:52
lucanor21-Feb-22 1:52 
GeneralRe: Pinheads Pin
KarstenK21-Feb-22 2:08
mveKarstenK21-Feb-22 2:08 
GeneralRe: Pinheads Pin
musefan21-Feb-22 3:00
musefan21-Feb-22 3:00 
GeneralRe: Pinheads Pin
KarstenK22-Feb-22 5:19
mveKarstenK22-Feb-22 5:19 
GeneralRe: Pinheads Pin
Wendelius21-Feb-22 4:41
mentorWendelius21-Feb-22 4:41 
GeneralRe: Pinheads Pin
trønderen21-Feb-22 7:10
trønderen21-Feb-22 7:10 
GeneralRe: Pinheads Pin
DougInNC222-Feb-22 2:38
DougInNC222-Feb-22 2:38 
GeneralRe: Pinheads Pin
OriginalGriff22-Feb-22 3:20
mveOriginalGriff22-Feb-22 3:20 
GeneralI have so few one-line methods... Pin
#realJSOP20-Feb-22 23:18
professional#realJSOP20-Feb-22 23:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.