473,594 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attribute Naming Confusion

HI

I am trying to understand Attribute usage. For example the class
SerializableAtt ribute is a class correct? So why when it is actually u
sed the "Attribute" portion of the name is dropped. The sam is true of
the AttributeUsageA ttribute class and on and on. I don't get it.

Gary

Jun 11 '06 #1
2 1722
"ga**********@g mail.com" <ga**********@g mail.com> wrote:
I am trying to understand Attribute usage. For example the class
SerializableAtt ribute is a class correct? So why when it is actually u
sed the "Attribute" portion of the name is dropped. The sam is true of
the AttributeUsageA ttribute class and on and on. I don't get it.


There are two sides to look at: those who use attributes, and those who
write their own attributes.

When an attribute user places an attribute on an element, he or she
doesn't have to specify the "Attribute" part. This reduces typing on the
attribute user's part, and increases code clarity. Because every
attribute ends in "Attribute" , the "Attribute" part is redundant.

For those who create attributes, they usually want something short and
snappy that has a high degree of relevance to what they're placing the
attribute on, but they don't necessarily want to require the attribute
users to qualify the namespace explicitly (since that would make
attribute usage quite wordy). This runs the risk of polluting the global
namespace with short identifiers. To prevent this, they usually follow
the convention that the attribute shall have the word "Attribute"
appended to it. (It isn't necessary for attributes to follow this
convention, but it is recommended.)

For example of what I mean by short and snappy, consider these
attributes defined as part of .NET:

---8<---
Flags
Obsolete
Serializable
Conditional
Obfuscation
OnSerializing
OnSerialized
OnDeserializing
OnDeserialized
Guid
In
Out
Optional
Discardable
Dependency
Security
Context
OneWay
Proxy
Soap
Synchronization
Url
--->8---

These attributes listed here are without their "Attribute" extension, to
illustrate how short and potentially ambiguous they could be without the
"Attribute" suffix convention. For example, somebody new to the
framework could easily mistake an "Url" type as representing the same
thing that "System.Uri " represents, and not recognize it as an attribute
type, and similarly for Guid. What would the newcomer make of a type
named "Proxy"? Wouldn't they think it actually represented a Proxy?

Another way of looking at these things is that attributes are usually
either nouns or adjectives that qualify whatever they are placed on. If
the attribute takes parameters in its constructor, it's typically a noun
which is logically becomes a kind of property of whatever it's attached
to. If the attribute doesn't take parameters, it often ends up being an
adjective.

The thing is, classes are usually given noun-based names too. But an
attribute noun that is logically a property of some reflection element
is something quite different from an actual class, which is meant to be
instantiated and manipulated.

Therefore, it makes sense to keep the two in separate namespaces. This
permits overloading of names where appropriate, but also prevents
conflicts. There usually isn't a risk of ambiguity, since the shortened
attribute names can only occur in a limited context, between '[]'.

The namespace separation comes about by the convention of adding
"Attribute" . This creates a namespace separation without forcing
explicit namespace qualification to resolve ambiguities.

-- Barry

--
http://barrkel.blogspot.com/
Jun 11 '06 #2
"Barry Kelly" <ba***********@ gmail.com> wrote in message
news:ts******** *************** *********@4ax.c om...
"ga**********@g mail.com" <ga**********@g mail.com> wrote: The namespace separation comes about by the convention of adding
"Attribute" . This creates a namespace separation without forcing
explicit namespace qualification to resolve ambiguities.


Which of course is the way we used to create namespaces before there were
explicit language constructs. Interesting.

///ark
Jun 11 '06 #3

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

Similar topics

4
8396
by: VK | last post by:
09/30/03 Phil Powell posted his "Radio buttons do not appear checked" question. This question led to a long discussion about the naming rules applying to variables, objects, methods and properties in JavaScript/JScript and HTML/XML elements. Without trying to get famous :-) but thinking it would be interesting to others I decided to post the following summary: 1. Variable names in JavaScript/JScript
3
3838
by: Brian | last post by:
Hello: I saw the following the other day in the id attribute of a div tag and was wondering if it had any special meaning. Here is the example: <div id=tag200\top\level_1\level_2>Blah...</div> Basically I am trying to understand if the slash character influences the resulting DOM in some way. I can see where *maybe* the slashes might create a hierarchy of some sort. It could also just be a naming
10
1637
by: Allan Ebdrup | last post by:
We have a developer who has defined our vraiable naming conventions, He has defined that variables should benamed the same as the class they are an instance of, for example: Syste.Xml.XmlDocument XmlDocument; I find this a very bad idea as you might get confused about what XmlDocument is, a variabel or a class. Do any of you have some good arguments for or against such a naming convention? Would it be possible to actually make...
6
1073
by: Michael | last post by:
Hi, What is the naming convention in .NET when it comes to naming a variable like "StudentID"? Is it "StudentID" or "StudentId"? For variable like "myHtml", I know the "HTML" part must be "Html". But there is some confusion when it is only 2 characters, like in "ID". Is is "ID" or "Id"? Not very important, but I would like to know what is the suggested Microsoft
114
7810
by: Jonathan Wood | last post by:
I was just wondering what naming convention most of you use for class variables. Underscore, "m_" prefix, camel case, capitalized, etc? Has one style emerged as the most popular? Thanks for any comments. --
35
12165
by: Smithers | last post by:
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.
8
2284
by: mrashidsaleem | last post by:
Can anyone guide me what is wrong with the naming conventions suggested below? I know that this is not recommended by many (including Microsoft) but I need to know what exactly is the rationale behind going for a different convention in .NET. The recommendations do make sense (to me, at least but I may be wrong and would like someone to correct me). Scope Prefixes Member Variable Prefix: Most of the people still use (and like the idea...
1
1979
by: chris.bahns | last post by:
Hello All, I am fairly new to creating custom attributes, and want to get a better feel for how they should be named. We have a class hierarchy, with a base class called "SequenceCommand". This class has a couple static functions and an embedded class, all of which are referenced in code like "SequenceCommand.Create()" or "SequenceCommand.ArgumentDef". There is also a fairly rich hierarchy of classes under it (maybe 10-15 intermediate...
5
1326
by: laredotornado | last post by:
Hi, I have a number of INPUTs on my page that look like <input id="form_items" name="form_items " size="15" type="text" value="..." /> How do I refer the last one of these on my page? Thanks, - Dave
0
7946
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
7877
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
8253
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
8374
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
8009
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
3867
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1482
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.