Talk:Property (programming)

Latest comment: 2 years ago by 42.190.201.161 in topic C++ properties

Negative of properties

edit

I would really like to see some mention of the negative of properties. In particular, the statement "properties provide a higher level of encapsulation than public fields" is really a stretch. Properties basically override encapsulation in the worst possible way. See, for example, http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/ — Preceding unsigned comment added by 99.226.116.206 (talk) 01:46, 12 July 2013 (UTC)Reply

I'm reluctant to make a really radical change - yet I can't really see the point to the "See also" section when there are links in the first pp. - Jon Shemitz 10:33, 11 September 2006 (UTC)Reply

Python example code issues

edit

The python example doesn't cause an exception as claimed: >>> pen.readonly = "Something Else" # this fails (raises an exception) >>> pen.readonly 'Something Else' >>>

Also it would be nice to be able to copy and paste the python directly into a python shell. Currently there are indentation errors if a direct copy-paste is done.

Thanks.

Thanks for testing it out, I have fixed both. -- 58.187.94.8 (talk) 07:21, 22 December 2007 (UTC)Reply

Language Support of Properties

edit

The article states

"Some object-oriented languages, such as C++ and Java, don't support properties, and require the programmer to define a pair of accessor and mutator methods instead."

I won't speak to C++, but Java has had a persistent properties API available since it's release.

java.util.Properties has been available since 1.0.

java.util.Properties is a class for storing configuration about a Java application, see .properties. From this article: "In some object-oriented programming languages, a property is a special sort of class member, intermediate between a field (or data member) and a method. You read and write a property just as you read and write a field, but this is (usually) translated to get and set method calls." -- nothing to do with configuration. 217.205.94.62 10:50, 12 September 2007 (UTC)Reply

What about Scala? Does it support properties (get/set, not this lib)? —Preceding unsigned comment added by 200.100.199.203 (talk) 04:08, 14 July 2010 (UTC)Reply

History

edit

Does anyone know who came up with the idea or what programming language first implemented them? Delphi was the first one I used that had them. I can't say that there wasn't something before that, however. --71.214.223.133 (talk) 19:50, 17 January 2010 (UTC)Reply

C++ properties

edit

The example given for C++ is short, but the code provided doesn't really offer support for getter and setter methods much less any additional stuff properties are good for.

  • The correct implementation of this (property class) is listed at CodeGuru, but this method is pretty RAM and CPU greedy.
  • A better, less RAM consuming method (using #define with subclassing) is listed at CodeProject
  • I myself have done some analysis and work on the subject and created a somewhat more complete implementation (also using the subclassing method) here. This sample also supports classes, containers and other complex types, which the above two samples do not. Additionally my implementation already declares a base property-enabled class (almost) equivalent to TObject in Delphi VCL - which was my goal.
  • Perhaps one should also mention Qt (framework) because their own preprocessor allows them to have properties supported very well.

Anyway, what I'm trying to say is that the sample provided doesn't really provide property functionality, it just strict-types the member. The above links provide much better functionality.

I also think these links should be mentioned in the C++ text with references to these pages so that the reader can be directed to proper solutions right away. The only reason I haven't done that myself is because I have "a personal interest" with my own implementation here.

Please discuss.

Velis74 (talk) 07:04, 20 March 2012 (UTC)Reply

Tried to copy/paste an example from Stack Overflow (Portability of Native C++ properties) but edit was blocked, so I just put a link instead. Can someone with higher privileges copy the code from https://stackoverflow.com/a/5924281 ? Ta. — Preceding unsigned comment added by 42.190.201.161 (talk) 22:03, 5 January 2022 (UTC)Reply

Definition For Non-Experts, First... Comparisons, Later

edit

The definition is very poor and doesn't help. First sentence: Defines property as been in between field and method, which are terms not necessarily known to the reader. Simply more confusing than clarifying... One comes with the question "what is a class property?", and the first thing you get is "go and get to understand these two other things (fields and methods)"... Second sentence: Again sets the qualification of Property as a function of Fields... And the definition continues along the same lines... 0_o

This is, for a non-expert, like going to check the definition for "Lake", and the definition starting "A lake is a body of water in between a sea and a swimming pool. Lakes are like sea in so that they have water, but lakes are usually not salty"

I'm sorry, but this is really my impression. I cannot help to define it better since I don't know what a Property is. — Preceding unsigned comment added by 87.144.106.246 (talk) 08:08, 14 October 2016 (UTC)Reply

Well, for starters, if you don't know what "field" and "method", then you will not understand anything in the article. And you are totally right writing "go and get to understand these two other things (fields and methods)". I am not saying the article is well-written. But you cannot start reading about advanced concepts without understanding basics (and "class", "field", "method" are the very basics here). Contrary to your example with "lake", "property is like field" is not so idiotic, if you know what "field" is.
That said, I tried to rephrase the intro a bit, bus still you have to learn more basic of object-oriented programming. Staszek Lem (talk) 17:48, 14 October 2016 (UTC)Reply
I understand that you took your time to provide this article for people, and that's great, but saying that I'm right when I say that your definition forces the reader to go to check another two concepts and that if I don't know about those things I shouldn't be looking here, is misunderstanding the scope of Wikipedia and the use people make of it.
Just like anyone, I've been reading articles on everything I feel appeal to, and this one was especially cryptic. There's no need to do a Degree in Physics to read about Quantum Mechanics and there should not be assumed any coding background from the reader that comes to the page. In fact, if you knew, you would come here to start with, would you?
Writing well is exactly about that - no matter what background your readers have, or how dumb they are, they should understand. Besides, I open my first "class" program in MatLab and the second word that I find is "Properties", so it's not a "so advanced concept" as to force the reader to learn other stuff before. In fact, for what I've discovered so far, it seems like class relates to property and methods, and it's field the one that goes a level down in the hierarchy - if this were the case, then your article confuses me (and any reader) even more.
Here, a try out:
A property, in some object-oriented programming languages, is a particular sort of class member. Properties have an intermediate functionality between a field (or data member) and a method. Using properties allows for data validation, active updating (e.g., of GUI elements), or implementation of what may be called "read-only fields". Properties use similar syntax to fields but its reads and writes, which are (usually) named as 'getter' and 'setter' method calls, are easier to read and write than many method calls. — Preceding unsigned comment added by 2003:45:596F:6622:5835:91F7:F188:9A46 (talk) 04:17, 19 October 2016 (UTC)Reply