Ask for C# programming styles?

G

Guest

Hi all,

I used to be a Delphi progammer and swithed to C# recently. I know c# is a
pure OOP language. But my main goal is developing database application. In
delphi, I could put some DBconnections and datasets etc, in a runtime
invisible form and they are automatically public visible to other forms. But
in Visual Studio .NET, it seems that I could not do it like in this way.
Although I know that I could set all variables to public (which default are
private) to pass them around forms as parameters or even make them public
static, I still wonder if Visual .NET could make this process automatically
and I simply don't know it yet.

Another question is where I can find some programming conventions for c#?
For example, name conventions for files, classes names and control names?

Thanks in advance!

Karl
 
C

clintonG

The state-of-the-art in architecture and design methodology is called Model
Driven Architecture (MDA) also referred to as Model View Controller (MVC).
There are apparently some differences in implementation when used with any
given framework. The emerging Service Oriented Architecture (SOA) is also
proving to be a widely accepted methodology.

Start by diving into MSDN and read till your eyes sting :)
Naming conventions and most everything else you need will be found there but
for the refinements found in the many blogs and of course this and related
newsgroups.
 
G

Guest

Karl,
If you need somplace quick and dirty to put your globals into, put them into
a public or protected class with public vaiables. Your entire project will
be able to see them, just like in your Delphi days or in VB. This is not a
great nor even recomended way of doing things, but if you need to get going
in a pinch, it'll do it for you.
 
B

Bob Powell [MVP]

Yes, start off badly, write code with little or no structure, generate as
much spaghetti as you can and when you're done you'll see the benefits of
correct program design.

But seriously folks...

Karl, don't use global variables. C# doesn't cater for them and people who
use odd techniques to sidestep this usually end up in pain.

My own personal programming conventions, for what they're worth, can be
found on my blog http://bobpowelldotnet.blogspot.com

--
Bob Powell [MVP]
Visual C#, System.Drawing

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.
 
D

Davids

on this subject...
why does everyone recommend not using Hungarian naming conventions in c# ? I
think it's very helpful!
 
G

Guest

Hi all,

Thank you for your wonderful advices on styles.

Still I have to make the first point straight. Because all the purpose of
dirty globles is to share them over forms (Not OOP thought). For example, if
I use private variable and create one atabase connection for each form, first
it is a kind of silly to me; second, if I forget to close the connection when
I switch to another form, I might run out of SQL server connection limits. So
I want to know that in C# database application, what is C# expert's
recommondation about where to put common used variables, such as DB
connections for sharing? And if Visual .NET IDE has some database form
similar to Diaphi?

Thanks,

Kai
 
C

C# Learner

Davids said:
on this subject...
why does everyone recommend not using Hungarian naming conventions in c# ? I
think it's very helpful!

advPersonally, proI vrbDislike adjHungarian nNotation. proI vrbFeel proIt
vrbMakes nThings adjHarder prpTo vrbRead.
 
J

Jon Skeet [C# MVP]

Davids said:
on this subject...
why does everyone recommend not using Hungarian naming conventions in c# ? I
think it's very helpful!

1) It's error prone - it's very easy for a variable to change type
later in a project, but not renamed.

2) Some people (myself included) find it drastically reduces
readability - the code no longer reads in pseudo-plain English.

3) When using an IDE, hovering over a variable name gives you much more
information - it gives the actual type, along with any comments you've
added to explain the use.

4) Names should give semantic meaning which can be much richer than a
small set of pre-defined prefixes.

5) With so many types, either you need to make the set of prefixes
*huge* (and thus cumbersome) or all kinds of things end up as objFoo
which is almost entirely useless.

Personally I can't stand Hungarian, and am very glad it's being
discouraged by MS.
 
R

Roy

The state-of-the-art in architecture and
design methodology is called Model
Driven Architecture (MDA)
also referred to as Model View Controller
(MVC).

Model Driven Architecture (MDA) new way of writing specifications and
developing applications, based on a platform-independent model (PIM).
A complete MDA specification consists of a definitive
platform-independent base UML model, plus one or more
platform-specific models (PSM) and interface definition sets, each
describing how the base model is implemented on a different middleware
platform. A complete MDA application consists of a definitive PIM,
plus one or more PSMs and complete implementations, one on each
platform that the application developer decides to support.

From: http://www.omg.org/mda/
 
O

Otis Mukinfus

1) It's error prone - it's very easy for a variable to change type
later in a project, but not renamed.

2) Some people (myself included) find it drastically reduces
readability - the code no longer reads in pseudo-plain English.

3) When using an IDE, hovering over a variable name gives you much more
information - it gives the actual type, along with any comments you've
added to explain the use.

4) Names should give semantic meaning which can be much richer than a
small set of pre-defined prefixes.

5) With so many types, either you need to make the set of prefixes
*huge* (and thus cumbersome) or all kinds of things end up as objFoo
which is almost entirely useless.

Personally I can't stand Hungarian, and am very glad it's being
discouraged by MS.

I second that!!!
Otis Mukinfus
http://www.otismukinfus.com
 
O

Otis Mukinfus

Hi all,

Thank you for your wonderful advices on styles.

Still I have to make the first point straight. Because all the purpose of
dirty globles is to share them over forms (Not OOP thought). For example, if
I use private variable and create one atabase connection for each form, first
it is a kind of silly to me; second, if I forget to close the connection when
I switch to another form, I might run out of SQL server connection limits. So
I want to know that in C# database application, what is C# expert's
recommondation about where to put common used variables, such as DB
connections for sharing? And if Visual .NET IDE has some database form
similar to Diaphi?

Thanks,

Kai

while(learning)
{
buyBooks();
read();
}

trySomeThings();

while(experimenting)
{
buyBooks();
read();
askQuestions;
}

Otis Mukinfus
http://www.otismukinfus.com
 
R

Ravichandran J.V.

As for naming conventions are concerned, the best naming convention is
that with which you are comfortable.

Some conventions you could consider are

1. Prefix the identifier with the data-type in small case
Eg - intScore, strName etc.

2. Use the Pascal naming convention (the default in C#) - the identifier
is in two parts as in "UserName", the first letter of the first word is
capitalized as is the first letter of the second word.

3. Use the Camel-casing convention (as in Java) (the default in VC#) -
the identifier is in two parts as in "userName", the first letter of the
first word is non-capitalized but the first letter of the second word is
not.


with regards,


J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
 
R

Richard Blewett [DevelopMentor]

I'd argue that the best naming solution is the one that makes your components look and feel like ones from the BCL. That means that people who use your components and maintain them will have familiar code to work with. You can see the guidelines that Microsoft publish here

http://msdn.microsoft.com/library/d...en-us/cpgenref/html/cpconnamingguidelines.asp

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

As for naming conventions are concerned, the best naming convention is
that with which you are comfortable.

Some conventions you could consider are

1. Prefix the identifier with the data-type in small case
Eg - intScore, strName etc.

2. Use the Pascal naming convention (the default in C#) - the identifier
is in two parts as in "UserName", the first letter of the first word is
capitalized as is the first letter of the second word.

3. Use the Camel-casing convention (as in Java) (the default in VC#) -
the identifier is in two parts as in "userName", the first letter of the
first word is non-capitalized but the first letter of the second word is
not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top