Styled Text Control - Properties vs. Functions

Hello,

E.g. the styled text control has a property Text to either retrieve or set the text

in the current control but some could also use the functions GetText() or SetText(text)

to do the same.

Is there some advantage/disadvantage using functions instead of properties

or is it just there to satisfy developer preferences?

Hm, while writing these lines I might see an advantage using properties instead of functions.

When the function itself changes, let’s say an additional parameter has been added,

and this change can be handled by the framework itself there is no need for changing the property.

But on the other hand if using a property it might be slower in code execution than using the function.

Some insights?

Thank you

Hubert

Personal preference. Properties are called “syntactic sugar”, in
that they do not provide any added functionality; they just let you
write things in a way that might seem more natural. When you use
the Text property, you are actually calling the GetText and SetText
methods. It’s just being hidden from you.
Not really. If the developer decides that GetText needs a
parameter, then to avoid messing with existing code, he’s going to
provide a default for the new parameter. As I said, when you do
this:
xxx = std.Text
you are actually calling
xxx = std.GetText()
If GetText changes, then the property no longer works.
Any speed difference is absolutely trivial.

···

Hubert Mayr wrote:

E.g. the styled text control has a property Text to
either retrieve or set the text

      in the current control but some could also use the

functions GetText() or SetText(text)

to do the same.

      Is there some advantage/disadvantage using functions

instead of properties

or is it just there to satisfy developer preferences?

      Hm, while writing these lines I might see an advantage

using properties instead of functions.

      When the function itself changes, let's say an additional

parameter has been added,

      and this change can be handled by the framework itself

there is no need for changing the property.

      But on the other hand if using a property it might be

slower in code execution than using the function.

-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com

Again, thank you very much.

···

On Monday, June 13, 2016 at 7:36:52 PM UTC+2, Tim Roberts wrote:

      Hm, while writing these lines I might see an advantage

using properties instead of functions.

      When the function itself changes, let's say an additional

parameter has been added,

      and this change can be handled by the framework itself

there is no need for changing the property.

Not really.  If the developer decides that GetText needs a

parameter, then to avoid messing with existing code, he’s going to
provide a default for the new parameter. As I said, when you do
this:

    xxx = std.Text

you are actually calling

    xxx = std.GetText()



If GetText changes, then the property no longer works.

Of course, why should one do the work twice - should have thought about it.

Thank you

Hubert