473,800 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Namespace Qualification a Smell?

Hi, Group,

I know it says not to mess with the "code required for Designer
support" that the IDE generates when I work with things in the layout
editor, but I nevertheless find myself making changes along these
lines:

this.bMagnifier = new System.Windows. Forms.Button();
this.bMagnet.An chor = ((System.Window s.Forms.AnchorS tyles)
((System.Window s.Forms.AnchorS tyles.Top |
System.Windows. Forms.AnchorSty les.Right)));
this.bMagnet.Lo cation = new System.Drawing. Point(304, 176);

==>

bMagnifier = new Button();
bMagnet.Anchor = ((AnchorStyles)
((AnchorStyles. Top |
AnchorStyles.Ri ght)));
bMagnet.Locatio n = new Point(304, 176);

just so it's easier for me to read.

I realize that it's "safer" for the code generator to so precisely
qualify the items it refers to, and I'm not really quibbling about the
code it generates (maybe a topic for another post). But I'm starting
to consider such qualifications to be what XPers call a "smell" - an
indication that something is wrong about the code.

When I can strip off the qualification and everything still works fine,
that's great. But when - and this has happened in my own code, not
that built by the IDE - qualifications are _required_ for the code to
function properly, it is a clue to me that the function I'm writing
really belongs in another namespace, probably in a different class. Or
that my namespace map is somehow less than ideal - a class isn't where
it belongs, or has a bad name, etc.
In the immortal words of The Onion: What do you think?

Peace,
--Carl

Nov 16 '05 #1
7 1583
Carl,

Personally, I think there is a reason why they say not to mess with the
designer generated code, because you can break it! In this case, I don't
think there is anything wrong with what the designer is doing. As a matter
of fact, it's doing the ^right^ thing. The reason you get fully qualified
names is that it can't guarantee that the proper using statements will be in
the file the code is placed in, so it can't make assumptions about using
shortened type names.

Also, wouldn't just editing things in the designer just be easier? I
mean, if you want to hand edit code, that's fine, but the designer is there
specifically to make it easier to do these things, and not wade through
stuff like this.

Finally, in VS.NET 2005, you will notice that designer generated code is
kept in a completely separate file, so there should be no reason why you
^ever^ have to touch the stuff (ok, maybe no is too absolute, but it's
pretty darn close).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<ca***********@ gmail.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
Hi, Group,

I know it says not to mess with the "code required for Designer
support" that the IDE generates when I work with things in the layout
editor, but I nevertheless find myself making changes along these
lines:

this.bMagnifier = new System.Windows. Forms.Button();
this.bMagnet.An chor = ((System.Window s.Forms.AnchorS tyles)
((System.Window s.Forms.AnchorS tyles.Top |
System.Windows. Forms.AnchorSty les.Right)));
this.bMagnet.Lo cation = new System.Drawing. Point(304, 176);

==>

bMagnifier = new Button();
bMagnet.Anchor = ((AnchorStyles)
((AnchorStyles. Top |
AnchorStyles.Ri ght)));
bMagnet.Locatio n = new Point(304, 176);

just so it's easier for me to read.

I realize that it's "safer" for the code generator to so precisely
qualify the items it refers to, and I'm not really quibbling about the
code it generates (maybe a topic for another post). But I'm starting
to consider such qualifications to be what XPers call a "smell" - an
indication that something is wrong about the code.

When I can strip off the qualification and everything still works fine,
that's great. But when - and this has happened in my own code, not
that built by the IDE - qualifications are _required_ for the code to
function properly, it is a clue to me that the function I'm writing
really belongs in another namespace, probably in a different class. Or
that my namespace map is somehow less than ideal - a class isn't where
it belongs, or has a bad name, etc.
In the immortal words of The Onion: What do you think?

Peace,
--Carl

Nov 16 '05 #2
ca***********@g mail.com <ca***********@ gmail.com> wrote:

<snip>
When I can strip off the qualification and everything still works fine,
that's great. But when - and this has happened in my own code, not
that built by the IDE - qualifications are _required_ for the code to
function properly, it is a clue to me that the function I'm writing
really belongs in another namespace, probably in a different class. Or
that my namespace map is somehow less than ideal - a class isn't where
it belongs, or has a bad name, etc.
In the immortal words of The Onion: What do you think?


When you have to qualify things, it suggests that either you've named a
class the same as one of the ones in a namespace you've "used" (i.e.
got a using directive for) or you've "used" two namespaces containing
the same short class names.

It's worth trying to avoid framework class names if possible, IMO - but
there are duplicates within the framework already, particularly between
WinForms and WebForms.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Thanks, Nicholas,

But I like to mess around with my code. Like, extract and consolidate
all the creation, parameter setting, and adding-to-components-list for
one button into its own procedure, then call (eg) InitializeButto nFoo()
from InitializeCompo nents(). Then notice the (profound) similiarities
between InitializeButto nFoo() and InitializeButto nBar() and extract
their common functionality into InitializeButto n(which)...

Ultimately, then, I can create buttons in a nice, standard way, in
code, and if I want to make a change to all buttons (color, say) it's
just a one-line change.

Certainly sometimes I just leave the IDE-generated code alone, but
sometimes I want to make it my own. And my own doesn't have any more
namespace qualifications than it absolutely needs...

Peace,
--Carl

Nov 16 '05 #4
>>What do you think?

I think you'll be posting questions about why the IDE messed up your
precious code soon.

It says "do not modify the contents of this method with the code editor" for
a very good reason.

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

<ca***********@ gmail.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
Hi, Group,

I know it says not to mess with the "code required for Designer
support" that the IDE generates when I work with things in the layout
editor, but I nevertheless find myself making changes along these
lines:

this.bMagnifier = new System.Windows. Forms.Button();
this.bMagnet.An chor = ((System.Window s.Forms.AnchorS tyles)
((System.Window s.Forms.AnchorS tyles.Top |
System.Windows. Forms.AnchorSty les.Right)));
this.bMagnet.Lo cation = new System.Drawing. Point(304, 176);

==>

bMagnifier = new Button();
bMagnet.Anchor = ((AnchorStyles)
((AnchorStyles. Top |
AnchorStyles.Ri ght)));
bMagnet.Locatio n = new Point(304, 176);

just so it's easier for me to read.

I realize that it's "safer" for the code generator to so precisely
qualify the items it refers to, and I'm not really quibbling about the
code it generates (maybe a topic for another post). But I'm starting
to consider such qualifications to be what XPers call a "smell" - an
indication that something is wrong about the code.

When I can strip off the qualification and everything still works fine,
that's great. But when - and this has happened in my own code, not
that built by the IDE - qualifications are _required_ for the code to
function properly, it is a clue to me that the function I'm writing
really belongs in another namespace, probably in a different class. Or
that my namespace map is somehow less than ideal - a class isn't where
it belongs, or has a bad name, etc.
In the immortal words of The Onion: What do you think?

Peace,
--Carl

Nov 16 '05 #5
Hi, Bob,
What do you think?


I think you'll be posting questions about why the IDE messed up
your precious code soon.


:-) Not gonna happen. (the questions, not the messing up).
Peace,
--Carl

Nov 16 '05 #6
<ca***********@ gmail.com> wrote:
I know it says not to mess with the "code required for
Designer support" that the IDE generates when I work
with things in the layout editor, but I nevertheless find
myself making changes along these lines:
[snipped examples of removing namespace prefixes]
just so it's easier for me to read.
Why do you need to read the automatically generated layout code?
when [...] qualifications are _required_ for the code to
function properly, it is a clue to me that the function I'm
writing really belongs in another namespace, probably in
a different class.


Hm. This has only happened to me once, when I had a Location class
(representing a geographical location with a postal address) and a
Windows form to allow the user to create and edit locations. There was
namespace confusion because of the Location struct used for
positioning controls in containers.

I don't think it was architecturally wrong of me to want to use both
kinds of Location in a single class (form). It struck me more as a
shortcoming of the English language. Perhaps you have a better example
than mine...?

P.
Nov 16 '05 #7
Hi, Paul,
Why do you need to read the automatically generated layout code?
To abstract out common functionality, chiefly - but, well, just to
understand what's going on in my own program. To make it mine.
I don't think it was architecturally wrong of me to want to use both
kinds of Location in a single class (form). It struck me more as a
shortcoming of the English language. Perhaps you have a better
example than mine...?


I have a specific example, but it's a general question; here's the
example if it helps.

I have an indirect subclass of System.Windows. Forms.Form, and I've
placed it in its own namespace ("Info") and called it "Form".
Duplicating (against Jon's advice) the library name. My rationale is
that, within the Info space, this is the only Form I want to refer to,
and any linguistic games I might play to get around that fact
("Info.InfoForm ", "Info.Form_ ", "Info.SpecialFo rm", "Info.MyFor m",
etc.) are - well, not pretty.

But an Info.Form's role is to peek at other forms and say something
about them, so I found myself iterating over the other
System.Windows. Forms.Form(s), and initially wound up with a typecast
bug as I tried to treat each of them as just Form(s), which of course
meant an inadvertent and erroneous typecast to an Info.Form. Which I
initially solved by adding the namespace qualification. But needing to
do that suggested to me that the code, in Info.Form, where I was
iterating over all Forms, actually belonged somewhere else. Or I
should have found another name for Info.Form, or something - a smell,
as I said in the initial post.

Peace,
--Carl

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
3523
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example using std::cin; using std::cout;
7
7440
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; com.unFocus.Namespaces = new function() { this.register = function(namespace) { namespace = namespace.split('.');
21
6370
by: Bilgehan.Balban | last post by:
Hi, I have two different enum definitions with members of same name. The compiler complains about duplicate definitions. Is this expected behaviour? Can't I have same-named fields in different enum definitions? I think it should have been perfectly valid to do that. Its a stupid limitation to have to define disjoint enum symbol definitions. This is like having to have disjoint member names in structures.
13
18162
by: toton | last post by:
Hi, I have some enum (enumeration ) defined in some namespace, not inside class. How to use the enum constant's in some other namespace without using the whole namespace. To say in little detail, the enum is declared as, namespace test{ enum MyEnum{ VALUE1,VALUE2 };
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.