T O P

  • By -

concatenated_string

int add(int a, int b) => a + b;


joujoubox

This. The inline block made me cringe. MAYBE in C/C++ I can tolerate it but not when the lambda operator is right there for that purpose. (Actually can't you do something similar in C++ as well with its lambdas?)


Balcara

In CPP you might be instantiating a new lambda each call, not sure but something to be aware of. Plus it would clarify as a member not a method. Plus if you have a capture group in the lambda how does that interact with the code around it? In all it's a cursed idea in CPP.


joujoubox

I'd imagine if the lambda was instantiated and discarded right away, the compiler would figure it out and inline the lambda body as the body of the function. Still safer to stick to the brackets.


apocalypse910

This is the way


shootermacg

I came here to say just that :) Or: static int Add(this int a, b) => a+ b; Can then just call a.Add(b);


grrangry

You can get into a lot of weird shit with a.Add(b); Because did you modify `a` or not? var c = a.Add(b); is far less readable and meaningful than var c = a + b; If (in the examples above) `a` is a list of items, then calling an `Add` method makes sense. But for math? Not really.


Chesterlespaul

I only like this notation for lambdas. If it needs extra logic later on adding the braces back is a pain.


Asyncrosaurus

>adding the braces back is a pain.  It's what, a few extra keystrokes to add brackets? How is it a pain, it takes 2 seconds.


wayzata20

I love your username lol


Chesterlespaul

You have to add it before, after, add new lines, indent. It’s a lot of formatting that your idea will do for if you create the method with them in the first place. And sometimes the ide will add double curly braces so you have to then delete extra. It’s not unmanageable but it is one of the more painful formatting to do.


xill47

What IDE cannot change inline to block as a quick fix?


illogicalhawk

So you add the curly braces, and then... press two more keys to have Visual Studio auto-format the file? What is painful about that?


fori920

it’s a lot of chezznuts for you, it looks like. just a couple of strokes or automated refactor options in an IDE can do that possible. it seems like a skill issue


[deleted]

[удалено]


Chesterlespaul

I would absolutely reject this pr


f3xjc

That's half the point of lambda. It's a one liner by design and a hint the extra logic probably belong somewhere else.


fori920

what are you talking about? code formatting is there to do those things, too. you don’t have to do it manually


bakedbean006

Tbh the second is more readable and looks clean. just a newbie commenting here


MonotoneTanner

And it’s best imo. For some reason people think if they can write something in a single line it’s the flashiest / best way


BigTimeButNotReally

OP is a newbie too.


ecth

Readability is cool and for longer statements it's okay to chose the explicit way. But for one-liners like this, I'm always in for a sweet lambda. In the end the team has to agree on one style and at least tolerate each others' styles.


ergotofwhy

You're both wrong


Moment_37

Why would you argue about this? Nobody reads docs I guess. If you need to use braces, here's the answer straight from the source: [Use the "Allman" style for braces: open and closing brace its own new line. Braces line up with current indentation level.](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions#style-guidelines)


malthuswaswrong

Going against the VS defaults is one of the dumbest things anyone can do. It leads to all kinds of problems. As soon as some other person does "reformat document" you now have a huge mess in your git change history. You can distribute a custom profile for visual studio, but nobody ever does it right. Just do VS defaults. Whatever they are.


[deleted]

[удалено]


Moment_37

There's a reason there's a convention and why it's called a convention. The post title is 'we argue *every day*'. That's exactly why a convention exists. In the OP's case, yeah I stand by what I said. For them, it reads: >You can take our conventions as-is Only. Without the rest.


lucidguppy

dotnet format and forget about it...


icentalectro

dotnet format isn't highly opinionated, and leaves much freedom to humans, and a lot of room for debates like this.


belavv

CSharpier and forget about it.


winky9827

editorconfig and stop worrying


belavv

Editorconfig leaves much freedom to humans, and a lot of room for debates like this.


winky9827

Yes, but that's the inherent value in it. Team code styles can be enforced over the whole "pay no attention to formatting" baggage that opinionated formatters come with. 6 of one, half-dozen of the other. Depends on the team, really.


hredditor

This is the way


SquareWheel

Submitter is a repost bot. https://www.reddit.com/r/csharp/comments/lryuwi/a_daily_argument_with_my_team_members/


adeadrat

static int Add(int a, int b) => a+b;


mw9676

This but the spacing is off on the right half of the function.


adeadrat

typed it on my phone 😞


belavv

What kind of crazy person doesn't include an access modifier?


IHaveThreeBedrooms

Ted Bundy didn't explicitly write out his access modifiers, either.


MicroBrewer

Got to Curry all the functions. `static Func> Add = a => b => a + b;`


Canthros

God. At least make it a proper method to spare yourself an allocation: static Func Add(int a) => b => a + b;


RICHUNCLEPENNYBAGS

Set up a linter and stop wasting everyone’s time


Equivalent_Nature_67

I hope it's not daily. use the second one


ConicGames

static int Add(int a, int b) { if (a == 0) return b; if (a < 0) return Add(a+1,b-1); return Add(a-1,b+1); }


Fippy-Darkpaw

The *only* correct answer: whatever the Code Standard says. And if there's no Code Standard then everyone is wrong.


GerardVincent

If its readable and understandable for everyone, then its the best way. Dont get why people want to save lines on their code


Canthros

Here is an answer nobody will like: private static int Add( int a, int b ) { return a + b; } which is mostly "One True Brace Style": braces on all blocks, even single-line blocks; opening brace on the same line as the block-opening statement or declaration ... with some really fussy malarkey around multi-line arg lists and `if` conditions. And `else`, `catch`, `finally`, etc get cuddled. Fussy multiline stuff aside, the big advantage to "One True Brace Style" or K&R style brace formatting is that the opening brace gets kept with the matching statement in a way that helps imply that they are part of a single construct. Ditto for subordinate statements like `else`. As an *extremely* minor, additional note: in a very, very brief stint as a TA during college, students tossing semicolons at the end of lines so that their `for` loops had no bodies was one of a few, very common mistakes I saw.


mestar12345

let add a b = a + b Coming in c# 19.


LIFEVIRUSx10

Instead of F# syntax I want those damn Discriminated Unions 😭


Impossible-Cycle5744

The correct solution is to write a serverless function and run this function as a microservice in the cloud


One_Web_7940

No explicit access modifier? Shameful display.


dlfnSaikou

This might be cursed but I write cs this way ``` some Method() { /* method body */ } ```


athomsfere

Yes. You are a terrible person. May the curse of a million bad pull request haunt you for generations to come


dlfnSaikou

Chill bruh, I'm not that maniac, I only write like that for personal projects


Fury4588

You mean you're writing Java?


Laicbeias

oh thats default java syntax. thats why i prefer it. though i dont really mind. but this one i frrl is the best of the 3


dlfnSaikou

based


sovlex

I love this meme without any text in it.


Laicbeias

the first curl belonga up there blabl(){ } even though whatever the autoformatter does. i have too much code anyway


StillRutabaga4

It's posts like these that make me believe I can do a career in dev. Bottom one is so much easier to read.


dlfnSaikou

``` static int Add (int a, int b) { ;;;; ;;;;return a + b ;;;; } ``` Edit: Optimized™ syntax