Form Naming Convention

  • Thread starter Thread starter Smithers
  • Start date Start date
S

Smithers

Is it common practise to begin the name of form classes with "frm" (e.g.,
frmOneForm, frmAnotherForm).

Or is that generally considered an outdated convention?

If not "frm" what is a common or recommended practise?

Thanks.
 
That is an outdated convention.

Class names in .NET should begin with a capital letter, and there should be
no abbreviations.

I'm not sure if there is a recommended practice of having any sort of prefix
in the name of a form.
 
Smithers said:
Is it common practise to begin the name of form classes with "frm" (e.g.,
frmOneForm, frmAnotherForm).

Or is that generally considered an outdated convention?

If not "frm" what is a common or recommended practise?

One possible convention:

Use the suffix 'Form' for all forms typically shown using their 'Show'
method and the suffix 'Dialog' for forms typically shown by calling their
'ShowDialog' method (samples: 'MainForm', 'AboutDialog', 'SettingsDialog').
 
Herfried K. Wagner said:
One possible convention:

Use the suffix 'Form' for all forms typically shown using their 'Show'
method and the suffix 'Dialog' for forms typically shown by calling their
'ShowDialog' method (samples: 'MainForm', 'AboutDialog',
'SettingsDialog').

LOL!

And how is that better than frmMain, fdlgAbout and fdlgSettings...?
 
Mark Rae said:
LOL!

And how is that better than frmMain, fdlgAbout and fdlgSettings...?

Mark, it actually isn't much better. It's only more compliant to the naming
guidelines chosen in the .NET Framework's class library. Nothing prevents
you from creating your own naming conventions.
 
Mark said:
And how is that better than frmMain, fdlgAbout and fdlgSettings...?

It complies with a published standard that I feel has more pros and
less cons than Hungarian notation.

Why do you think Hungarian notation is better?
 
Mark, it actually isn't much better. It's only more compliant to the
naming guidelines chosen in the .NET Framework's class library.

Which means not very much...
Nothing prevents you from creating your own naming conventions.

Or even using the ones I've used for the last 20 years or so...
 
It complies with a published standard that I feel has more pros and
less cons than Hungarian notation.

Such as...?
Why do you think Hungarian notation is better?

I've used it successfully for years and years.

It's *really* easy to understand.

It's *really* easy for other people to understand.

The prefix notation groups all my objects together according to type.

It makes my life easier.

It allows me to work more efficiently.

Microsoft themselves bought into it hook, line and sinker (or, at least,
Stan Leszynski's version of it) until relatively recently when someone took
a bit of a disliking to it for no logical reason, AFAICS...
 
Mark said:
And how is that of any use to me...?

Last I checked, even obnoxious guys with slow websites in North London
used the same First name / Last name convention that we do here.

So, an IndividualGroup naming convention feels natural. You look at
it, and right away see how it stands out; you read the whole thing and
see which group it belongs to. In most cases, this is exactly what you
want. You may want to know that you are reading a button's Text
property (after all, that's a lot slower than reading a normal
(field-backed) property) but *which* button is usually more important.
 
Mark Rae said:
Which means not very much...

It means quite a lot if your goal is to maintain conformance to the naming
standards other .NET developers are using. Whether you believe it or not,
that *is* a perfectly valid goal, and one shared by a wide variety of
people, especially when dealing with the names of elements of their code
that are exposed for reuse by third parties in the context of .NET.
Or even using the ones I've used for the last 20 years or so...

True enough. What does that have to do with this thread though? The
original poster asked what the "common" or "recommended" practice is, not
what you've been doing for the last 20 years or so.

Pete
 
Mark Rae said:
I've used it successfully for years and years.

As have many of us. That doesn't make it better. It just makes it
different.

That said, you haven't been using it correctly if you name your *class*
"fdlgAbout". Lower-case type tags are for variables, not type names.
It's *really* easy to understand.

Perhaps for you. I didn't find it too hard either. But I certainly have
run into my share of people who have trouble with it. I have spent more
than my share of time in a variety of development teams trying to explain
the correct use of Hungarian to my fellow developers.
It's *really* easy for other people to understand.

See above.
The prefix notation groups all my objects together according to type.

How does it do that? Where do your objects get grouped together according
to type? Why can't you just group them that way by typing them in the
correct order in the first place? And what if you would rather your objects
get grouped together according to some other characteristic.
It makes my life easier.

It allows me to work more efficiently.

All good reasons for you to use it. That has nothing to do with the
original question, nor does it justify your derision of the various replies.
Microsoft themselves bought into it hook, line and sinker (or, at least,
Stan Leszynski's version of it) until relatively recently when someone
took a bit of a disliking to it for no logical reason, AFAICS...

Well, first of all, Microsoft's public APIs have never truly complied with
Hungarian. It's always been a sort of bastardized version, in which much of
the semantic benefits of Hungarian have been removed.

Secondly, there's nothing in the .NET naming conventions that specifically
precludes the use of Hungarian. As I note above, naming a *class* something
like "fdlgAbout" is NOT correct Hungarian notation. A class name like
"About" or "AboutDialog" would be perfectly reasonable Hungarian, and is
also fine for .NET. Specific object instances (locals, parameters, fields,
etc.) are only slightly more problematic and the recommendation for those
(http://msdn2.microsoft.com/en-us/library/ms229004.aspx) are vague enough
that one could use Hungarian notation and still appear to comply with the
spirit of the .NET guidelines.

Finally, the guidelines are just that. Guidelines. They are intended to
enhance code reuse by ensuring that people writing .NET components to be
shared with others all follow a consistent naming convention. And they do
accomplish that. If you never intend to share your code with anyone else,
there's absolutely no reason for you to use a naming convention other than
the one you think is most appropriate.

Your snobbery is entirely out of place here, and not constructive at all.
There are a wide variety of equally useful naming conventions. It's more
important to have *some* naming convention than that the naming convention
be some specific convention. In this case, the .NET naming convention isn't
the one you're familiar with. So what? It doesn't make it worse than the
one you're using...it just makes it different. If you don't like it, don't
use it. It's as simple as that. All of your negative commentary is
unnecessary and irrelevant.

Pete
 
You can all just ignore Mark Rae. He has a long history in these NGs for
being irrational and emotional... exuding the kind of resentment commonly
found with those passed over for promotion or recognition many times (yet
still in search of that all-elusive "atta-boy" - undeserved as it may be).

Rather than letting Mark derail this thread, I certainly would have
appreciated a few more ideas for what you all are *actually* doing for your
naming conventions currently. I guess this is another case where people
don't really want to say what they *actually* do because of emotional guys
like Mark Rae criticizing.

Hey Mark - relax, man!
 
I use the convention of using Form on the ends of my forms, or
Dialog if it's a dialog, like SettingsDialog, AboutDialog,
ProductForm, etc.

If you have both web forms and windows forms, you can call
them ProductWin and ProductWeb (I think that's the convention;
I don't do web stuff, so can't attest to that for sure).

For controls, everything I've read recently said to name them
with pascal casing and the control type on the end, but the
names seem awfully long to me. ProductNameTextBox seems like
a lot of letters to type. I, also, would be interested to
learn what others are using for their controls.

Robin S.
 
Smithers said:
You can all just ignore Mark Rae. He has a long history in these NGs for
being irrational and emotional...

Hmmm...maybe he doesn't post in the C# newsgroup much? I hadn't noticed him
as being one of the "usual suspects". Oh well...maybe that's the risk of
cross-posting like you did. :)
[...]
Rather than letting Mark derail this thread, I certainly would have
appreciated a few more ideas for what you all are *actually* doing for
your naming conventions currently.

Well, if that's so then I'd suggest you might have been more clear in your
original post about that. I certainly didn't get the impression that you
wanted personal coding habits, and as near as I can tell the question you
actually asked has been answered already.
I guess this is another case where people don't really want to say what
they *actually* do because of emotional guys like Mark Rae criticizing.

No, it's just another case of a person asking a different question than the
one they really want the answer to. I'm perfectly comfortable with my
naming conventions, even as they continue to be revised over time in
response to a variety of factors, including who I'm coding with, what
language I'm using, and what mood I'm in when I start a project. It
wouldn't bother me at all for someone to criticize something like the naming
convention I use when coding.

As far as what I actually do in C#, I don't have a good answer, as I've only
been doing C# stuff for a year. It's way too early for me to have developed
any solid philosophies on naming conventions specifically for .NET. As it
happens, I do like and use Hungarian and so much of the conventions I use
doing C# code is based on that. Initially, I *only* used Hungarian but then
as I started inheriting from existing .NET classes, that started to result
in some less-than-pleasant-looking juxtapositions where my own methods and
properties showed in various places next to the .NET-style ones.

So lately I've been experimenting with conforming more closely to the .NET
style when writing properties and methods. For the methods, the main
difference here is I have switched from using "F" as the first letter in a
method that returns a boolean value to using the "Is" construct, because
inclusion of the "Is" still makes it clear that I'm dealing with a boolean.
For other methods that return a value, I continue to use the Hungarian-style
notation to ensure that the type return value is clearly noted in the method
name. For properties, I have taken to sticking with a simple descriptive
name rather than including any type information, and for any methods that
are implementing functionality that already has a standard naming convention
within .NET (Dispose, Close, OnPaint, etc.) I use the .NET standard even
when it's not strictly necessary (obviously in some cases there's no
choice).

Within a class, I continue to use Hungarian. Field names, variables,
parameters, etc. all get Hungarian style type tags and suffixes (Min, Mac,
Cur, etc.). And I use the convention of putting an underscore to start the
name of any non-public entity.

As far as the type tags go, to a certain extent my use of Hungarian is
simply so that I don't get out of the habit. One of the primary arguments
in favor of Hungarian comes from languages like C or C++ where you may have
defined types that are simply duplicates of some existing built-in type. In
the absence of strict type checking, Hungarian allows one to review the code
and more easily detect type mis-matches. Even in .NET/C# this still comes
up though. For example, I use "x", "dx", and "cx" as variations on an
x-coordinate for a type tag, each with their own specific meaning (absolute
coordinate; delta, always used in relation to some absolute; and a count,
respectively). This is because there's no coordinate type; everything still
uses ints and so there is still the potential for a semantic type mis-match
that the compiler doesn't catch.

But mostly, C# is a very strongly typed language and so there's not really
as much need to worry about mismatching types as the compiler simply won't
let you do it. So I'd admit that in most cases, the Hungarian notation
doesn't serve any purpose. Of course, since it does still serve a purpose
in some very narrow-but-common situations, and since mixing Hungarian and
non-Hungarian doesn't look very nice (and is also prone to errors), that is
in and of itself a justification for using Hungarian.

You'll note that none of the above has anything to do with naming a class.
:) On that topic...

The "flavor" of Hungarian that I originally used involved coming up with
three- or four-letter names for types (with a comment with the type
declaration explaining the abbreviation). The actual type would be
upper-case while the type tag would be exactly the same except lower case.
This was really nice for coming up with and interpreting type tags, but you
often got a lot of similar-looking types, and anything that wasn't
ubiquitous in code risked being misunderstood.

It did have the advantage though that types and variable names were short
and easy to type. It kept the code nice and concise, and it was much
quicker to type code in.

Now with Visual Studio's context-sensitive typing expansion
("intellisense"?), the fact that a type name is lengthy doesn't slow me down
since I almost never have to type the whole thing out anyway (I get really
annoyed when I have to do something in C++ now and don't have the code
editor filling things in for me :) ). So where I used to write something
like:

typedef class DataPerClient
{
...
} DPC, *PDPC, **PPDPC;

using the DPC, PDPC, and PPDPC for declarations and the lower-case versions
for the actual variable, I now just use the "DataPerClient" typename in C#
(and of course, since the concepts of pointers and pointers to pointers has
been covered with a veneer enforced by the language, I don't bother with
anything but the base type in C#). I also don't include base type
information if it's reasonably clear from the name of the class what the
base type or intended variant (such as the "XyzForm is modeless, XyzDialog
is modal" convention) is (which, though I didn't realize it initially, turns
out to be acceptable under the .NET naming guidelines).

Note the initial capital letters, lower-case for each individual word in the
class name. I was using that for my class names long before .NET showed up,
and it's been a fairly common convention for that time as well. It's not
much of a surprise that the .NET guidelines recommend the same thing.

So, does *that* answer the question you meant to ask? :)

Pete
 
Back
Top