digitalmars.D.learn - property usage
- uri (4/4) Dec 04 2014 Hi All,
- Rikki Cattermole (5/9) Dec 04 2014 When it makes sense I use it.
- uri (6/18) Dec 04 2014 Thanks for the examples. As always I found what I needed just
- ketmar via Digitalmars-d-learn (9/10) Dec 04 2014 i'm using it alot for the things that looks like properties. ;-)
- Jonathan M Davis via Digitalmars-d-learn (10/12) Dec 06 2014 @property is used rather freuently - e.g. some of the functions in the r...
- ketmar via Digitalmars-d-learn (11/25) Dec 06 2014 On Sat, 06 Dec 2014 15:23:10 -0800
- Nicholas Londey (4/6) Dec 08 2014 Does @property ever make sense for a free floating function? I
- ketmar via Digitalmars-d-learn (16/24) Dec 08 2014 On Tue, 09 Dec 2014 07:31:20 +0000
- Mike Parker (8/11) Dec 08 2014 I use it from time-to-time. I assume you think of properties as
- uri (4/11) Dec 09 2014 After a quick grep I see phobos uses quite a few free floating
- Joseph Rushton Wakeling via Digitalmars-d-learn (2/3) Dec 10 2014 http://dlang.org/phobos/std_random.html#.rndGen :-)
Hi All, Do you guys use property much, or is it largely ignored/avoided? Thanks, uri
Dec 04 2014
On 4/12/2014 11:21 p.m., uri wrote:Hi All, Do you guys use property much, or is it largely ignored/avoided? Thanks, uriWhen it makes sense I use it. https://github.com/Devisualization/window/blob/master/interfaces/devisualization/window/interfaces/window.d#L144 vs https://github.com/rikkimax/Dobol/blob/master/source/dobol/parser/dobol/parser/defs.d
Dec 04 2014
On Thursday, 4 December 2014 at 10:24:00 UTC, Rikki Cattermole wrote:On 4/12/2014 11:21 p.m., uri wrote:Thanks for the examples. As always I found what I needed just after posting: http://wiki.dlang.org/Property_Discussion_Wrap-up /uriHi All, Do you guys use property much, or is it largely ignored/avoided? Thanks, uriWhen it makes sense I use it. https://github.com/Devisualization/window/blob/master/interfaces/devisualization/window/interfaces/window.d#L144 vs https://github.com/rikkimax/Dobol/blob/master/source/dobol/parser/dobol/parser/defs.d
Dec 04 2014
On Thu, 04 Dec 2014 10:21:10 +0000 uri via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Do you guys use property much, or is it largely ignored/avoided?i'm using it alot for the things that looks like properties. ;-) the thing is looking like a property if it works almost as fast as accesing the field directly. i.e. does simple check or two, but doesn't calculate something heavy. that means that `area` for Rect is definitely a property, but `equalElementCount` for a single-linked list is not. i also using that alot to simulate read-only fields.
Dec 04 2014
On Thursday, December 04, 2014 10:21:10 uri via Digitalmars-d-learn wrote:Hi All, Do you guys use property much, or is it largely ignored/avoided?property is used rather freuently - e.g. some of the functions in the range API are required to be properties. Typically, property is used when you'd use a getter or setter in another language (or when you need to emulate a variable). Using get* or set* would generally not be considered idiomatic D and is not typically done. property functions are used instead. Now, because the parens are optional on functions with no arguments, there are plenty of cases where functions are called without parens when they're not properties, but property functions are quite common. - Jonathan M Davis
Dec 06 2014
On Sat, 06 Dec 2014 15:23:10 -0800 Jonathan M Davis via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:On Thursday, December 04, 2014 10:21:10 uri via Digitalmars-d-learn wrote:ngeHi All, Do you guys use property much, or is it largely ignored/avoided?=20 property is used rather freuently - e.g. some of the functions in the ra=API are required to be properties. Typically, property is used when you'd use a getter or setter in another language (or when you need to emulate a variable). Using get* or set* would generally not be considered idiomatic=Dand is not typically done. property functions are used instead. =20 Now, because the parens are optional on functions with no arguments, there are plenty of cases where functions are called without parens when they're not properties, but property functions are quite common.we all waiting for property enforcement fixes (which i already integrated, heh), so delegate properties can be used as propeties, omiting the annoying '()'. as this can break some invalid code (the code where people using properties as functions) i assume that we'll live with half-backed properties forever.
Dec 06 2014
as this can break some invalid code (the code where people using properties as functions)Does property ever make sense for a free floating function? I would have thought no but was recently asked to add it if using the function with uniform call syntax. https://github.com/D-Programming-Language/dub/pull/455#discussion_r21430311
Dec 08 2014
On Tue, 09 Dec 2014 07:31:20 +0000 Nicholas Londey via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:11 when you want to make a function that acts as getter/setter for delegate callback, for example. private void delegate () cb; property auto myCB () { return cb; } property void myCB (void delegate () newcb) { /* some checks */ cb =3D newcb; } this will work as expected when property enforcement will be fixed -- i.e. you will be able to omit '()' for calling delegate. alas, this is another thing that is "cosmetic", so PR with property enforcement will rot on github forever.as this can break some invalid code (the code where people using properties as functions)=20 Does property ever make sense for a free floating function? I=20 would have thought no but was recently asked to add it if using=20 the function with uniform call syntax. =20 https://github.com/D-Programming-Language/dub/pull/455#discussion_r214303=
Dec 08 2014
On 12/9/2014 4:31 PM, Nicholas Londey wrote:Does property ever make sense for a free floating function? I would have thought no but was recently asked to add it if using the function with uniform call syntax.I use it from time-to-time. I assume you think of properties as belonging to objects and not just something that is useful with UFCS. Keep in mind that free-floating functions belong to modules and modules (usually) belong to packages. These are units of encapsulation above classes & structs. There could be (and has been in these forums) lengthy debate about what constitutes a property and what doesn't, but whether or not a function belongs to a class or struct shouldn't enter into it, IMO.
Dec 08 2014
On Tuesday, 9 December 2014 at 07:31:21 UTC, Nicholas Londey wrote:After a quick grep I see phobos uses quite a few free floating property...as this can break some invalid code (the code where people using properties as functions)Does property ever make sense for a free floating function? I would have thought no but was recently asked to add it if using the function with uniform call syntax. https://github.com/D-Programming-Language/dub/pull/455#discussion_r21430311
Dec 09 2014
On 09/12/14 08:31, Nicholas Londey via Digitalmars-d-learn wrote:Does property ever make sense for a free floating function?
Dec 10 2014