Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

These two words are completely synonymous for me, but I wonder if there's actually a useful semantic difference that I can incorporate into coding/naming conventions/process.

share|improve this question
7  
In .NET they are completely different things. Property and Attribute – ChrisF Oct 4 '11 at 21:32
    
Your saying as a .net developer I'd be wise to only call something an attribute if it refers to an actual .NET attribute class.. yeah that makes sense. Thanks, – Aaron Anodide Oct 4 '11 at 21:34
2  
Entirely depends on context, as @ChrisF commented. – Oded Oct 4 '11 at 21:34
    
@DavidSchwartz There is no concept of a inter-site duplicate, and the answers on Stack Overflow aren't particularly useful. – user8 Oct 4 '11 at 22:53

Attributes represents the state of the object.

Properties are used synonymously as attributes but its depends on language. Properties are getters and/or setters which are invoked as we read it or assign it.

With properties , we can add error handling code to prevent the object to be in unsafe state.But we cant do the same with attributes as they are just meant to store some value.

ex:

her.age = -10;

// shes is in unsafe state as age cannot be negative

but if her.age is a property , it may check before assign new age to the attribute i.e. private one.

if(newAge >= 18) 

{ *// then do someThing..* }

else

{
  *// throw some exception*
}

// here newAge is arg to property age

Properties just execute some error handling code.

You can add custom code to it too.

share|improve this answer
1  
is this only your opinion or you can back it up somehow? – gnat Dec 11 '15 at 13:34

The English words have overlapping meanings but slightly different implications. Property implies something possessed by something else. Attribute suggests something that is an inherent characteristic.

However, because their meanings almost completely overlap, you can substitute one for the other. The exception would be where the terms are jargon, for example in C# where property and attribute have different, much more specific, meanings. In HTML, there is something specifically called a tag attribute and calling it a property would be confusing.

If you're inventing new jargon for a specific context, I would say to prefer whichever sounds more natural. If it's something discrete that something else contains, I'd generally prefer property. If it's something that is an inseparable inherent characteristic of something else (and especially if it's something other things can have as well), I'd generally prefer attribute.

share|improve this answer

The definition of Properties and Attributes are context sensitive based on the programming language/markup you're using.

In standard markup languages (XML, HTML, SVG, etc) an attribute is well defined

<xml version="1.0"> <!-- The attribute here is version -->

In other programming languages an Attribute is an object where a property is a stored value

public Attribute FirstName { get; set; } // C# Property which stores and returns an Attribute object :-D
share|improve this answer

protected by MichaelT Dec 12 '15 at 4:07

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.