Gary Milton said:
During my many years of OO development, I have worked on a lot of different
projects with a lot of different people and I haven't spoken to anyone
(until now) who prefers to leave off the definition for default member
accessibility.
In many languages it wouldn't be appropriate - and in those languages I
would explicitly state the access. (Java has the unfortunate situation
where the default access *can't* be stated explicitly. This is
certainly something to be avoided in language design.)
IMO, code is without a doubt more structured and more
readable with clearly defined member accessibility against all members
regardless of whether or not they are using the default accessibility.
To me, it's still clearly defined. I never have to "guess" at the
accessibility - but with my scheme, non-private members leap out at me
more, which is exactly how I wish it.
Books are a generally good example to go by. If you take a look at any book
written by the professionals (and that includes the MCAD/MCSD ones), then
nowhere will you see code examples that omit the accessibility definition
for default access.
Not true. I've just picked up a random book off my bookshelf, and the
first page I turned to had an example where the private members don't
have the accessibility explicitly stated. I agree, however, that most
books do include the private modifier.
There may be general mention that this can be done but
they do not preach the use of doing so throughout their code examples.
No, but then frankly code examples in books are often far from great
examples anyway. They have public fields for the sake of code
simplicity, for example, where most people would suggest they should be
private with public property access instead.
In this case, it's also understandable that you might want to make
explicit in a book for relative beginners the access which you might
leave defaulted for those who are already comfortable with the
language.
Although nothing compares to real-world experience, books generally teach,
or at least try to point you towards the best practises in development &
coding and I have yet to see a book that shows code examples without
accessibility defined on all members. If you can show me a book where this
is the case then I would certainly be interested to see it.
The book I looked at before was Joe Mayo's "C# Unleashed".
Of course, everyone has their own personal preference in coding methodology
and I respect yours and everyone else's opinions on this but at the end of
the day we have to accept that we have differing views on this particular
subject and leave it there.
If everyone agreed with each other all the time and had the same opinions
then the world would be a very dull place :-(
I'm happy to accept it's a personal preference - but I do take issue
with your statement that it's bad practice.