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
-
@lambda123 there ARE good potential reasons for that, though. like creating an instance of the whole application to use in automated e2e-tests.
-
Leading underscore for private readonly fields.
Anything else and the PR is getting rejected. -
Nihil757552yinteresting.
New to C#, coming from Python, I place underscore for local vars (i.e func input params).
Am I the worst? -
@Nihil75 Nope, its just a deprecated practice (at least most of the C# devs I met agree with this, not sure of the community as a whole)
-
Agree. We have stopped using Hungarian notation for a reason.
I also hate C#'s capitalization convention.
Almost everything is capitalized. Types, namespaces, generics, properties, public variables, methods, enum cases. There is no clear rule or reasoning behind why something is capitalized or not. It’s completely arbitrary. -
@lambda123 You "hate" that it allows you freedom to code however you want?
Really?
Is it the language's fault that someone does weird, uneccessary, complicated or downright wrong things with it?
Please name a language that doesn't allow you to do that. Including spoken languages.
Bad tradesmen blame their tools. Don't be a bad tradesman. Don't blame your tools. -
OP: for the record, I am not a big fan of underscores either. It looks ugly, but I have learned to ignore it. I am an eager user of keyboard shortcuts in VS, so most of the time they are declared for me.
-
@lambda123 Shit, you're right! I just re-read it now, I interpreted it the wrong way.
Sorry, my bad! 😖 -
Leading underscores are commonwealth metasyntax for "ignore" or "do not use"; names which are accessible due to limitations of the language's visibility system but weren't meant to be used by the majority of code which has them in-scope, which are planned to be used by future code, or which exist purely to satisfy language rules such as unused parameter names. Python's private properties are a good example. Does C# use them in any other way?
-
@lbfalvy in C# a leading underscore signifies it is a private member of the class (though C# is strongly typed, therefore this underscore is by definition superfluous)
What I mean is your editor shows and knows what are the private class fields so there is no need to add an extra character to show this.
Related Rants
I absolutely HATE the leading underscore in .NET variables.
I systematically destroy them 😈
rant
private variables
.net
.net core