Dang Tran said:
Hi C# Learner:
I'm too a fresh learner of C#. At first, I appreciate your all help for my
question. Finally, I'd like to contribute my thought to the on-going fight.
C# or any kind of language, in my mind, is simply a tool which should be
used to clearly state functions of the project. Hence, I believe that it
should not confuse reader by any assumption. I previosly asked the question
about the scope of a variable whose scope is not clearly define. I was
confused and had to guess its scope.
No, you *didn't* have to guess its scope. You should never *guess* what
the language will do, and you don't have to. That's what the language
specification is for.
I think the guessing is the most
dangerous thing in software development.
Agreed.
If we misunderstand the functionality of any variable, function, we'll face
a huge problem later on in Testing phase.
Again, agreed. That's why when you see something that you're unsure of,
you should consult the language specification. You can then decide
whether to adopt the omission of the access modifier as part of your
coding style or not.
There are some times where redundant specification is good - extra
brackets (and spaces!) can do wonders for readability in complicated
lines of code, for instance.
In this case, however, I feel *every* respectable C# developer should
know the default access, especially as it's a single easy-to-remember
rule: the default access is always the most restrictive one you can
specify in that situation.
Given that, I believe it makes code clearer to omit the default access
specifer as it then makes it more obvious when you've got a member
which deviates from that most restrictive access. Making things
accidentally *more* restrictive than you intend pretty much always has
far less worrying consequences than making something accidentally
*less* restrictive than you intend.
I hope that my opinion is not incorrect. However, C# learner, you have your
point. As long as we feel comfortable about our coding style, we are doing
fine, aren't we?
On that, I disagree. People may feel comfortable with non-thread-safe
code, and never find out it's problematic until they have a customer
with a multi-processor machine, etc.
There are things where there are valid differing opinions - and the
issue of specifying private access is one of them, I feel. There are
other areas where code readability more obviously suffers (usually due
to laziness) and there it's worth getting into good habits.