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.
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
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.
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
In other programming languages an Attribute is an object where a property is a stored value
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.
// 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.
// here newAge is arg to property age
Properties just execute some error handling code.
You can add custom code to it too.
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 (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?