I sort of disagree with the take in "this". this is implicit for members so
one need not type it *except* when using an IDE with intellisense where
typeing "this.som" is way easier than typeing
"SomeLongMethodNameThatsEasyToMisspell". Having this. in a statement is not
hard to read and adds no overhead for the compiler.
Even though it's discouraged by the style-police I wholeheartedly agree with
the prefix of an underbar in private members because a program written in C#
that doesn't make use of the underbar for private members and relies only on
capitalization for the distinction between the member and the accessor
property is a complete pig to translate to VB.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Javaman59" <Ja*******@discussions.microsoft.com> wrote in message
news:FB**********************************@microsof t.com...
Hi, MM
Some of this can be addressed straight from Microsofts .Net guidelines...
http://msdn.microsoft.com/library/de...Guidelines.asp
I notice that some books, and web articles, use conventions which
contradict
the Microsoft guidelines. I don't know when the guidelines were first
published, but I think that it would make life easier for the whole C#
community if people were to always use them in new code, if they have a
choice to do so.
On to your questions...
class someclass
{
private datatype data1;
You should definitely use Pascal case for class names. This is almost
universal. ie. "class SomeClass". Similarly for any user defined types, ie
"DataType"
I personally have a bit of sypathy for the _ prefix to class members, and
some good authors use it, however the conventions say no, and most C#
coders
now avoid it.
"Do not use Hungarian notation for field names. Good names describe
semantics, not type.
Do not apply a prefix to field names or static field names. Specifically,
do
not apply a prefix to a field name to distinguish between static and
nonstatic fields. For example, applying a g_ or s_ prefix is incorrect. "
public someclass( datatype data1, datatype data2 etc)
{
this.data1 = data1;
this.data2 = data2;
That's exactly how most C# code does it (except for the upper-low case
anomolies I've pointed out).
but alot of modern texts seem to decry the use of 'this' to
prefix/access class memebers
They are quite correct. One rarely sees "this" in good code, except when
it
is needed to disambiguate identitiers (as in the constructor above).
and don't even seem to bother with explicit 'private'.
What's the 'norm' these days? Thanks!
Again, I agree with this, and I agree with Jon's argument for it.
Regards,
Javaman