Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
What... Lmao, for me getting back to C# feels like finally getting down from a plank, to a solid, stable ground.
-
@theabbie that is how you learn telepathy!
I don’t dislike c#, I dislike c# devs doing stuff like tryGet.
If it’s null -> you failed to get
No need to abuse an out parameter -
@piratefox tryGet should be error handling (and not null checking) and would be pretty much this:
bool tryGet(int id, out object obj){
try{
obj = get(id);
return true;
}
catch{
//some error handling
}
return false;
}
The reason is that in C# we like error handling by throwing exceptions. -
@Eklavya yeah, it's missing the ability to write any random disgusting incomprehensible bullshit while high on heroine and have it "run" without it actually properly informing you what it did and why, if anything.
-
this is why i discourage people from learning js as their first language - when they then go to any other, it's like a 5star restaurant cook complaining that barfing into platters is not an acceptable cooking method.
-
Never seen TryGet used in any C# project.
TryParse on the other hand is a very useful "this might be type X, convert if it is but don't incur the overhead of an exception I don't care about if it isn't".
Very helpful for parsing filthy user inputs. -
@kwilliams seen in a unity project. You can guess the quality by one sentence: “sure this way it’s unreadable, but it’s way faster as it’s one less operation! Assigning a variable is expensive!”
-
@saucyatom in that case I find more helpful something as tryOrDefault (passing an optional default value), but it’s just cause more examples come to my mind, I see why your example could be useful (e.g get an entry or ask the user to create a new one)
-
@piratefox Of course it depends what get() is actually doing. I just meant that tryX implies that it is functioning that way, like e.g. tryParse. xOrDefault has another implication. Both are useful in their own way and for different things.
After javascript, coding in C# feels like I have to communicate with a deaf person with using only one hand. :D
rant