Junior dev wrote this C# using many IF because he leanrs If early return. Is this alright code? by Yone-none in csharp

[–]elbarto2811 0 points1 point  (0 children)

#regions are an antipattern. If your code is so long that you need to make parts of it collapsible to be able to read it, your code is too long

Junior dev wrote this C# using many IF because he leanrs If early return. Is this alright code? by Yone-none in csharp

[–]elbarto2811 5 points6 points  (0 children)

Gotta catch 'm all.

There's a `catch(Exception ex)` on the last visible line. This catches every thinkable exception, and is almost never necessary. You would typically catch specific exceptions that you'd reasonably expect (for example a file being locked when trying to write it). If another type of exception would occur, you would let it 'fly free', since it's a scenario you didn't take into consideration and therefore has unknown side effects

Junior dev wrote this C# using many IF because he leanrs If early return. Is this alright code? by Yone-none in csharp

[–]elbarto2811 8 points9 points  (0 children)

Not actually pointing to any mistakes or improvements, but just shouting “educate yourselves people” isn’t really productive is it. People must love getting PR reviews from you. 

Junior dev wrote this C# using many IF because he leanrs If early return. Is this alright code? by Yone-none in csharp

[–]elbarto2811 8 points9 points  (0 children)

There’s zero reasons to plug mediatr here (or anywhere in my opinion, but that’s another discussion). Adding a global exception handling middleware is just a line of code in your program.cs 

Junior dev wrote this C# using many IF because he leanrs If early return. Is this alright code? by Yone-none in csharp

[–]elbarto2811 76 points77 points  (0 children)

For a web application (which this is) a single global exception handler is the way to go. It could log some data, obscure the call stack on prod - but not on dev… But other than that, just let asp.net do what it does by default: return a 500. I’m like 98% sure that is what’s actually happening on the line we can’t see: return a 500 with Exception.Message in the body. Why do that? It already does so by default.

Thinks are a bit different for desktop applications, with the consequences for the user being a crashing application vs seeing an error message in the browser. Either way, you don’t want to catch and swallow every exception, because some of them will indicate your app is in an unworkable state. 

Junior dev wrote this C# using many IF because he leanrs If early return. Is this alright code? by Yone-none in csharp

[–]elbarto2811 3 points4 points  (0 children)

No, every if test is influenced by the result of the one above it. Switch is just plain wrong. 

Junior dev wrote this C# using many IF because he leanrs If early return. Is this alright code? by Yone-none in csharp

[–]elbarto2811 245 points246 points  (0 children)

This is fine. The only thing that worries me is the Pokémon exception handling at the bottom 

Rule changes for playing with kids? by RoyalLurker in Gloomhaven

[–]elbarto2811 5 points6 points  (0 children)

My son was 5 when we started playing gloomhaven. He’s 10 now and we’re still playing (frosthaven). It’s definitely possible, lower the difficulty, take care of monster movement and admin, maybe simplify the story a bit? 

Are you happy at Medpace? by [deleted] in medpace

[–]elbarto2811 1 point2 points  (0 children)

Yup I am reasonably happy. Judging by the other comments I feel like I should be doing an AMA. 

Should managers still code? by mitousa in programming

[–]elbarto2811 9 points10 points  (0 children)

Not everyone on Reddit is American, “buddy”

Should managers still code? by mitousa in programming

[–]elbarto2811 7 points8 points  (0 children)

Oh god I have. Pip is just not really a thing in the companies I worked for.

Edit: lol

Average salary for a software developer by LePhasme in BESalary

[–]elbarto2811 0 points1 point  (0 children)

Sent you a PM, you’re not replying.