Article View: borland.public.csharpbuilder.language.csharp
Article #217Re: Two basic questions
From: Joanna Carter [TeamB]
Date: Sun, 09 Jul 2006 20:02
Date: Sun, 09 Jul 2006 20:02
102 lines
4765 bytes
4765 bytes
"Bob Dawson" <RBDawson@prodigy.net> a οΏ½crit dans le message de news:
44b0539d$1@newsgroups.borland.com...
| 1. What are people generally using for a style guide? Two issues are
really
| puzzling me
You have already mentioned the MSDN guidelines that seem to be the "norm"
| a. Case sensitivity. As a long time non-case sensitive Delphi user, I
tend
| to hate code like
| ThisClass thisClass - new ThisClass();
| or property Something implemented with private field something, but that
| does seem to be widely accepted, and the idea of 'UpperCase means
| Class/Struct; lowerCase means instance' is at least a consistent standard
| (though how it explains Something/something escapes me), so maybe I could
| get used to it if I just gritted my teeth for a while.
In that case, ask Rudy to fit you a guard to protecty your teeth :-)
I have found that following the camel case convention for variables and
private fields makes for very easy reading, making it very obvious what is a
type and what is a value.
What can get a little confusing is when you get a property with the same
name as the type it represents. A common example is DialogResult which is a
type and the name of the property of that type !! This kid of thing can
sometimes be avoided, but even if it can't, you get used to using code
insight to get help on apparently ambivalent cases.
| b. Code organization. What rules have other Delphi folks adopted? In
Delphi
| for me it's always been private/protected/public, alphabetical within
| section, but I don't get a sense that there's any real concensus for the
| layourt of CSharp classes. What standards do people use to judge a
| well-organized class?
The common advice for this is to use private/protected/internal/public for
everything except methods which should be grouped according to functional
area.
Using regions is a great help and one use I make of them is to contain
something like an event and its related field/caller.
e.g.
public class PropertyBag : INotifyPropertyChanged, ....
{
....
#region INotifyPropertyChanged Members
private PropertyChangedEventHandler propertyChanged;
protected virtual void OnPropertyChanged(object sender,
PropertyChangedEventArgs args)
{
if (propertyChanged != null)
propertyChanged(sender, args);
}
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
{
add { propertyChanged += value; }
remove { propertyChanged -= value; }
}
#endregion
}
| I'm willing to give up my Delphi prejudices and write CSharp as
| CSharp--but the various style guiides I've read seem to vary quite a bit
in
| their recommendations. I wonder if a winner is emerging.
I feel that following the same style used in the MSDN docs for their
examples makes it a lot easier for those who will look back on your code to
understand it.
| (simple and narrow)
| 2. Most of the CSharp text I've looked at all explain that string is an
| alias for System.String, int is an alias for System.Int32, etc. And the
| advice is almost universally to use the CSharp aliases rather than the
built
| in System types. But nobody ever says why. So why? It bugs me especially
| since I'm trying to get used to the 'UpperCase means Class/Struct;
lowerCase
| means instance' rule, then told to use lower case alias for all the value
| types. Where's the consistency to that? grumble grumble <g>
I must admit I use the aliases, but I really couldn't say why I prefer them,
it just sort of feels better ?? :-) In any case, syntax highlighting marks
them as reserved words and I feel this can give quicker recognition of the
"system types"
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
Technical Details
Message-ID:
<44b160d9$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<44b0539d$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,dc12dddeb5f6ea0 X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII From: "Joanna Carter [TeamB]" <joanna@not.for.spam> Newsgroups: borland.public.csharpbuilder.language.csharp References: <44b0539d$1@newsgroups.borland.com> Subject: Re: Two basic questions Date: Sun, 9 Jul 2006 21:02:16 +0100 Lines: 104 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 NNTP-Posting-Host: 82.69.239.102 Message-ID: <44b160d9$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1152475353 82.69.239.102 (9 Jul 2006 13:02:33 -0700) X-Authenticated-User: jcarter Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail