473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Attribute Naming Confusion

HI

I am trying to understand Attribute usage. For example the class
SerializableAttribute 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 AttributeUsageAttribute class and on and on. I don't get it.

Gary

Jun 11 '06 #1
2 1699
"ga**********@gmail.com" <ga**********@gmail.com> wrote:
I am trying to understand Attribute usage. For example the class
SerializableAttribute 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 AttributeUsageAttribute 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.com...
"ga**********@gmail.com" <ga**********@gmail.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
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...
3
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...
10
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: ...
6
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...
114
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...
35
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...
8
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...
1
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...
5
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? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.