digitalmars.D - byKey and byValue: properties or methods?
- Andrei Alexandrescu (8/8) Jan 16 2012 I hate I must ask this:
- Mail Mantis (3/4) Jan 16 2012 Can't find any arguments for either version, but subjectively I like
- Nick Sabalausky (4/10) Jan 16 2012 Property. It's not an action, you're just accessing a particular interfa...
- Nick Sabalausky (8/22) Jan 16 2012 Another way you can look at it to make it clear: As far as the caller is...
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (11/19) Jan 17 2012 My thoughts:
- Jonathan M Davis (13/40) Jan 17 2012 em
- Nick Sabalausky (5/33) Jan 17 2012 You're all getting hung up on the trivial detail of the names. Look at t...
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (5/40) Jan 17 2012 That doesn't make the name any less bad. Naming is important IMHO. Hence...
- Timon Gehr (3/46) Jan 17 2012 I think the compiler should just allow .dup()/.idup(). It would not
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (4/54) Jan 17 2012 +1.
- Steven Schveighoffer (22/73) Jan 18 2012 e:
- Andrei Alexandrescu (8/13) Jan 18 2012 Even ptr and length should be in the library. The slice structure should...
- Jacob Carlborg (4/17) Jan 18 2012 But a library can't handle common properties like "mangleof" and "string...
- Steven Schveighoffer (12/21) Jan 18 2012 That is debatable. The exact semantics of length are not repeatable in ...
- Andrei Alexandrescu (12/31) Jan 18 2012 1. Offer the runtime the possibility of tweaking the efficiency of the
- Steven Schveighoffer (16/50) Jan 18 2012 The runtime already implements the abstraction. All that the compiler
- Jonathan M Davis (7/9) Jan 17 2012 save for forward ranges is pretty much the same. It's a property even th...
- Nick Sabalausky (7/17) Jan 17 2012 Right, I was only addressing the original matter "property or function?"
- Timon Gehr (2/37) Jan 17 2012 In fact, it creates a new copy that can be iterated on.
- Jose Armando Garcia (17/25) Jan 17 2012 If it is any help, Scala libraries use by convention that methods that
- Michel Fortin (10/19) Jan 17 2012 Is it a verb? If not, it is a property.
- Andrei Alexandrescu (4/19) Jan 17 2012 "Iterate collection by key".
- bearophile (10/11) Jan 17 2012 Is this code now working? (I have tried it hours ago):
- bearophile (4/5) Jan 17 2012 After the last change it now works, thank you.
- Alvaro (21/23) Jan 17 2012 OK, I see, .keys and .values currently return dynamic arrays.
- Timon Gehr (2/27) Jan 17 2012 See std.array.array.
- Alvaro (10/49) Jan 17 2012 Oops. Yes, thanks.
- bearophile (5/15) Jan 17 2012 sort property is deprecated (or going to be).
- Nick Sabalausky (4/49) Jan 17 2012 My thoughts exactly. The current .keys made sense back in the days befor...
- deadalnix (2/55) Jan 18 2012 ++ here. keys is the perfect name for that stuff.
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (4/57) Jan 18 2012 Vote++ from me as well.
- Steven Schveighoffer (12/23) Jan 18 2012 There is one significant problem with changing aa.keys to be a lazy rang...
- bearophile (5/16) Jan 18 2012 On this topic see also:
- =?utf-8?Q?Simen_Kj=C3=A6r=C3=A5s?= (3/11) Jan 17 2012 Property.
- Timon Gehr (4/12) Jan 17 2012 IMO it does not matter. I think we should just deprecate the -property
- Jonathan M Davis (5/8) Jan 17 2012 Then we might as well throw out @property and change TDPL. There's no po...
- Timon Gehr (3/11) Jan 17 2012 Since -property is optional I think the relevant ships are still in the
- Jonathan M Davis (12/27) Jan 17 2012 @property is in TDPL. It's definitely the plan to implement it as descri...
- Peter Alexander (19/24) Jan 17 2012 There's a few good reasons to throw it out:
- Andrei Alexandrescu (11/39) Jan 17 2012 Yes! I can't believe we have a check that has _zero_ contribution to
- Steven Schveighoffer (22/50) Jan 18 2012 The solution is easy, just don't start the discussion. Make a decision ...
- Andrei Alexandrescu (17/30) Jan 18 2012 Well in this case I am right :o). We did a poor job at designing
- Steven Schveighoffer (14/43) Jan 18 2012 Then I withdraw the "being spiteful" suggestion, it was probably unfair.
- Andrei Alexandrescu (12/47) Jan 18 2012 Indeed I told you all! Every time we add anything, there's going to be
- Steven Schveighoffer (25/77) Jan 18 2012 All of your arguments were subjective "doesn't palpably change the
- Jonathan M Davis (7/14) Jan 18 2012 There are those of us who _do_ think that it palpably improves the langu...
- Ary Manzana (2/43) Jan 19 2012 Before I knew Ruby I was in favor of @property. Now I'm against it.
- Nick Sabalausky (28/56) Jan 17 2012 Andrei's the only one that ever starts any of this "Is this a property o...
- Nick Sabalausky (8/18) Jan 17 2012 Obviously, I need to re-proofread *after* I edit... ;)
- bearophile (16/19) Jan 17 2012 I have a partially related question.
- Jonathan M Davis (8/25) Jan 17 2012 Definitely a bug. Strict enforcement requires that parens be used on all...
- bearophile (4/6) Jan 17 2012 I agree! I'll take a look in Bugzilla if this bug report is already pres...
- Timon Gehr (11/36) Jan 17 2012 A related and way more embarrassing problem is that lazy function
- Peter Alexander (6/49) Jan 18 2012 Perhaps I'm wrong, but this issue is different.
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (5/56) Jan 18 2012 But couldn't that be considered leaking an implementation detail of lazy...
- Timon Gehr (2/59) Jan 18 2012 I suppose it is an implementation relic.
- Jonathan M Davis (16/18) Jan 18 2012 The language requires that lazy parameters be accessed with (). That lea...
- Timon Gehr (3/21) Jan 18 2012 They are only required if you want to call a lazy delegate/function
- Jonathan M Davis (6/8) Jan 18 2012 I could have sworn that they were required. If not, then yeah, that seem...
- Timon Gehr (6/58) Jan 18 2012 What would 'un-lazying' be and what is supposed to be its effect?
- Peter Alexander (16/77) Jan 19 2012 Under the hood, lazy is just a delegate with different syntax.
- Timon Gehr (8/89) Jan 19 2012 It is more than that, type checking works differently for lazy values
- Jonathan M Davis (6/8) Jan 19 2012 Ignoring the fact that this will break code, I completely agree. However...
- Jonathan M Davis (12/43) Jan 17 2012 I'm fully aware that there are those who want to throw it out (e.g. Andr...
- sclytrack (40/42) Jan 18 2012 I hope we are not dropping properties
- Jacob Carlborg (23/65) Jan 18 2012 I would like this:
- Steven Schveighoffer (6/88) Jan 18 2012 what about:
- Jacob Carlborg (5/99) Jan 18 2012 I could go either way with that one. But I think I prefer optional
- Nick Sabalausky (8/10) Jan 18 2012 FWIW, I always do a double-take when I see code like:
- Nick Sabalausky (14/25) Jan 18 2012 Also it doesn't help that using the function name by itself (with no par...
- Alvaro (10/19) Feb 05 2012 Exactly, to my eyes the () is what says "execute!", what triggers the
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (6/17) Jan 18 2012 Indeed! It's so unnatural in a C-based language. See, if the semicolon
- Manfred Nowak (4/5) Jan 18 2012 ... it would look like a parameterless command in a shell:
- Jacob Carlborg (5/16) Jan 18 2012 It's even more fun in Ruby which doesn't require semicolons :) Just:
- sclytrack (3/22) Jan 17 2012 Can't we drop the empty (). It's too much typing.
- Somedude (6/21) Jan 17 2012 Microsoft guidelines:
- Peter Alexander (5/13) Jan 17 2012 byKey(aa)
- Martin Nowak (5/25) Jan 18 2012 But the current compiler behavior is really annoying.
- Jonathan M Davis (7/10) Jan 18 2012 Once the implementation of -property has been fully sorted out, I believ...
- bearophile (15/16) Jan 17 2012 I am sorry to see you do something you hate :-(
- Andrei Alexandrescu (3/9) Jan 17 2012 byPair is tricky because std.tuple is not visible from object.
- bearophile (6/10) Jan 17 2012 I will add this answer to the issue 5466.
- Kapps (7/15) Jan 17 2012 Is there even a point to having byKey/byValue?
- Steven Schveighoffer (7/13) Jan 18 2012 It changes semantics. For example:
- Olivier Pisano (4/12) Jan 18 2012 I vote for the methods.
- torhu (18/24) Jan 19 2012 For it to be a property, I think you should be able to simplify this
- torhu (7/35) Jan 19 2012 Sorry, I meant this for the second example:
- torhu (7/47) Jan 19 2012 The reason would be that if it looks like field access, it should behave...
- Andrei Alexandrescu (5/7) Jan 19 2012 The difficulty is in knowing where to stop. The only things that behaves...
- Jonathan M Davis (7/14) Jan 19 2012 Yeah. It's generally expected that properties may return stuff which is
- Marco Leise (5/22) Jan 19 2012 I just came across some C++ code and came to the conclusion, that
- Jonathan M Davis (6/10) Jan 19 2012 I don't know why you came to that concluson. I don't agree at all. Obvio...
- Marco Leise (5/17) Jan 20 2012 Ah, I meant to say that getters should not modify their object. When I s...
- Jonathan M Davis (12/16) Jan 20 2012 Yes. Generally, setters should be used to set rather than getters doing ...
- Alvaro (5/15) Jan 20 2012 Well, there is the case of std::map and its [] operator which adds an
- Jonathan M Davis (4/10) Jan 20 2012 Maybe. It's certainly a pretty horrible design decision IMHO, and it's n...
- Andrei Alexandrescu (4/32) Jan 19 2012 Yah, this is the lvalue vs. rvalue part. I think you are making a good
- Steven Schveighoffer (14/42) Jan 19 2012 That's like saying this:
- torhu (4/16) Jan 19 2012 If the type of byKeys is Range, I would expect to be able to treat it
- Steven Schveighoffer (3/28) Jan 19 2012 I don't know what you mean. You can treat it like one.
- Andrei Alexandrescu (5/11) Jan 19 2012 It's the rvalue aspect. byKey does not hold a range inside the hashtable...
- Jonathan M Davis (5/18) Jan 19 2012 Well, that's part of the point of properties. They don't have to actuall...
- Andrei Alexandrescu (3/20) Jan 19 2012 Yah, but .length acts to a better extent like an lvalue.
- Jonathan M Davis (4/5) Jan 19 2012 True, but that's because it's both a getter and a setter. What's weirder...
- Jose Armando Garcia (4/20) Jan 19 2012 I think MSDN has some decent advice on when to use properties vs
- Johannes Pfau (5/30) Jan 20 2012 us/library/bzwdh01d(v=vs.71).aspx#cpconpropertyusageguidelinesanchor1
- Jose Armando Garcia (9/39) Feb 05 2012 std.log still works! hehe. std.log is ready for review but
- Andrei Alexandrescu (4/10) Feb 05 2012 If the changes make more sense to put in druntime let's do so. Please
- Jose Armando Garcia (5/16) Feb 05 2012 https://github.com/D-Programming-Language/druntime/pull/141/files
- Jonathan M Davis (3/7) Jan 19 2012 Those do seem like pretty good guidelines.
- Steven Schveighoffer (10/22) Jan 19 2012 The point of a property is to allow for read-only access on something th...
- Peter Alexander (7/26) Jan 20 2012 Can you define what "is logically a property means"? (I assume you meant...
- Jonathan M Davis (15/22) Jan 20 2012 Usually when discussing properties, taking the address doesn't come into...
- Steven Schveighoffer (25/50) Jan 20 2012 No, I meant property. A property is a more general term. It's a piece ...
- Jens Mueller (5/12) Jan 20 2012 Then why not add these in a condensed form to
- Jonathan M Davis (9/21) Jan 20 2012 Oh, it may be a good idea to add them (or something like them) to the st...
- Jens Mueller (4/25) Jan 20 2012 I was only hoping for a reduction. If a convention works most of the
- Andrei Alexandrescu (9/17) Jan 20 2012 I tallied the votes.
- Steven Schveighoffer (4/26) Jan 20 2012 I voted property, though not as a direct reply before.
- Jonathan M Davis (11/37) Jan 20 2012 I'm divided. If it were keys and values, I'd be all for property, but by...
- Matt Soucy (4/41) Jan 20 2012 Agreed - if it were keys and values, property would be perfect. The
- sclytrack (21/45) Jan 20 2012 Collection properties should satisfy the "torhu" criteria.
- bearophile (4/13) Jan 20 2012 I vote for byKey and byValue to be properties.
- Peter Alexander (2/8) Jan 20 2012 I vote function.
- Michel Fortin (17/25) Jan 20 2012 Votes ?!?
- Andrei Alexandrescu (9/32) Jan 20 2012 Give them better names and convince others. Please don't choose "keys"
- Michel Fortin (18/56) Jan 20 2012 Well, if the best ones are already taken, I'd say "allKeys" and
- Alvaro (10/17) Jan 22 2012 Agree with "allKeys" and "allValues" as the next best.
- Jonathan M Davis (3/4) Jan 22 2012 Prepositional phrase actually.
- Andrei Alexandrescu (5/24) Jan 22 2012 torhu convinced me byXyz can't be properties. I'll operate the change so...
- Steven Schveighoffer (17/20) Jan 24 2012 Actually, it's for each (x) in (y) by key:
- Andrei Alexandrescu (5/13) Jan 24 2012 I'm thinking independently of foreach, e.g.
- Steven Schveighoffer (10/23) Jan 24 2012 I wrote about that.
- Steven Schveighoffer (12/19) Jan 24 2012 On Sun, 22 Jan 2012 10:27:42 -0500, Andrei Alexandrescu
- Andrei Alexandrescu (3/25) Jan 24 2012 Changing parens would be (have been) a smaller change.
- Johannes Pfau (2/45) Jan 21 2012
- Peter Alexander (3/5) Jan 21 2012 And this is exactly the problem. There are no general rules because
- torhu (14/18) Jan 21 2012 I think that the people here have two different views of what a property...
- Alix Pexton (7/31) Jan 21 2012 I vote property.
- Alvaro (20/31) Jan 21 2012 I vote properties.
- Era Scarecrow (3/15) Jan 24 2012 Perhaps I'm out of line, and I haven't looked much at the class/struct ...
- Steven Schveighoffer (10/31) Jan 24 2012 The builtin associative arrays of D. i.e.:
- Era Scarecrow (20/31) Jan 24 2012 That's what I thought... I'd think keys could be mutable; However the h...
I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" Alexandrescu
Jan 16 2012
2012/1/17 Andrei Alexandrescu <SeeWebsiteForEmail erdani.org>:I hate I must ask this:Can't find any arguments for either version, but subjectively I like non-property version more.
Jan 16 2012
"Andrei Alexandrescu" <SeeWebsiteForEmail erdani.org> wrote in message news:jf35jr$e2k$1 digitalmars.com...I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }Property. It's not an action, you're just accessing a particular interface of aa.
Jan 16 2012
"Nick Sabalausky" <a a.a> wrote in message news:jf36tf$g3g$1 digitalmars.com..."Andrei Alexandrescu" <SeeWebsiteForEmail erdani.org> wrote in message news:jf35jr$e2k$1 digitalmars.com...Another way you can look at it to make it clear: As far as the caller is concerened, it would have made equal sense if byKey were implemented as a nested struct. Ie, it's data, not action. Just because your implementation happens to involve an imperative block of statements doesn't change the user's perspective of byKey's semantics. Nick "Yes, it is still clear-cut" Sabalausky ;)I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }Property. It's not an action, you're just accessing a particular interface of aa.
Jan 16 2012
On 17-01-2012 07:48, Andrei Alexandrescu wrote:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuMy thoughts: The "by" in the name is way too awkward for a property. If it was just named "keys" and "values", it would've been perfectly fine to make them properties, but the "by" just looks awkward when you "call" them as properties. As far as efficiency goes, I don't think these perform any work that is heavy enough to warrant not making them properties. (I can't say that same for .dup/.idup... I still don't get why those are properties, at all.) -- - Alex
Jan 17 2012
On Tuesday, January 17, 2012 09:07:04 Alex R=C3=B8nne Petersen wrote:On 17-01-2012 07:48, Andrei Alexandrescu wrote:tI hate I must ask this: =20 int[string] aa; foreach (k; aa.byKey) { ... } =20 or =20 int[string] aa; foreach (k; aa.byKey()) { ... } =20 =20 =20 Thanks, =20 Andrei "I told you" Alexandrescu=20 My thoughts: =20 The "by" in the name is way too awkward for a property. If it was jus=named "keys" and "values", it would've been perfectly fine to make th=emproperties, but the "by" just looks awkward when you "call" them as properties. =20 As far as efficiency goes, I don't think these perform any work that =isheavy enough to warrant not making them properties. (I can't say that=same for .dup/.idup... I still don't get why those are properties, at=all.) Agreed. If it were keys and values, then a property would make sense. H= owever,=20 since it's byKey and byValue, I don't think that it makes as much sense= . It=20 _is_ a bit of a weird case though, since byKey and byValue are neither = nouns=20 nor verbs. - Jonathan M Davis
Jan 17 2012
"Jonathan M Davis" <jmdavisProg gmx.com> wrote in message news:mailman.496.1326793835.16222.digitalmars-d puremagic.com...On Tuesday, January 17, 2012 09:07:04 Alex Rønne Petersen wrote:You're all getting hung up on the trivial detail of the names. Look at the semantics: They retreive a range associated with the aa, right? Right. Property. It's a plain old classic getter.On 17-01-2012 07:48, Andrei Alexandrescu wrote:Agreed. If it were keys and values, then a property would make sense. However, since it's byKey and byValue, I don't think that it makes as much sense. It _is_ a bit of a weird case though, since byKey and byValue are neither nouns nor verbs.I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }The "by" in the name is way too awkward for a property. If it was just named "keys" and "values", it would've been perfectly fine to make them properties, but the "by" just looks awkward when you "call" them as properties. As far as efficiency goes, I don't think these perform any work that is heavy enough to warrant not making them properties. (I can't say that same for .dup/.idup... I still don't get why those are properties, at all.)
Jan 17 2012
On 17-01-2012 13:41, Nick Sabalausky wrote:"Jonathan M Davis"<jmdavisProg gmx.com> wrote in message news:mailman.496.1326793835.16222.digitalmars-d puremagic.com...That doesn't make the name any less bad. Naming is important IMHO. Hence why I'm also complaining about .dup/.idup. -- - AlexOn Tuesday, January 17, 2012 09:07:04 Alex Rønne Petersen wrote:You're all getting hung up on the trivial detail of the names. Look at the semantics: They retreive a range associated with the aa, right? Right. Property. It's a plain old classic getter.On 17-01-2012 07:48, Andrei Alexandrescu wrote:Agreed. If it were keys and values, then a property would make sense. However, since it's byKey and byValue, I don't think that it makes as much sense. It _is_ a bit of a weird case though, since byKey and byValue are neither nouns nor verbs.I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }The "by" in the name is way too awkward for a property. If it was just named "keys" and "values", it would've been perfectly fine to make them properties, but the "by" just looks awkward when you "call" them as properties. As far as efficiency goes, I don't think these perform any work that is heavy enough to warrant not making them properties. (I can't say that same for .dup/.idup... I still don't get why those are properties, at all.)
Jan 17 2012
On 01/17/2012 02:14 PM, Alex Rønne Petersen wrote:On 17-01-2012 13:41, Nick Sabalausky wrote:I think the compiler should just allow .dup()/.idup(). It would not break any existing code."Jonathan M Davis"<jmdavisProg gmx.com> wrote in message news:mailman.496.1326793835.16222.digitalmars-d puremagic.com...That doesn't make the name any less bad. Naming is important IMHO. Hence why I'm also complaining about .dup/.idup.On Tuesday, January 17, 2012 09:07:04 Alex Rønne Petersen wrote:You're all getting hung up on the trivial detail of the names. Look at the semantics: They retreive a range associated with the aa, right? Right. Property. It's a plain old classic getter.On 17-01-2012 07:48, Andrei Alexandrescu wrote:Agreed. If it were keys and values, then a property would make sense. However, since it's byKey and byValue, I don't think that it makes as much sense. It _is_ a bit of a weird case though, since byKey and byValue are neither nouns nor verbs.I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }The "by" in the name is way too awkward for a property. If it was just named "keys" and "values", it would've been perfectly fine to make them properties, but the "by" just looks awkward when you "call" them as properties. As far as efficiency goes, I don't think these perform any work that is heavy enough to warrant not making them properties. (I can't say that same for .dup/.idup... I still don't get why those are properties, at all.)
Jan 17 2012
On 17-01-2012 19:41, Timon Gehr wrote:On 01/17/2012 02:14 PM, Alex Rønne Petersen wrote:+1. -- - AlexOn 17-01-2012 13:41, Nick Sabalausky wrote:I think the compiler should just allow .dup()/.idup(). It would not break any existing code."Jonathan M Davis"<jmdavisProg gmx.com> wrote in message news:mailman.496.1326793835.16222.digitalmars-d puremagic.com...That doesn't make the name any less bad. Naming is important IMHO. Hence why I'm also complaining about .dup/.idup.On Tuesday, January 17, 2012 09:07:04 Alex Rønne Petersen wrote:You're all getting hung up on the trivial detail of the names. Look at the semantics: They retreive a range associated with the aa, right? Right. Property. It's a plain old classic getter.On 17-01-2012 07:48, Andrei Alexandrescu wrote:Agreed. If it were keys and values, then a property would make sense. However, since it's byKey and byValue, I don't think that it makes as much sense. It _is_ a bit of a weird case though, since byKey and byValue are neither nouns nor verbs.I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }The "by" in the name is way too awkward for a property. If it was just named "keys" and "values", it would've been perfectly fine to make them properties, but the "by" just looks awkward when you "call" them as properties. As far as efficiency goes, I don't think these perform any work that is heavy enough to warrant not making them properties. (I can't say that same for .dup/.idup... I still don't get why those are properties, at all.)
Jan 17 2012
On Tue, 17 Jan 2012 13:41:07 -0500, Timon Gehr <timon.gehr gmx.ch> wrote= :On 01/17/2012 02:14 PM, Alex R=C3=B8nne Petersen wrote:e:On 17-01-2012 13:41, Nick Sabalausky wrote:"Jonathan M Davis"<jmdavisProg gmx.com> wrote in message news:mailman.496.1326793835.16222.digitalmars-d puremagic.com...On Tuesday, January 17, 2012 09:07:04 Alex R=C3=B8nne Petersen wrot==On 17-01-2012 07:48, Andrei Alexandrescu wrote:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }The "by" in the name is way too awkward for a property. If it was ==just named "keys" and "values", it would've been perfectly fine to make=sthem properties, but the "by" just looks awkward when you "call" them a=at =properties. As far as efficiency goes, I don't think these perform any work th=hatis heavy enough to warrant not making them properties. (I can't say t=atsame for .dup/.idup... I still don't get why those are properties,=e.all.)Agreed. If it were keys and values, then a property would make sens=herHowever, since it's byKey and byValue, I don't think that it makes as much sense. It _is_ a bit of a weird case though, since byKey and byValue are neit=atnouns nor verbs.You're all getting hung up on the trivial detail of the names. Look =t.the semantics: They retreive a range associated with the aa, right? Righ=nceProperty. It's a plain old classic getter.That doesn't make the name any less bad. Naming is important IMHO. He=why I'm also complaining about .dup/.idup.I think the compiler should just allow .dup()/.idup(). It would not =break any existing code.I think the compiler should not be in the business of generating methods= = or properties that could be trivially handled by the library. The only array-specific properties of an array that the compiler should = = worry about are ptr and length. Everything else should be a library = function. -Steve
Jan 18 2012
On 1/18/12 7:20 AM, Steven Schveighoffer wrote:I think the compiler should not be in the business of generating methods or properties that could be trivially handled by the library.Yes. I'm fighting Walter tooth and nail over that, with pale success.The only array-specific properties of an array that the compiler should worry about are ptr and length. Everything else should be a library function.Even ptr and length should be in the library. The slice structure should be defined in object.d. The only business the compiler has is to lower the T[] type syntax and the [ ... ] literal syntax to .object.Slice!T and .object.slice(...) form, and to make sure that typeof(T[]) is not struct (although factually it is). Andrei
Jan 18 2012
On 2012-01-18 14:59, Andrei Alexandrescu wrote:On 1/18/12 7:20 AM, Steven Schveighoffer wrote:But a library can't handle common properties like "mangleof" and "stringof"? -- /Jacob CarlborgI think the compiler should not be in the business of generating methods or properties that could be trivially handled by the library.Yes. I'm fighting Walter tooth and nail over that, with pale success.The only array-specific properties of an array that the compiler should worry about are ptr and length. Everything else should be a library function.Even ptr and length should be in the library. The slice structure should be defined in object.d. The only business the compiler has is to lower the T[] type syntax and the [ ... ] literal syntax to .object.Slice!T and .object.slice(...) form, and to make sure that typeof(T[]) is not struct (although factually it is). Andrei
Jan 18 2012
On Wed, 18 Jan 2012 08:59:57 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/18/12 7:20 AM, Steven Schveighoffer wrote:That is debatable. The exact semantics of length are not repeatable in the library, where a get is a simple field access, yet a set calls a method. To achieve the same you would have to require -inline on the compile line. At that point, we have to say "what does it buy us". The function to set the length is already a library function, which is changable outside the compiler. What do we gain besides saying the language is purer? If we change dup and idup to be library defined, we can get benefits, such as taking advantage of pure being able to implicitly cast to immutable. -SteveThe only array-specific properties of an array that the compiler should worry about are ptr and length. Everything else should be a library function.Even ptr and length should be in the library. The slice structure should be defined in object.d. The only business the compiler has is to lower the T[] type syntax and the [ ... ] literal syntax to .object.Slice!T and .object.slice(...) form, and to make sure that typeof(T[]) is not struct (although factually it is).
Jan 18 2012
On 1/18/12 12:04 PM, Steven Schveighoffer wrote:On Wed, 18 Jan 2012 08:59:57 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:1. Offer the runtime the possibility of tweaking the efficiency of the abstraction 2. Smaller and simpler compiler 3. Detecting design and implementation bugs in the language (we found a lot while porting the associative arrays) 4. Uniform built-in type behavior and user-defined type behavior, which is a boon for generic code and generally for the language size and understandability As a related example, look at how simple and efficient byKey and byValue are thanks to migrating hashes into the runtime. AndreiOn 1/18/12 7:20 AM, Steven Schveighoffer wrote:That is debatable. The exact semantics of length are not repeatable in the library, where a get is a simple field access, yet a set calls a method. To achieve the same you would have to require -inline on the compile line. At that point, we have to say "what does it buy us". The function to set the length is already a library function, which is changable outside the compiler. What do we gain besides saying the language is purer?The only array-specific properties of an array that the compiler should worry about are ptr and length. Everything else should be a library function.Even ptr and length should be in the library. The slice structure should be defined in object.d. The only business the compiler has is to lower the T[] type syntax and the [ ... ] literal syntax to .object.Slice!T and .object.slice(...) form, and to make sure that typeof(T[]) is not struct (although factually it is).
Jan 18 2012
On Wed, 18 Jan 2012 14:11:16 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/18/12 12:04 PM, Steven Schveighoffer wrote:The runtime already implements the abstraction. All that the compiler does special is glue the property to the function call.On Wed, 18 Jan 2012 08:59:57 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:1. Offer the runtime the possibility of tweaking the efficiency of the abstractionOn 1/18/12 7:20 AM, Steven Schveighoffer wrote:That is debatable. The exact semantics of length are not repeatable in the library, where a get is a simple field access, yet a set calls a method. To achieve the same you would have to require -inline on the compile line. At that point, we have to say "what does it buy us". The function to set the length is already a library function, which is changable outside the compiler. What do we gain besides saying the language is purer?The only array-specific properties of an array that the compiler should worry about are ptr and length. Everything else should be a library function.Even ptr and length should be in the library. The slice structure should be defined in object.d. The only business the compiler has is to lower the T[] type syntax and the [ ... ] literal syntax to .object.Slice!T and .object.slice(...) form, and to make sure that typeof(T[]) is not struct (although factually it is).2. Smaller and simpler compilerMaybe relevant for new compilers.3. Detecting design and implementation bugs in the language (we found a lot while porting the associative arrays)There is only one function to set length. It's not quite comparable to the entire set of associative array functionality. Though as someone who has mostly rewritten it, I can say it's not a trivial function, and may still have bugs in it. However, I don't see changing the entity who glues the property to the function is going to find bugs in the function.4. Uniform built-in type behavior and user-defined type behavior, which is a boon for generic code and generally for the language size and understandabilityThis I agree with, it makes the language uniformly implemented, which makes things simpler to understand/implement. But it already works, and works rather well. This is my point, all we gain is being able to say the language is simpler/purer.As a related example, look at how simple and efficient byKey and byValue are thanks to migrating hashes into the runtime.Not to mention *possible* :) -Steve
Jan 18 2012
On Tuesday, January 17, 2012 14:14:46 Alex Rønne Petersen wrote:That doesn't make the name any less bad. Naming is important IMHO. Hence why I'm also complaining about .dup/.idup.save for forward ranges is pretty much the same. It's a property even though it's name and usage suggests otherwise. But we're pretty much stuck with all three of those at this point. Arguing about it is pretty much quibbling over straws, and some - Andrei in particular - are becoming increasingly adverse to arguing over such small changes to existing code for minimal benefit. - Jonathan M Davis
Jan 17 2012
"Alex Rønne Petersen" <xtzgzorex gmail.com> wrote in message news:jf3s86$1opl$1 digitalmars.com...On 17-01-2012 13:41, Nick Sabalausky wrote:Right, I was only addressing the original matter "property or function?"You're all getting hung up on the trivial detail of the names. Look at the semantics: They retreive a range associated with the aa, right? Right. Property. It's a plain old classic getter.That doesn't make the name any less bad. Naming is important IMHO.Hence why I'm also complaining about .dup/.idup.Yes, dup/idup are clearly not properties. But they're from way before property, so of course that's why they are how they are (Not that it's good for them to be that way). I'm also in favor of the suggestion of at least optionally allowing dup()/idup().
Jan 17 2012
On 01/17/2012 01:41 PM, Nick Sabalausky wrote:"Jonathan M Davis"<jmdavisProg gmx.com> wrote in message news:mailman.496.1326793835.16222.digitalmars-d puremagic.com...In fact, it creates a new copy that can be iterated on.On Tuesday, January 17, 2012 09:07:04 Alex Rønne Petersen wrote:You're all getting hung up on the trivial detail of the names. Look at the semantics: They retreive a range associated with the aa, right? Right. Property. It's a plain old classic getter.On 17-01-2012 07:48, Andrei Alexandrescu wrote:Agreed. If it were keys and values, then a property would make sense. However, since it's byKey and byValue, I don't think that it makes as much sense. It _is_ a bit of a weird case though, since byKey and byValue are neither nouns nor verbs.I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }The "by" in the name is way too awkward for a property. If it was just named "keys" and "values", it would've been perfectly fine to make them properties, but the "by" just looks awkward when you "call" them as properties. As far as efficiency goes, I don't think these perform any work that is heavy enough to warrant not making them properties. (I can't say that same for .dup/.idup... I still don't get why those are properties, at all.)
Jan 17 2012
On Tue, Jan 17, 2012 at 4:48 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }If it is any help, Scala libraries use by convention that methods that have a side should be called with '()' while methods that don't have a side effect should be called without the '()'. In scala this translate to: aa.sideEffectWhenCalled() aa.noSideEffect which looks as follow in the definition: def sideEffectWhenCalled() = { ... } def noSideEffect = { ... } I think that this translate really well to D's property. Photos can try to implement the policy that read properties shouldn't have side effects (externally observable side effect). The language doesn't need to enforce but it would be nice if Photos would follow it. Thoughts? Thanks, -JoseThanks, Andrei "I told you" Alexandrescu
Jan 17 2012
On 2012-01-17 06:48:26 +0000, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> said:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }Is it a verb? If not, it is a property. But why "by"? Why not just "aa.keys"? It's much more natural. Is "byKey" going to consume the associative array like "byLine" does for files? Obviously no. So I don't see why you need "by" here. -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Jan 17 2012
On 1/17/12 11:09 AM, Michel Fortin wrote:On 2012-01-17 06:48:26 +0000, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> said:"Iterate collection by key". aa.keys is taken btw. AndreiI hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }Is it a verb? If not, it is a property. But why "by"? Why not just "aa.keys"? It's much more natural. Is "byKey" going to consume the associative array like "byLine" does for files? Obviously no. So I don't see why you need "by" here.
Jan 17 2012
Andrei Alexandrescu:"Iterate collection by key".Is this code now working? (I have tried it hours ago): import std.stdio, std.algorithm; void main () { auto aa = ["a":1, "b":2]; writeln(aa.byValue()); writeln( map!q{ a * a }(aa.byValue()) ); } Bye, bearophile
Jan 17 2012
Is this code now working? (I have tried it hours ago):After the last change it now works, thank you. I will close/update the relative Bugzilla Issues. Bye, bearophile
Jan 17 2012
El 17/01/2012 18:24, Andrei Alexandrescu escribió:...On 2012-01-17 06:48:26 +0000, Andrei Alexandrescuaa.keys is taken btw.OK, I see, .keys and .values currently return dynamic arrays. But the most appropriate property name for the above range should indeed be .keys ! Now, wouldn't it be be better to turn .keys into the proposed range? Let's see. What is the use of .keys? I searched phobos and found that .keys is mostly used to itarate over the keys in a foreach loop. With the problem that is needs to allocate a dynamic array. If silently changed to the proposed range, the foreach loop would do the same and without an allocation. In a few unittests, .keys is followed by .sort, usually to print the keys in order. That would not work... unless the produced range includes a .sort method. Alternatively a .sortedKeys property can be added. The other use I see in phobos is just a typeof(a.keys[0]), which could be replaced by typeof(a.keys.front) What is the benefit of .keys as a range? it does not allocate an array, just gives the keys. And if an array is needed, it is easy to turn a range into an array. [Well, I'm missing a more direct way of doing that than using foreach and appending]
Jan 17 2012
On 01/17/2012 11:19 PM, Alvaro wrote:El 17/01/2012 18:24, Andrei Alexandrescu escribió:See std.array.array....On 2012-01-17 06:48:26 +0000, Andrei Alexandrescuaa.keys is taken btw.OK, I see, .keys and .values currently return dynamic arrays. But the most appropriate property name for the above range should indeed be .keys ! Now, wouldn't it be be better to turn .keys into the proposed range? Let's see. What is the use of .keys? I searched phobos and found that .keys is mostly used to itarate over the keys in a foreach loop. With the problem that is needs to allocate a dynamic array. If silently changed to the proposed range, the foreach loop would do the same and without an allocation. In a few unittests, .keys is followed by .sort, usually to print the keys in order. That would not work... unless the produced range includes a .sort method. Alternatively a .sortedKeys property can be added. The other use I see in phobos is just a typeof(a.keys[0]), which could be replaced by typeof(a.keys.front) What is the benefit of .keys as a range? it does not allocate an array, just gives the keys. And if an array is needed, it is easy to turn a range into an array. [Well, I'm missing a more direct way of doing that than using foreach and appending]
Jan 17 2012
El 17/01/2012 23:32, Timon Gehr escribió:On 01/17/2012 11:19 PM, Alvaro wrote:Oops. Yes, thanks. So, not bad. In those [infrequent, I'd say] cases needing an array one would do: auto keys = array(aa.keys); even: (unsure if this would work, but somethig similar maybe) foreach(k; array(aa.keys).sort) { ... use the ordered keys }El 17/01/2012 18:24, Andrei Alexandrescu escribió:See std.array.array....On 2012-01-17 06:48:26 +0000, Andrei Alexandrescuaa.keys is taken btw.OK, I see, .keys and .values currently return dynamic arrays. But the most appropriate property name for the above range should indeed be .keys ! Now, wouldn't it be be better to turn .keys into the proposed range? Let's see. What is the use of .keys? I searched phobos and found that .keys is mostly used to itarate over the keys in a foreach loop. With the problem that is needs to allocate a dynamic array. If silently changed to the proposed range, the foreach loop would do the same and without an allocation. In a few unittests, .keys is followed by .sort, usually to print the keys in order. That would not work... unless the produced range includes a .sort method. Alternatively a .sortedKeys property can be added. The other use I see in phobos is just a typeof(a.keys[0]), which could be replaced by typeof(a.keys.front) What is the benefit of .keys as a range? it does not allocate an array, just gives the keys. And if an array is needed, it is easy to turn a range into an array. [Well, I'm missing a more direct way of doing that than using foreach and appending]
Jan 17 2012
Alvaro:So, not bad. In those [infrequent, I'd say] cases needing an array one would do: auto keys = array(aa.keys);Unfortunately in D you often need arrays, so those cases are frequent.even: (unsure if this would work, but somethig similar maybe) foreach(k; array(aa.keys).sort) { ... use the ordered keys }sort property is deprecated (or going to be). Bye, bearophile
Jan 17 2012
"Alvaro" <alvaroDotSegura gmail.com> wrote in message news:jf4tr4$lnv$1 digitalmars.com...El 17/01/2012 23:32, Timon Gehr escribió:My thoughts exactly. The current .keys made sense back in the days before ranges, std.algorithm, etc, but not so much anymore. Vote++On 01/17/2012 11:19 PM, Alvaro wrote:Oops. Yes, thanks. So, not bad. In those [infrequent, I'd say] cases needing an array one would do: auto keys = array(aa.keys);El 17/01/2012 18:24, Andrei Alexandrescu escribió:See std.array.array....On 2012-01-17 06:48:26 +0000, Andrei Alexandrescuaa.keys is taken btw.OK, I see, .keys and .values currently return dynamic arrays. But the most appropriate property name for the above range should indeed be .keys ! Now, wouldn't it be be better to turn .keys into the proposed range? Let's see. What is the use of .keys? I searched phobos and found that .keys is mostly used to itarate over the keys in a foreach loop. With the problem that is needs to allocate a dynamic array. If silently changed to the proposed range, the foreach loop would do the same and without an allocation. In a few unittests, .keys is followed by .sort, usually to print the keys in order. That would not work... unless the produced range includes a .sort method. Alternatively a .sortedKeys property can be added. The other use I see in phobos is just a typeof(a.keys[0]), which could be replaced by typeof(a.keys.front) What is the benefit of .keys as a range? it does not allocate an array, just gives the keys. And if an array is needed, it is easy to turn a range into an array. [Well, I'm missing a more direct way of doing that than using foreach and appending]
Jan 17 2012
Le 18/01/2012 01:02, Nick Sabalausky a écrit :"Alvaro"<alvaroDotSegura gmail.com> wrote in message news:jf4tr4$lnv$1 digitalmars.com...++ here. keys is the perfect name for that stuff.El 17/01/2012 23:32, Timon Gehr escribi�:My thoughts exactly. The current .keys made sense back in the days before ranges, std.algorithm, etc, but not so much anymore. Vote++On 01/17/2012 11:19 PM, Alvaro wrote:Oops. Yes, thanks. So, not bad. In those [infrequent, I'd say] cases needing an array one would do: auto keys = array(aa.keys);El 17/01/2012 18:24, Andrei Alexandrescu escribi�:See std.array.array....On 2012-01-17 06:48:26 +0000, Andrei Alexandrescuaa.keys is taken btw.OK, I see, .keys and .values currently return dynamic arrays. But the most appropriate property name for the above range should indeed be .keys ! Now, wouldn't it be be better to turn .keys into the proposed range? Let's see. What is the use of .keys? I searched phobos and found that .keys is mostly used to itarate over the keys in a foreach loop. With the problem that is needs to allocate a dynamic array. If silently changed to the proposed range, the foreach loop would do the same and without an allocation. In a few unittests, .keys is followed by .sort, usually to print the keys in order. That would not work... unless the produced range includes a .sort method. Alternatively a .sortedKeys property can be added. The other use I see in phobos is just a typeof(a.keys[0]), which could be replaced by typeof(a.keys.front) What is the benefit of .keys as a range? it does not allocate an array, just gives the keys. And if an array is needed, it is easy to turn a range into an array. [Well, I'm missing a more direct way of doing that than using foreach and appending]
Jan 18 2012
On 18-01-2012 01:02, Nick Sabalausky wrote:"Alvaro"<alvaroDotSegura gmail.com> wrote in message news:jf4tr4$lnv$1 digitalmars.com...Vote++ from me as well. -- - AlexEl 17/01/2012 23:32, Timon Gehr escribió:My thoughts exactly. The current .keys made sense back in the days before ranges, std.algorithm, etc, but not so much anymore. Vote++On 01/17/2012 11:19 PM, Alvaro wrote:Oops. Yes, thanks. So, not bad. In those [infrequent, I'd say] cases needing an array one would do: auto keys = array(aa.keys);El 17/01/2012 18:24, Andrei Alexandrescu escribió:See std.array.array....On 2012-01-17 06:48:26 +0000, Andrei Alexandrescuaa.keys is taken btw.OK, I see, .keys and .values currently return dynamic arrays. But the most appropriate property name for the above range should indeed be .keys ! Now, wouldn't it be be better to turn .keys into the proposed range? Let's see. What is the use of .keys? I searched phobos and found that .keys is mostly used to itarate over the keys in a foreach loop. With the problem that is needs to allocate a dynamic array. If silently changed to the proposed range, the foreach loop would do the same and without an allocation. In a few unittests, .keys is followed by .sort, usually to print the keys in order. That would not work... unless the produced range includes a .sort method. Alternatively a .sortedKeys property can be added. The other use I see in phobos is just a typeof(a.keys[0]), which could be replaced by typeof(a.keys.front) What is the benefit of .keys as a range? it does not allocate an array, just gives the keys. And if an array is needed, it is easy to turn a range into an array. [Well, I'm missing a more direct way of doing that than using foreach and appending]
Jan 18 2012
On Tue, 17 Jan 2012 19:02:03 -0500, Nick Sabalausky <a a.a> wrote:"Alvaro" <alvaroDotSegura gmail.com> wrote in messageThere is one significant problem with changing aa.keys to be a lazy range instead of an array. This is valid code (and does exist in the wild): foreach(k; aa.keys) { if(shouldRemove(k)) aa.remove(k); } This would silently start crashing programs if we changed the behavior of keys. I don't see any way around this... -SteveOops. Yes, thanks. So, not bad. In those [infrequent, I'd say] cases needing an array one would do: auto keys = array(aa.keys);My thoughts exactly. The current .keys made sense back in the days before ranges, std.algorithm, etc, but not so much anymore. Vote++
Jan 18 2012
Steven Schveighoffer:There is one significant problem with changing aa.keys to be a lazy range instead of an array. This is valid code (and does exist in the wild): foreach(k; aa.keys) { if(shouldRemove(k)) aa.remove(k); } This would silently start crashing programs if we changed the behavior of keys.On this topic see also: http://d.puremagic.com/issues/show_bug.cgi?id=4179 Bye, bearophile
Jan 18 2012
On Tue, 17 Jan 2012 07:48:26 +0100, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuProperty.
Jan 17 2012
On 01/17/2012 07:48 AM, Andrei Alexandrescu wrote:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuIMO it does not matter. I think we should just deprecate the -property switch instead of engaging into that kind of fruitless discussion every now and then. ;)
Jan 17 2012
On Tuesday, January 17, 2012 19:38:47 Timon Gehr wrote:IMO it does not matter. I think we should just deprecate the -property switch instead of engaging into that kind of fruitless discussion every now and then. ;)Then we might as well throw out property and change TDPL. There's no point to property without enforcement. I think that that ship has pretty much sailed already. - Jonathan M Davis
Jan 17 2012
On 01/17/2012 07:55 PM, Jonathan M Davis wrote:On Tuesday, January 17, 2012 19:38:47 Timon Gehr wrote:Since -property is optional I think the relevant ships are still in the haven.IMO it does not matter. I think we should just deprecate the -property switch instead of engaging into that kind of fruitless discussion every now and then. ;)Then we might as well throw out property and change TDPL. There's no point to property without enforcement. I think that that ship has pretty much sailed already. - Jonathan M Davis
Jan 17 2012
On Tuesday, January 17, 2012 20:27:41 Timon Gehr wrote:On 01/17/2012 07:55 PM, Jonathan M Davis wrote:property is in TDPL. It's definitely the plan to implement it as described in TDPL, integrating -property into the compiler so that property is _always_ enforced. It's just not that way, because it's on the list of things that's not fully implemented, and we needed a migration path from no property enforcement to enforcement. You would need to come up with some really solid arguments why it should be thrown out (and what we should do instead) and get both Walter and Andrei (if not the community at large) to agree that they not only prefer your proposal but that it's worth the issues that the changes are going to cause at this stage. - Jonathan M DavisOn Tuesday, January 17, 2012 19:38:47 Timon Gehr wrote:Since -property is optional I think the relevant ships are still in the haven.IMO it does not matter. I think we should just deprecate the -property switch instead of engaging into that kind of fruitless discussion every now and then. ;)Then we might as well throw out property and change TDPL. There's no point to property without enforcement. I think that that ship has pretty much sailed already. - Jonathan M Davis
Jan 17 2012
On 17/01/12 10:11 PM, Jonathan M Davis wrote:You would need to come up with some really solid arguments why it should be thrown out (and what we should do instead) and get both Walter and Andrei (if not the community at large) to agree that they not only prefer your proposal but that it's worth the issues that the changes are going to cause at this stage.There's a few good reasons to throw it out: 1. Avoids pointless discussions like this one. These discussions add nothing, it's just mindless bike shedding. 2. The -property flag *creates* a new kind of error, but doesn't actually help find real problems with your code. Without properties, member function access would always be a.b(), and this artificial error could be avoided. 3. Properties introduce another thing to remember, with no value ("was it byKeys, or byKeys()?"). Without properties, it would be byKeys(). No need to remember. 4. Properties obfuscate code. Is (a.b = c) a variable assignment or arbitrary function call? Who knows! Is a.b an actual variable? Can I write &a.b to get its address, or is it a function masquerading as a variable? 5. One less language feature to implement, learn, document, debug, and discuss. Is it practical or realistic to throw it out at this stage? I don't know. But there are reasons to.
Jan 17 2012
On 1/17/12 5:13 PM, Peter Alexander wrote:On 17/01/12 10:11 PM, Jonathan M Davis wrote:Yes.You would need to come up with some really solid arguments why it should be thrown out (and what we should do instead) and get both Walter and Andrei (if not the community at large) to agree that they not only prefer your proposal but that it's worth the issues that the changes are going to cause at this stage.There's a few good reasons to throw it out: 1. Avoids pointless discussions like this one. These discussions add nothing, it's just mindless bike shedding.2. The -property flag *creates* a new kind of error, but doesn't actually help find real problems with your code. Without properties, member function access would always be a.b(), and this artificial error could be avoided.Yes! I can't believe we have a check that has _zero_ contribution to improving code.3. Properties introduce another thing to remember, with no value ("was it byKeys, or byKeys()?"). Without properties, it would be byKeys(). No need to remember.YES!!!4. Properties obfuscate code. Is (a.b = c) a variable assignment or arbitrary function call? Who knows! Is a.b an actual variable? Can I write &a.b to get its address, or is it a function masquerading as a variable?Hm, actually that's not bad.5. One less language feature to implement, learn, document, debug, and discuss.Back to yes.Is it practical or realistic to throw it out at this stage? I don't know. But there are reasons to.Me neither. If I had my way I'd carefully redo the feature to only require property on rare cases that would otherwise be ambiguous, and make parens optional everywhere else. Andrei
Jan 17 2012
On Tue, 17 Jan 2012 18:29:11 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/17/12 5:13 PM, Peter Alexander wrote:The solution is easy, just don't start the discussion. Make a decision (property or no), and that's the end of it. My intuition says that you will purposely make the *wrong* choice just to try and get others to complain so you can "be right". The point of required property semantics is that the name of the function includes whether you need parentheses or not. a.empty does not have the same tone as a.empty(). The former looks like a field, the latter looks like an action. It's a subtle bikeshed issue, but so is naming functions anyways! If you think the names of things aren't important, name them whatever you want, but at least you as the author get to choose instead of the user. And if I may add my opinion, byValue and byKey are properties.On 17/01/12 10:11 PM, Jonathan M Davis wrote:Yes.You would need to come up with some really solid arguments why it should be thrown out (and what we should do instead) and get both Walter and Andrei (if not the community at large) to agree that they not only prefer your proposal but that it's worth the issues that the changes are going to cause at this stage.There's a few good reasons to throw it out: 1. Avoids pointless discussions like this one. These discussions add nothing, it's just mindless bike shedding.I think you misunderstand Peter, he is saying we should not have properties *at all* a-la Java.2. The -property flag *creates* a new kind of error, but doesn't actually help find real problems with your code. Without properties, member function access would always be a.b(), and this artificial error could be avoided.Yes! I can't believe we have a check that has _zero_ contribution to improving code.Don't forget my suggestion that void-returning no-arg functions should be able to be called without parens. There should be no ambiguity (since you can't use it as an accessor). But I think enforced properties is the right path, which gives all the naming power to the code author, not the code user. -SteveIs it practical or realistic to throw it out at this stage? I don't know. But there are reasons to.Me neither. If I had my way I'd carefully redo the feature to only require property on rare cases that would otherwise be ambiguous, and make parens optional everywhere else.
Jan 18 2012
On 1/18/12 7:44 AM, Steven Schveighoffer wrote:The solution is easy, just don't start the discussion. Make a decision (property or no), and that's the end of it. My intuition says that you will purposely make the *wrong* choice just to try and get others to complain so you can "be right".Well in this case I am right :o). We did a poor job at designing properties. Anyhow, I honestly asked simply because I found no clear cut decision. My intuition was that byXxx should be a property but I asked Walter whose intuition said it should be a method. So we agreed to ask the newsgroup.The point of required property semantics is that the name of the function includes whether you need parentheses or not. a.empty does not have the same tone as a.empty(). The former looks like a field, the latter looks like an action. It's a subtle bikeshed issue, but so is naming functions anyways!Yes, but the problem is this adds additional bikeshedding for no benefit.If you think the names of things aren't important, name them whatever you want, but at least you as the author get to choose instead of the user.I understand this point. It doesn't reduce the frustration that we have a feature that does not palpably improve the language.And if I may add my opinion, byValue and byKey are properties.I agree. The current code has them as properties. My thoughts are, a property should reasonably replace a member variable (of which syntax it mimics). So x.length should be property, x.dup shouldn't. Now byXxx can be considered member variables but only as long as it's not considered an lvalue: r.byKey.popFront() does nothing interesting, but would do if r.byKey were actually a member variable. I think that distinction still does not impair byXxx's right to be a property. Andrei
Jan 18 2012
On Wed, 18 Jan 2012 09:13:37 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/18/12 7:44 AM, Steven Schveighoffer wrote:Then I withdraw the "being spiteful" suggestion, it was probably unfair. But the "I told you" didn't set the tone very well for this discussion :)The solution is easy, just don't start the discussion. Make a decision (property or no), and that's the end of it. My intuition says that you will purposely make the *wrong* choice just to try and get others to complain so you can "be right".Well in this case I am right :o). We did a poor job at designing properties. Anyhow, I honestly asked simply because I found no clear cut decision. My intuition was that byXxx should be a property but I asked Walter whose intuition said it should be a method. So we agreed to ask the newsgroup.Disagree on both points :) property with enforcement is the right answer, it improves the language significantly, bringing it in line with most other property-enabled C-like languages.The point of required property semantics is that the name of the function includes whether you need parentheses or not. a.empty does not have the same tone as a.empty(). The former looks like a field, the latter looks like an action. It's a subtle bikeshed issue, but so is naming functions anyways!Yes, but the problem is this adds additional bikeshedding for no benefit.If you think the names of things aren't important, name them whatever you want, but at least you as the author get to choose instead of the user.I understand this point. It doesn't reduce the frustration that we have a feature that does not palpably improve the language.I think the difference between what should be a property and what shouldn't is not black and white. There is no easy way to define it. The best I can come up with is, if it gets something that is logically a piece of the object, then it should be a property (even if it makes a copy of that something). If it creates something separate from the object, or modifies the object, it should be a method. -SteveAnd if I may add my opinion, byValue and byKey are properties.I agree. The current code has them as properties. My thoughts are, a property should reasonably replace a member variable (of which syntax it mimics). So x.length should be property, x.dup shouldn't. Now byXxx can be considered member variables but only as long as it's not considered an lvalue: r.byKey.popFront() does nothing interesting, but would do if r.byKey were actually a member variable. I think that distinction still does not impair byXxx's right to be a property.
Jan 18 2012
On 1/18/12 8:34 AM, Steven Schveighoffer wrote:On Wed, 18 Jan 2012 09:13:37 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Indeed I told you all! Every time we add anything, there's going to be sh... stuff like this.On 1/18/12 7:44 AM, Steven Schveighoffer wrote:Then I withdraw the "being spiteful" suggestion, it was probably unfair. But the "I told you" didn't set the tone very well for this discussion :)The solution is easy, just don't start the discussion. Make a decision (property or no), and that's the end of it. My intuition says that you will purposely make the *wrong* choice just to try and get others to complain so you can "be right".Well in this case I am right :o). We did a poor job at designing properties. Anyhow, I honestly asked simply because I found no clear cut decision. My intuition was that byXxx should be a property but I asked Walter whose intuition said it should be a method. So we agreed to ask the newsgroup.This is not an argument. It's good because it's like in other languages where it's supposed to be good. And it's not "the right answer" when there's nothing to be answered.I understand this point. It doesn't reduce the frustration that we have a feature that does not palpably improve the language.Disagree on both points :) property with enforcement is the right answer, it improves the language significantly, bringing it in line with most other property-enabled C-like languages.If that's the case, then there shouldn't be a black-and-white distinction in the language about it.I think the difference between what should be a property and what shouldn't is not black and white. There is no easy way to define it.And if I may add my opinion, byValue and byKey are properties.I agree. The current code has them as properties. My thoughts are, a property should reasonably replace a member variable (of which syntax it mimics). So x.length should be property, x.dup shouldn't. Now byXxx can be considered member variables but only as long as it's not considered an lvalue: r.byKey.popFront() does nothing interesting, but would do if r.byKey were actually a member variable. I think that distinction still does not impair byXxx's right to be a property.The best I can come up with is, if it gets something that is logically a piece of the object, then it should be a property (even if it makes a copy of that something). If it creates something separate from the object, or modifies the object, it should be a method.The fact that reasonable people disagree, and that choosing one way or another has zero impact on the quality of the code, makes this feature a costly mistake. Andrei
Jan 18 2012
On Wed, 18 Jan 2012 09:40:00 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/18/12 8:34 AM, Steven Schveighoffer wrote:All of your arguments were subjective "doesn't palpably change the language" "all it does it generate these [in your opinion] useless discussions", why can't mine be? And you did say you were right, when clearly you are wrong :)On Wed, 18 Jan 2012 09:13:37 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Indeed I told you all! Every time we add anything, there's going to be sh... stuff like this.On 1/18/12 7:44 AM, Steven Schveighoffer wrote:Then I withdraw the "being spiteful" suggestion, it was probably unfair. But the "I told you" didn't set the tone very well for this discussion :)The solution is easy, just don't start the discussion. Make a decision (property or no), and that's the end of it. My intuition says that you will purposely make the *wrong* choice just to try and get others to complain so you can "be right".Well in this case I am right :o). We did a poor job at designing properties. Anyhow, I honestly asked simply because I found no clear cut decision. My intuition was that byXxx should be a property but I asked Walter whose intuition said it should be a method. So we agreed to ask the newsgroup.This is not an argument. It's good because it's like in other languages where it's supposed to be good. And it's not "the right answer" when there's nothing to be answered.I understand this point. It doesn't reduce the frustration that we have a feature that does not palpably improve the language.Disagree on both points :) property with enforcement is the right answer, it improves the language significantly, bringing it in line with most other property-enabled C-like languages.The language defines the mechanisms of enforcement, not when to use them. Any time it's a human interpretation of something, the language has to step back and say "you're the boss, you tell me what to do and I'll enforce it." The problem with the current situation is that there is no enforcement. You can suggest a certain usage, and be completely ignored. I liken it to case sensitivity. We could say symbol names aren't case sensitive, and that anyone can use any casing to call a function. But then the author of the function has lost control of what his function names look like. Since D enforced case sensitivity from the beginning, there is never a post saying "should this function be called isUseless or IsUseless. Grr... why on earth do we have case sensitivity anyways, it just generates useless discussions!" But go try to suggest to some language community that has case insensitive symbols that they should add case sensitivity enforcement, and you'll get shit like that.If that's the case, then there shouldn't be a black-and-white distinction in the language about it.I think the difference between what should be a property and what shouldn't is not black and white. There is no easy way to define it.And if I may add my opinion, byValue and byKey are properties.I agree. The current code has them as properties. My thoughts are, a property should reasonably replace a member variable (of which syntax it mimics). So x.length should be property, x.dup shouldn't. Now byXxx can be considered member variables but only as long as it's not considered an lvalue: r.byKey.popFront() does nothing interesting, but would do if r.byKey were actually a member variable. I think that distinction still does not impair byXxx's right to be a property.The error in that sentence is "has zero impact." It has an impact, about as significant as choosing a good symbol name. -SteveThe best I can come up with is, if it gets something that is logically a piece of the object, then it should be a property (even if it makes a copy of that something). If it creates something separate from the object, or modifies the object, it should be a method.The fact that reasonable people disagree, and that choosing one way or another has zero impact on the quality of the code, makes this feature a costly mistake.
Jan 18 2012
On Wednesday, January 18, 2012 08:13:37 Andrei Alexandrescu wrote:On 1/18/12 7:44 AM, Steven Schveighoffer wrote:There are those of us who _do_ think that it palpably improves the language. I think that the issue is more that we have a feature that is rather divisive as to whether it's an improvement or not. Some think that it definitely is, and some think it definitely isn't. It's not one of those features where pretty much everyone agrees that it's an improvement. - Jonathan M DavisIf you think the names of things aren't important, name them whatever you want, but at least you as the author get to choose instead of the user.I understand this point. It doesn't reduce the frustration that we have a feature that does not palpably improve the language.
Jan 18 2012
On 1/17/12 8:29 PM, Andrei Alexandrescu wrote:On 1/17/12 5:13 PM, Peter Alexander wrote:Before I knew Ruby I was in favor of property. Now I'm against it.On 17/01/12 10:11 PM, Jonathan M Davis wrote:Yes.You would need to come up with some really solid arguments why it should be thrown out (and what we should do instead) and get both Walter and Andrei (if not the community at large) to agree that they not only prefer your proposal but that it's worth the issues that the changes are going to cause at this stage.There's a few good reasons to throw it out: 1. Avoids pointless discussions like this one. These discussions add nothing, it's just mindless bike shedding.2. The -property flag *creates* a new kind of error, but doesn't actually help find real problems with your code. Without properties, member function access would always be a.b(), and this artificial error could be avoided.Yes! I can't believe we have a check that has _zero_ contribution to improving code.3. Properties introduce another thing to remember, with no value ("was it byKeys, or byKeys()?"). Without properties, it would be byKeys(). No need to remember.YES!!!4. Properties obfuscate code. Is (a.b = c) a variable assignment or arbitrary function call? Who knows! Is a.b an actual variable? Can I write &a.b to get its address, or is it a function masquerading as a variable?Hm, actually that's not bad.5. One less language feature to implement, learn, document, debug, and discuss.Back to yes.Is it practical or realistic to throw it out at this stage? I don't know. But there are reasons to.Me neither. If I had my way I'd carefully redo the feature to only require property on rare cases that would otherwise be ambiguous, and make parens optional everywhere else. Andrei
Jan 19 2012
"Peter Alexander" <peter.alexander.au gmail.com> wrote in message news:jf4ull$n6b$1 digitalmars.com...On 17/01/12 10:11 PM, Jonathan M Davis wrote:Andrei's the only one that ever starts any of this "Is this a property or func?!?" nonsense, because he's been against the distinction from the start. We finally got him to give in due to the delegate ambiguity, and he's been bitching about it at every opportinity since.You would need to come up with some really solid arguments why it should be thrown out (and what we should do instead) and get both Walter and Andrei (if not the community at large) to agree that they not only prefer your proposal but that it's worth the issues that the changes are going to cause at this stage.There's a few good reasons to throw it out: 1. Avoids pointless discussions like this one. These discussions add nothing, it's just mindless bike shedding.2. The -property flag *creates* a new kind of error, but doesn't actually help find real problems with your code. Without properties, member function access would always be a.b(), and this artificial error could be avoided.Bullshit. Without properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!3. Properties introduce another thing to remember, with no value ("was it byKeys, or byKeys()?"). Without properties, it would be byKeys(). No need to remember.Of *course* there's a need to remember useless shit: There's a need to remember that it's implemented as a function and not just simply as a member variable. In this *particular* case it may be a little easier since we know it returns range, but what about "aa.keys"? What about every other property out there?4. Properties obfuscate code. Is (a.b = c) a variable assignment or arbitrary function call? Who knows! Is a.b an actual variable?Who the hell cares? The whole damn *point* is that you don't have to give a shit about the member's implementation on *every* fucking member access. If you want transparency, use assembler.Can I write &a.b to get its address, or is it a function masquerading as a variable?That's only an issue when you actually want to take the address of something (and there are ways to improve that situation anyway). But forcing every property to be used as if it were a function instead of data access forces the user to figure out how it's implemented *EVERY* time it's accessed.5. One less language feature to implement, learn, document, debug, and discuss.So we're taking the Java/JavaScript/Brainfuck route of "minimal language == good langauge" now?Is it practical or realistic to throw it out at this stage?I wouldn't think so even if I wanted them gone.I don't know. But there are reasons to.No there aren't. The only reason to throw it out is that Andrei keeps whining and moaning about it just because it's something he can't/won't grok. But being that he's Andrei, that just might end up being enough of a reason, which is why I'm so insistent about the matter.
Jan 17 2012
"Nick Sabalausky" <a a.a> wrote in message news:jf53c2$u86$1 digitalmars.com..."Peter Alexander" <peter.alexander.au gmail.com> wrote in message news:jf4ull$n6b$1 digitalmars.com...Obviously, I need to re-proofread *after* I edit... ;) The: "...member function access *ANY* many..." Should be: "...member function accesses *AND* many..." (Little less grammatically non-sensical that way ;) )2. The -property flag *creates* a new kind of error, but doesn't actually help find real problems with your code. Without properties, member function access would always be a.b(), and this artificial error could be avoided.Bullshit. Without properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!
Jan 17 2012
Nick Sabalausky:Without properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!I have a partially related question. Currently this code compiles even with -property: void main() { int[int] aa = [1:2]; auto byval = aa.byValue(); } But I think byValue is a property, so isn't it right to give a compilation error if you add () after the name of a property? ----------------- By the way, I have just seen this code gives a Access Violation, I think it's a bug for Bugzilla: void main() { int[int] aa; auto byval = aa.byValue(); } Bye, bearophile
Jan 17 2012
On Tuesday, January 17, 2012 19:31:25 bearophile wrote:Nick Sabalausky:Definitely a bug. Strict enforcement requires that parens be used on all function calls and that no properties use parens. If you use parens on them, that would mean that you're using them on the return value of the property (e.g. opCall) - and in fact, that's one of the main reasons that property was added in the first place, since without enforcement, property functions which return a delegate result in an ambiguity. - Jonathan M DavisWithout properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!I have a partially related question. Currently this code compiles even with -property: void main() { int[int] aa = [1:2]; auto byval = aa.byValue(); } But I think byValue is a property, so isn't it right to give a compilation error if you add () after the name of a property?
Jan 17 2012
Jonathan M Davis:Definitely a bug. Strict enforcement requires that parens be used on all function calls and that no properties use parens.I agree! I'll take a look in Bugzilla if this bug report is already present. Thank you for your answers :-) Bye, bearophile
Jan 17 2012
On 01/18/2012 01:40 AM, Jonathan M Davis wrote:On Tuesday, January 17, 2012 19:31:25 bearophile wrote:A related and way more embarrassing problem is that lazy function parameters have the same issue. This program prints nothing: import std.stdio; void foo(lazy void delegate() dg){ dg(); } void main(){ foo({writeln("hello");}); }Nick Sabalausky:Definitely a bug. Strict enforcement requires that parens be used on all function calls and that no properties use parens. If you use parens on them, that would mean that you're using them on the return value of the property (e.g. opCall) - and in fact, that's one of the main reasons that property was added in the first place, since without enforcement, property functions which return a delegate result in an ambiguity. - Jonathan M DavisWithout properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!I have a partially related question. Currently this code compiles even with -property: void main() { int[int] aa = [1:2]; auto byval = aa.byValue(); } But I think byValue is a property, so isn't it right to give a compilation error if you add () after the name of a property?
Jan 17 2012
On 18/01/12 12:52 AM, Timon Gehr wrote:On 01/18/2012 01:40 AM, Jonathan M Davis wrote:Perhaps I'm wrong, but this issue is different. The code you have written is something that would be written by someone that doesn't understand how lazy works. You have to use () to un-lazy it, and then () again to invoke the delegate. There is no ambiguity like there is with property delegates.On Tuesday, January 17, 2012 19:31:25 bearophile wrote:A related and way more embarrassing problem is that lazy function parameters have the same issue. This program prints nothing: import std.stdio; void foo(lazy void delegate() dg){ dg(); } void main(){ foo({writeln("hello");}); }Nick Sabalausky:Definitely a bug. Strict enforcement requires that parens be used on all function calls and that no properties use parens. If you use parens on them, that would mean that you're using them on the return value of the property (e.g. opCall) - and in fact, that's one of the main reasons that property was added in the first place, since without enforcement, property functions which return a delegate result in an ambiguity. - Jonathan M DavisWithout properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!I have a partially related question. Currently this code compiles even with -property: void main() { int[int] aa = [1:2]; auto byval = aa.byValue(); } But I think byValue is a property, so isn't it right to give a compilation error if you add () after the name of a property?
Jan 18 2012
On 19-01-2012 01:41, Peter Alexander wrote:On 18/01/12 12:52 AM, Timon Gehr wrote:But couldn't that be considered leaking an implementation detail of lazy values? Or is this intentional design? -- - AlexOn 01/18/2012 01:40 AM, Jonathan M Davis wrote:Perhaps I'm wrong, but this issue is different. The code you have written is something that would be written by someone that doesn't understand how lazy works. You have to use () to un-lazy it, and then () again to invoke the delegate. There is no ambiguity like there is with property delegates.On Tuesday, January 17, 2012 19:31:25 bearophile wrote:A related and way more embarrassing problem is that lazy function parameters have the same issue. This program prints nothing: import std.stdio; void foo(lazy void delegate() dg){ dg(); } void main(){ foo({writeln("hello");}); }Nick Sabalausky:Definitely a bug. Strict enforcement requires that parens be used on all function calls and that no properties use parens. If you use parens on them, that would mean that you're using them on the return value of the property (e.g. opCall) - and in fact, that's one of the main reasons that property was added in the first place, since without enforcement, property functions which return a delegate result in an ambiguity. - Jonathan M DavisWithout properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!I have a partially related question. Currently this code compiles even with -property: void main() { int[int] aa = [1:2]; auto byval = aa.byValue(); } But I think byValue is a property, so isn't it right to give a compilation error if you add () after the name of a property?
Jan 18 2012
On 01/19/2012 01:38 AM, Alex Rønne Petersen wrote:On 19-01-2012 01:41, Peter Alexander wrote:I suppose it is an implementation relic.On 18/01/12 12:52 AM, Timon Gehr wrote:But couldn't that be considered leaking an implementation detail of lazy values? Or is this intentional design?On 01/18/2012 01:40 AM, Jonathan M Davis wrote:Perhaps I'm wrong, but this issue is different. The code you have written is something that would be written by someone that doesn't understand how lazy works. You have to use () to un-lazy it, and then () again to invoke the delegate. There is no ambiguity like there is with property delegates.On Tuesday, January 17, 2012 19:31:25 bearophile wrote:A related and way more embarrassing problem is that lazy function parameters have the same issue. This program prints nothing: import std.stdio; void foo(lazy void delegate() dg){ dg(); } void main(){ foo({writeln("hello");}); }Nick Sabalausky:Definitely a bug. Strict enforcement requires that parens be used on all function calls and that no properties use parens. If you use parens on them, that would mean that you're using them on the return value of the property (e.g. opCall) - and in fact, that's one of the main reasons that property was added in the first place, since without enforcement, property functions which return a delegate result in an ambiguity. - Jonathan M DavisWithout properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!I have a partially related question. Currently this code compiles even with -property: void main() { int[int] aa = [1:2]; auto byval = aa.byValue(); } But I think byValue is a property, so isn't it right to give a compilation error if you add () after the name of a property?
Jan 18 2012
On Thursday, January 19, 2012 01:38:23 Alex Rønne Petersen wrote:But couldn't that be considered leaking an implementation detail of lazy values? Or is this intentional design?The language requires that lazy parameters be accessed with (). That leaks the fact that the variable is lazy into the function body, but whether it leaks how lazy parameters are implemented is debatable. The same syntax could be used with a different implementation underneath the hood. But the fact that you have to use double parens on a lazy delegate isn't leaking any kind of implemenatation detail. It's the natural extension of the syntax for lazy. var() gives you the value of the lazy parameter var, and so if you want to call var (or use opCall or it), then you need another set of parens - var()(). Whether requiring parens on lazy parameters is a good design decision is debatable, but I don't see any leaking of implementation details in it. The syntax chosen was probably chosen because it's implemented with a delegate, but the fact that it's implemented with a delegate is still an implementation detail which could theoretically be changed. - Jonathan M Davis
Jan 18 2012
On 01/19/2012 01:52 AM, Jonathan M Davis wrote:On Thursday, January 19, 2012 01:38:23 Alex Rønne Petersen wrote:They are only required if you want to call a lazy delegate/function pointer. They are optional in all other cases.But couldn't that be considered leaking an implementation detail of lazy values? Or is this intentional design?The language requires that lazy parameters be accessed with (). That leaks the fact that the variable is lazy into the function body, but whether it leaks how lazy parameters are implemented is debatable. The same syntax could be used with a different implementation underneath the hood. But the fact that you have to use double parens on a lazy delegate isn't leaking any kind of implemenatation detail. It's the natural extension of the syntax for lazy. var() gives you the value of the lazy parameter var, and so if you want to call var (or use opCall or it), then you need another set of parens - var()(). Whether requiring parens on lazy parameters is a good design decision is debatable,but I don't see any leaking of implementation details in it. The syntax chosen was probably chosen because it's implemented with a delegate, but the fact that it's implemented with a delegate is still an implementation detail which could theoretically be changed.
Jan 18 2012
On Thursday, January 19, 2012 03:18:22 Timon Gehr wrote:They are only required if you want to call a lazy delegate/function pointer. They are optional in all other cases.I could have sworn that they were required. If not, then yeah, that seems pretty bad. It's certainly not the end of the world, but it's inconsistent in away that has caused problem for some people (Andrej was posting about it just the other day). So, it's poor design in that respect. - Jonathan M Davis
Jan 18 2012
On 01/19/2012 01:41 AM, Peter Alexander wrote:On 18/01/12 12:52 AM, Timon Gehr wrote:It is written by someone who understands how it should work.On 01/18/2012 01:40 AM, Jonathan M Davis wrote:Perhaps I'm wrong, but this issue is different. The code you have written is something that would be written by someone that doesn't understand how lazy works.On Tuesday, January 17, 2012 19:31:25 bearophile wrote:A related and way more embarrassing problem is that lazy function parameters have the same issue. This program prints nothing: import std.stdio; void foo(lazy void delegate() dg){ dg(); } void main(){ foo({writeln("hello");}); }Nick Sabalausky:Definitely a bug. Strict enforcement requires that parens be used on all function calls and that no properties use parens. If you use parens on them, that would mean that you're using them on the return value of the property (e.g. opCall) - and in fact, that's one of the main reasons that property was added in the first place, since without enforcement, property functions which return a delegate result in an ambiguity. - Jonathan M DavisWithout properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!I have a partially related question. Currently this code compiles even with -property: void main() { int[int] aa = [1:2]; auto byval = aa.byValue(); } But I think byValue is a property, so isn't it right to give a compilation error if you add () after the name of a property?You have to use () to un-lazyWhat would 'un-lazying' be and what is supposed to be its effect?it, and then () again to invoke the delegate. There is no ambiguity like there is with property delegates.The code has exactly the same semantics whether or not you write the parens after a lazy variable except for the case when it is a delegate or function pointer.
Jan 18 2012
On 19/01/12 12:51 AM, Timon Gehr wrote:On 01/19/2012 01:41 AM, Peter Alexander wrote:Under the hood, lazy is just a delegate with different syntax. void foo(lazy int x) {} int a; foo(a++); Essentially translates to: void foo(int delegate() x) {} int a; foo( { return a++; } ); Inside foo, you have to do x() to evaluate the delegate, just like normals delegates. x on its own without parens would just be the delegate variable. If you had a lazy delegate parameter then that is like a delegate that returns a delegate, so you have to do x()() to evaluate the returned delegate.On 18/01/12 12:52 AM, Timon Gehr wrote:It is written by someone who understands how it should work.On 01/18/2012 01:40 AM, Jonathan M Davis wrote:Perhaps I'm wrong, but this issue is different. The code you have written is something that would be written by someone that doesn't understand how lazy works.On Tuesday, January 17, 2012 19:31:25 bearophile wrote:A related and way more embarrassing problem is that lazy function parameters have the same issue. This program prints nothing: import std.stdio; void foo(lazy void delegate() dg){ dg(); } void main(){ foo({writeln("hello");}); }Nick Sabalausky:Definitely a bug. Strict enforcement requires that parens be used on all function calls and that no properties use parens. If you use parens on them, that would mean that you're using them on the return value of the property (e.g. opCall) - and in fact, that's one of the main reasons that property was added in the first place, since without enforcement, property functions which return a delegate result in an ambiguity. - Jonathan M DavisWithout properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!I have a partially related question. Currently this code compiles even with -property: void main() { int[int] aa = [1:2]; auto byval = aa.byValue(); } But I think byValue is a property, so isn't it right to give a compilation error if you add () after the name of a property?You have to use () to un-lazyWhat would 'un-lazying' be and what is supposed to be its effect?I was not aware of this. I believe this is a bug (or at least a design flaw).it, and then () again to invoke the delegate. There is no ambiguity like there is with property delegates.The code has exactly the same semantics whether or not you write the parens after a lazy variable except for the case when it is a delegate or function pointer.
Jan 19 2012
On 01/19/2012 03:47 PM, Peter Alexander wrote:On 19/01/12 12:51 AM, Timon Gehr wrote:It is more than that, type checking works differently for lazy values compared to scoped delegates.On 01/19/2012 01:41 AM, Peter Alexander wrote:Under the hood, lazy is just a delegate with different syntax.On 18/01/12 12:52 AM, Timon Gehr wrote:It is written by someone who understands how it should work.On 01/18/2012 01:40 AM, Jonathan M Davis wrote:Perhaps I'm wrong, but this issue is different. The code you have written is something that would be written by someone that doesn't understand how lazy works.On Tuesday, January 17, 2012 19:31:25 bearophile wrote:A related and way more embarrassing problem is that lazy function parameters have the same issue. This program prints nothing: import std.stdio; void foo(lazy void delegate() dg){ dg(); } void main(){ foo({writeln("hello");}); }Nick Sabalausky:Definitely a bug. Strict enforcement requires that parens be used on all function calls and that no properties use parens. If you use parens on them, that would mean that you're using them on the return value of the property (e.g. opCall) - and in fact, that's one of the main reasons that property was added in the first place, since without enforcement, property functions which return a delegate result in an ambiguity. - Jonathan M DavisWithout properties, member function access *ANY* many value accesses are "a.b()". Is this member value a plain-old-var or a function? Who knows! It's a leeked out implementation detail, hooray!I have a partially related question. Currently this code compiles even with -property: void main() { int[int] aa = [1:2]; auto byval = aa.byValue(); } But I think byValue is a property, so isn't it right to give a compilation error if you add () after the name of a property?You have to use () to un-lazyWhat would 'un-lazying' be and what is supposed to be its effect?void foo(lazy int x) {} int a; foo(a++); Essentially translates to: void foo(int delegate() x) {} int a; foo( { return a++; } ); Inside foo, you have to do x() to evaluate the delegate, just like normals delegates. x on its own without parens would just be the delegate variable. If you had a lazy delegate parameter then that is like a delegate that returns a delegate, so you have to do x()() to evaluate the returned delegate.I know what is under the hood, but I don't really care. Lazy is just another storage class, and as such it has no business changing the syntax using which the value is accessed.Parens should be removed completely from lazy values. They don't add a lot while being inconsistent with how other STCs work.I was not aware of this. I believe this is a bug (or at least a design flaw).it, and then () again to invoke the delegate. There is no ambiguity like there is with property delegates.The code has exactly the same semantics whether or not you write the parens after a lazy variable except for the case when it is a delegate or function pointer.
Jan 19 2012
On Thursday, January 19, 2012 18:33:15 Timon Gehr wrote:Parens should be removed completely from lazy values. They don't add a lot while being inconsistent with how other STCs work.Ignoring the fact that this will break code, I completely agree. However, given the fact that it's going to break code, I question that you we could get Walter to agree. It would definitely lead to the language being more consistent though. - Jonathan M Davis
Jan 19 2012
On Tuesday, January 17, 2012 23:13:21 Peter Alexander wrote:On 17/01/12 10:11 PM, Jonathan M Davis wrote:I'm fully aware that there are those who want to throw it out (e.g. Andrei) and that there are reasons for doing so. My point is that those reasons must be strong enough to justify the cost of getting rid of property at this stage in the game, or it's not going to happen. As it stands, we're going to have property with it being enforced. And there _are_ those of us who like it. I _do_ think that it's an improvement over what we had before. One of the primary reasons for properties IMHO is to be able to swap out functions and public member variables without breaking code, and that's not possible without something like property with strict enforcement. - Jonathan M DavisYou would need to come up with some really solid arguments why it should be thrown out (and what we should do instead) and get both Walter and Andrei (if not the community at large) to agree that they not only prefer your proposal but that it's worth the issues that the changes are going to cause at this stage.There's a few good reasons to throw it out: 1. Avoids pointless discussions like this one. These discussions add nothing, it's just mindless bike shedding. 2. The -property flag *creates* a new kind of error, but doesn't actually help find real problems with your code. Without properties, member function access would always be a.b(), and this artificial error could be avoided. 3. Properties introduce another thing to remember, with no value ("was it byKeys, or byKeys()?"). Without properties, it would be byKeys(). No need to remember. 4. Properties obfuscate code. Is (a.b = c) a variable assignment or arbitrary function call? Who knows! Is a.b an actual variable? Can I write &a.b to get its address, or is it a function masquerading as a variable? 5. One less language feature to implement, learn, document, debug, and discuss. Is it practical or realistic to throw it out at this stage? I don't know. But there are reasons to.
Jan 17 2012
Is it practical or realistic to throw it out at this stage? I don't know. But there are reasons to.I hope we are not dropping properties regardless of the syntax of how to call them. Keep property Keep methods-as-properties --------------------------------- (a) No () obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method; obj.method("first", "second"); --------------------------------- (b) Optional () for methods obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method; string str = obj.method(); obj.method("first", "second"); --------------------------------- (c) Mandatory () for methods obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method(); obj.method("first", "second"); --------------------------------- (d) Property and Method separated. (Is this the goal for -property?) obj.property = "test"; string str = obj.property; string str = obj.method(); obj.method("first"); obj.method("first", "second"); --------------------------------- Who likes (a) ? Also I think that the property opDispatch() looks weird.
Jan 18 2012
On 2012-01-18 09:30, sclytrack wrote:I would like this: property: getter - parentheses are not allowed setter: * equal sign is required * parentheses are not allowed method: no parameters - parentheses are optional parameters: * parentheses are required * equal sign is not allowed Examples: obj.property; // legal obj.property = 1; // legal obj.property(); // error obj.property(1); // error obj.method; // legal obj.method(); // legal obj.method(1); // legal obj.method = 1; // error -- /Jacob CarlborgIs it practical or realistic to throw it out at this stage? I don't know. But there are reasons to.I hope we are not dropping properties regardless of the syntax of how to call them. Keep property Keep methods-as-properties --------------------------------- (a) No () obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method; obj.method("first", "second"); --------------------------------- (b) Optional () for methods obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method; string str = obj.method(); obj.method("first", "second"); --------------------------------- (c) Mandatory () for methods obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method(); obj.method("first", "second"); --------------------------------- (d) Property and Method separated. (Is this the goal for -property?) obj.property = "test"; string str = obj.property; string str = obj.method(); obj.method("first"); obj.method("first", "second"); --------------------------------- Who likes (a) ? Also I think that the property opDispatch() looks weird.
Jan 18 2012
On Wed, 18 Jan 2012 07:33:45 -0500, Jacob Carlborg <doob me.com> wrote:On 2012-01-18 09:30, sclytrack wrote:what about: int x = obj.method; // passes by your rules, but I think should be illegal I think the parentheses should only be optional on void-returning methods. Otherwise, I agree with your list. -SteveI would like this: property: getter - parentheses are not allowed setter: * equal sign is required * parentheses are not allowed method: no parameters - parentheses are optional parameters: * parentheses are required * equal sign is not allowed Examples: obj.property; // legal obj.property = 1; // legal obj.property(); // error obj.property(1); // error obj.method; // legal obj.method(); // legal obj.method(1); // legal obj.method = 1; // errorIs it practical or realistic to throw it out at this stage? I don't know. But there are reasons to.I hope we are not dropping properties regardless of the syntax of how to call them. Keep property Keep methods-as-properties --------------------------------- (a) No () obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method; obj.method("first", "second"); --------------------------------- (b) Optional () for methods obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method; string str = obj.method(); obj.method("first", "second"); --------------------------------- (c) Mandatory () for methods obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method(); obj.method("first", "second"); --------------------------------- (d) Property and Method separated. (Is this the goal for -property?) obj.property = "test"; string str = obj.property; string str = obj.method(); obj.method("first"); obj.method("first", "second"); --------------------------------- Who likes (a) ? Also I think that the property opDispatch() looks weird.
Jan 18 2012
On 2012-01-18 14:47, Steven Schveighoffer wrote:On Wed, 18 Jan 2012 07:33:45 -0500, Jacob Carlborg <doob me.com> wrote:I could go either way with that one. But I think I prefer optional parentheses.On 2012-01-18 09:30, sclytrack wrote:what about: int x = obj.method; // passes by your rules, but I think should be illegalI would like this: property: getter - parentheses are not allowed setter: * equal sign is required * parentheses are not allowed method: no parameters - parentheses are optional parameters: * parentheses are required * equal sign is not allowed Examples: obj.property; // legal obj.property = 1; // legal obj.property(); // error obj.property(1); // error obj.method; // legal obj.method(); // legal obj.method(1); // legal obj.method = 1; // errorIs it practical or realistic to throw it out at this stage? I don't know. But there are reasons to.I hope we are not dropping properties regardless of the syntax of how to call them. Keep property Keep methods-as-properties --------------------------------- (a) No () obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method; obj.method("first", "second"); --------------------------------- (b) Optional () for methods obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method; string str = obj.method(); obj.method("first", "second"); --------------------------------- (c) Mandatory () for methods obj.property = "test"; string str = obj.property; obj.method = "string"; obj.method("first"); string str = obj.method(); obj.method("first", "second"); --------------------------------- (d) Property and Method separated. (Is this the goal for -property?) obj.property = "test"; string str = obj.property; string str = obj.method(); obj.method("first"); obj.method("first", "second"); --------------------------------- Who likes (a) ? Also I think that the property opDispatch() looks weird.I think the parentheses should only be optional on void-returning methods. Otherwise, I agree with your list. -Steve-- /Jacob Carlborg
Jan 18 2012
"Jacob Carlborg" <doob me.com> wrote in message news:jf6e7a$1929$1 digitalmars.com...method: no parameters - parentheses are optionalFWIW, I always do a double-take when I see code like: functionName; //or object.functionName; It sets off all mannar of "no-effect expression!" bells and buzzers in my head every time I look at it, which I then have to silence.
Jan 18 2012
"Nick Sabalausky" <a a.a> wrote in message news:jf79sh$2l7b$1 digitalmars.com..."Jacob Carlborg" <doob me.com> wrote in message news:jf6e7a$1929$1 digitalmars.com...Also it doesn't help that using the function name by itself (with no parens or &) can be used to pass a function as a template alias parameter (or just alias a function), instead of passing the result of the function call as the argument. Plus I've spent time in other langauges where using a function name without parens is the way to refer to a function itself, rather than invoke the function. That's something I very much like: "foo" refers to the function, "foo()" calls the function. Period. End of story. But in D, while "foo()" calls a function, refering to a function is a mess: usually it's "&foo", but if you're aliasing it or passing it as a template alias parameter than it's "foo". But then if you use "foo" in other places, it calls the function instead of referring to it! Bleh!!! Messy, messy.method: no parameters - parentheses are optionalFWIW, I always do a double-take when I see code like: functionName; //or object.functionName; It sets off all mannar of "no-effect expression!" bells and buzzers in my head every time I look at it, which I then have to silence.
Jan 18 2012
El 18/01/2012 21:37, Nick Sabalausky escribió:"Nick Sabalausky"<a a.a> wrote in message Plus I've spent time in other langauges where using a function name without parens is the way to refer to a function itself, rather than invoke the function. That's something I very much like: "foo" refers to the function, "foo()" calls the function. Period. End of story. But in D, while "foo()" calls a function, refering to a function is a mess: usually it's "&foo", but if you're aliasing it or passing it as a template alias parameter than it's "foo". But then if you use "foo" in other places, it calls the function instead of referring to it! Bleh!!! Messy, messy.Exactly, to my eyes the () is what says "execute!", what triggers the action, so: f = func; // even if not in D, looks like getting the function itself (a pointer to it) x = func(); // looks like "execute func" and assign its ret value to x even with void returning functions: doThat(); // the () is like "Action!" In fact, why not get rid of the & to get a reference to a function? So my vote is: properties: always without (), methods: always ()
Feb 05 2012
On 18-01-2012 21:26, Nick Sabalausky wrote:"Jacob Carlborg"<doob me.com> wrote in message news:jf6e7a$1929$1 digitalmars.com...Indeed! It's so unnatural in a C-based language. See, if the semicolon wasn't there, it would be a different story (see most ML-style functional languages). -- - Alexmethod: no parameters - parentheses are optionalFWIW, I always do a double-take when I see code like: functionName; //or object.functionName; It sets off all mannar of "no-effect expression!" bells and buzzers in my head every time I look at it, which I then have to silence.
Jan 18 2012
Alex Rønne Petersen wrote:if the semicolon wasn't there... it would look like a parameterless command in a shell: pwd, ls, du, df, date, uptime, ... -manfred
Jan 18 2012
On 2012-01-18 21:26, Nick Sabalausky wrote:"Jacob Carlborg"<doob me.com> wrote in message news:jf6e7a$1929$1 digitalmars.com...It's even more fun in Ruby which doesn't require semicolons :) Just: functionName -- /Jacob Carlborgmethod: no parameters - parentheses are optionalFWIW, I always do a double-take when I see code like: functionName; //or object.functionName; It sets off all mannar of "no-effect expression!" bells and buzzers in my head every time I look at it, which I then have to silence.
Jan 18 2012
On 01/17/2012 07:38 PM, Timon Gehr wrote:On 01/17/2012 07:48 AM, Andrei Alexandrescu wrote:Can't we drop the empty (). It's too much typing. You don't need them in Delphi and Delphi has properties.I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuIMO it does not matter. I think we should just deprecate the -property switch instead of engaging into that kind of fruitless discussion every now and then. ;)
Jan 17 2012
Le 17/01/2012 07:48, Andrei Alexandrescu a écrit :I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuMicrosoft guidelines: http://msdn.microsoft.com/en-us/library/ms229054.aspx http://msdn.microsoft.com/en-us/library/bzwdh01d%28v=vs.71%29.aspx Googling "method vs property" gives different answers to this recurring question.
Jan 17 2012
On 17/01/12 6:48 AM, Andrei Alexandrescu wrote:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescubyKey(aa) Roll a dice, choose one at random. The only thing properties are good for is distracting us from tabs vs. spaces debates, and other really, really important matters.
Jan 17 2012
On Tue, 17 Jan 2012 22:13:49 +0100, Peter Alexander <peter.alexander.au gmail.com> wrote:On 17/01/12 6:48 AM, Andrei Alexandrescu wrote:But the current compiler behavior is really annoying. Either nobody should use enforced properties or it should be part of the standard warning level.I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescubyKey(aa) Roll a dice, choose one at random. The only thing properties are good for is distracting us from tabs vs. spaces debates, and other really, really important matters.
Jan 18 2012
On Wednesday, January 18, 2012 09:38:41 Martin Nowak wrote:But the current compiler behavior is really annoying. Either nobody should use enforced properties or it should be part of the standard warning level.Once the implementation of -property has been fully sorted out, I believe that it will be moved to the standard warning level, and then finally to an error, since per TDPL it's a requirement of the language that properties not be called with parens and that non-property functions _must_ be called with parens. The problem is that we're still in the transition period. - Jonathan M Davis
Jan 18 2012
Andrei Alexandrescu:I hate I must ask this:I am sorry to see you do something you hate :-( Regarding your question, I'd like keys/values to require () because they do lot of work to create the dynamic array, while I like byKey/byValue to be properties because (I think) their creation is O(1). But now we can't change keys/values. So I'd like to keep all five of them as properties. I'd like a byPair property too: http://d.puremagic.com/issues/show_bug.cgi?id=5466 --------------------- There is also the question about code like this: http://d.puremagic.com/issues/show_bug.cgi?id=5075 import std.algorithm; void main() { auto aa = ["red":2, "yellow":3]; auto r = map(n => n * n)(aa); } Bye, bearophile
Jan 17 2012
On 1/17/12 4:49 PM, bearophile wrote:Andrei Alexandrescu:byPair is tricky because std.tuple is not visible from object. AndreiI hate I must ask this:I am sorry to see you do something you hate :-( Regarding your question, I'd like keys/values to require () because they do lot of work to create the dynamic array, while I like byKey/byValue to be properties because (I think) their creation is O(1). But now we can't change keys/values. So I'd like to keep all five of them as properties. I'd like a byPair property too: http://d.puremagic.com/issues/show_bug.cgi?id=5466
Jan 17 2012
Andrei Alexandrescu:I will add this answer to the issue 5466. But I hope we'll have the unpacking syntax sugar for tuples. I think this too requires object to see tuples. There are functions in std.math that are better to return a tuple. While having complex numbers as built-in in D is not that useful for most people, I believe tuples are a basic language data type, even more than associative arrays :-) By the way, I have already started using byKey/byValue ranges in my code, and I've already seen a speedup in some programs :-) Bye, bearophileI'd like a byPair property too: http://d.puremagic.com/issues/show_bug.cgi?id=5466byPair is tricky because std.tuple is not visible from object.
Jan 17 2012
Is there even a point to having byKey/byValue? Once UFCS comes in (and there's already a seemingly working pull request for it), having .keys return a range like byKey/byValue should will be a silent (though more efficient) change for most programs. And in the situations where it's not (namely when you want to store it as an array), just adding a .array at the end would work. On 17/01/2012 12:48 AM, Andrei Alexandrescu wrote:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" Alexandrescu
Jan 17 2012
On Tue, 17 Jan 2012 19:00:38 -0500, Kapps <Kapps notvalidemail.com> wrote:Is there even a point to having byKey/byValue? Once UFCS comes in (and there's already a seemingly working pull request for it), having .keys return a range like byKey/byValue should will be a silent (though more efficient) change for most programs. And in the situations where it's not (namely when you want to store it as an array), just adding a .array at the end would work.It changes semantics. For example: foreach(k; a.keys) { if(shouldRemove(k)) a.remove(k); // this is currently valid } -Steve
Jan 18 2012
Le 17/01/2012 07:48, Andrei Alexandrescu a écrit :I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuI vote for the methods. Cheers, Olivier
Jan 18 2012
On 17.01.2012 07:48, Andrei Alexandrescu wrote:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }For it to be a property, I think you should be able to simplify this example: --- auto k = aa.byKey; writeln(k.front); k.popFront(); writeln(k.front); --- to this: --- writeln(k.byKey.front); k.byKey.popFront(); writeln(k.byKey.front); --- and get the same result. But my understanding is that you wouldn't, in which case byKey doesn't sense to me as a property. It creates and returns a new range object each time you call it, right?
Jan 19 2012
On 19.01.2012 18:19, torhu wrote:On 17.01.2012 07:48, Andrei Alexandrescu wrote:Sorry, I meant this for the second example: --- writeln(aa.byKey.front); aa.byKey.popFront(); writeln(aa.byKey.front); ---I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }For it to be a property, I think you should be able to simplify this example: --- auto k = aa.byKey; writeln(k.front); k.popFront(); writeln(k.front); --- to this: --- writeln(k.byKey.front); k.byKey.popFront(); writeln(k.byKey.front); --- and get the same result. But my understanding is that you wouldn't, in which case byKey doesn't sense to me as a property. It creates and returns a new range object each time you call it, right?
Jan 19 2012
On 19.01.2012 18:21, torhu wrote:On 19.01.2012 18:19, torhu wrote:The reason would be that if it looks like field access, it should behave like that. People will quickly learn how this works, like they have gotten used to .dup and similar, but what happens when third-party libraries start doing it too? It think this is not a good precedence to set. We already have fields and functions, this would be a third kind, one that looks like a field but behaves more like a function.On 17.01.2012 07:48, Andrei Alexandrescu wrote:Sorry, I meant this for the second example: --- writeln(aa.byKey.front); aa.byKey.popFront(); writeln(aa.byKey.front); ---I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }For it to be a property, I think you should be able to simplify this example: --- auto k = aa.byKey; writeln(k.front); k.popFront(); writeln(k.front); --- to this: --- writeln(k.byKey.front); k.byKey.popFront(); writeln(k.byKey.front); --- and get the same result. But my understanding is that you wouldn't, in which case byKey doesn't sense to me as a property. It creates and returns a new range object each time you call it, right?
Jan 19 2012
On 1/19/12 11:29 AM, torhu wrote:The reason would be that if it looks like field access, it should behave like that.The difficulty is in knowing where to stop. The only things that behaves exactly like a field access is a field access. This is a known issue in C++, e.g. smart pointers "are smart but aren't pointers". Andrei
Jan 19 2012
On Thursday, January 19, 2012 11:33:24 Andrei Alexandrescu wrote:On 1/19/12 11:29 AM, torhu wrote:Yeah. It's generally expected that properties may return stuff which is generated on each call. They're _simulating_ a member variable rather than being one. I don't think that the fact that a new value is returned each time is particularly relevant, especially since as long as the AA hasn't been altered, the returned values are equivalent. - Jonathan M DavisThe reason would be that if it looks like field access, it should behave like that.The difficulty is in knowing where to stop. The only things that behaves exactly like a field access is a field access. This is a known issue in C++, e.g. smart pointers "are smart but aren't pointers".
Jan 19 2012
Am 19.01.2012, 19:19 Uhr, schrieb Jonathan M Davis <jmdavisProg gmx.com>:On Thursday, January 19, 2012 11:33:24 Andrei Alexandrescu wrote:I just came across some C++ code and came to the conclusion, that properties and indexed access should not modify the structure. In other words all my property and opIndex will probably also by const. An exception to that being caching and access counting.On 1/19/12 11:29 AM, torhu wrote:Yeah. It's generally expected that properties may return stuff which is generated on each call. They're _simulating_ a member variable rather than being one. I don't think that the fact that a new value is returned each time is particularly relevant, especially since as long as the AA hasn't been altered, the returned values are equivalent. - Jonathan M DavisThe reason would be that if it looks like field access, it shouldbehavelike that.The difficulty is in knowing where to stop. The only things that behaves exactly like a field access is a field access. This is a known issue in C++, e.g. smart pointers "are smart but aren't pointers".
Jan 19 2012
On Thursday, January 19, 2012 20:56:39 Marco Leise wrote:I just came across some C++ code and came to the conclusion, that properties and indexed access should not modify the structure. In other words all my property and opIndex will probably also by const. An exception to that being caching and access counting.I don't know why you came to that concluson. I don't agree at all. Obviously, you're free to do what you want with your code, but that seems overly restrictive to little or no benefit. Properties can be both getters and setters for a reason. It would be horrible if all you had were getters. - Jonathan M Davis
Jan 19 2012
Am 19.01.2012, 21:53 Uhr, schrieb Jonathan M Davis <jmdavisProg gmx.com>:On Thursday, January 19, 2012 20:56:39 Marco Leise wrote:Ah, I meant to say that getters should not modify their object. When I see "a = abc.x[i]" I would be a little surprised to find that it changes the observable state of abc. The same goes for "a = b.length()". Now it is clearer, isn't is? :pI just came across some C++ code and came to the conclusion, that properties and indexed access should not modify the structure. In other words all my property and opIndex will probably also by const. An exception to that being caching and access counting.I don't know why you came to that concluson. I don't agree at all. Obviously, you're free to do what you want with your code, but that seems overly restrictive to little or no benefit. Properties can be both getters and setters for a reason. It would be horrible if all you had were getters. - Jonathan M Davis
Jan 20 2012
On Friday, January 20, 2012 09:58:42 Marco Leise wrote:Ah, I meant to say that getters should not modify their object. When I see "a = abc.x[i]" I would be a little surprised to find that it changes the observable state of abc. The same goes for "a = b.length()". Now it is clearer, isn't is? :pYes. Generally, setters should be used to set rather than getters doing it one way or another, though I have no idea how either of your examples there would result in the getter changing anything. However, if a getter property returns a ref, then it's both a getter and a setter. But whether exposing the underlying variable like that makes sense depends on the property - generally not, I think. The one major place where you essentially have a getter being able to modifer the original through its return value in C++ that I'm aware of is the subscript operator, and it has to in order to function like the built-in substript operator, so that's a special case. - Jonathan M Davis
Jan 20 2012
El 20/01/2012 10:15, Jonathan M Davis escribió:On Friday, January 20, 2012 09:58:42 Marco Leise wrote:Well, there is the case of std::map and its [] operator which adds an element if it does not exist. Even if in the right hand side: a = map[x]; // modifies map if x was not found in it Maybe Marco is talking about something like that.Ah, I meant to say that getters should not modify their object. When I see "a = abc.x[i]" I would be a little surprised to find that it changes the observable state of abc. The same goes for "a = b.length()". Now it is clearer, isn't is? :pThe one major place where you essentially have a getter being able to modifer the original through its return value in C++ that I'm aware of is the subscript operator, and it has to in order to function like the built-in substript operator, so that's a special case. - Jonathan M Davis
Jan 20 2012
On Friday, January 20, 2012 15:13:51 Alvaro wrote:Well, there is the case of std::map and its [] operator which adds an element if it does not exist. Even if in the right hand side: a = map[x]; // modifies map if x was not found in it Maybe Marco is talking about something like that.Maybe. It's certainly a pretty horrible design decision IMHO, and it's not something that should be emulated. - Jonathan M Davis
Jan 20 2012
On 1/19/12 11:19 AM, torhu wrote:On 17.01.2012 07:48, Andrei Alexandrescu wrote:Yah, this is the lvalue vs. rvalue part. I think you are making a good argument. AndreiI hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }For it to be a property, I think you should be able to simplify this example: --- auto k = aa.byKey; writeln(k.front); k.popFront(); writeln(k.front); --- to this: --- writeln(k.byKey.front); k.byKey.popFront(); writeln(k.byKey.front); --- and get the same result. But my understanding is that you wouldn't, in which case byKey doesn't sense to me as a property. It creates and returns a new range object each time you call it, right?
Jan 19 2012
On Thu, 19 Jan 2012 12:19:09 -0500, torhu <no spam.invalid> wrote:On 17.01.2012 07:48, Andrei Alexandrescu wrote:That's like saying this: int[] arr; int l = arr.length; l++; should be the same as this: arr.length++; because it's a property. This is an orthogonal problem. byKey doesn't try to affect the original AA, so the semantics should be the same whether you save a copy or access it in one line. There are no hard-fast rules on what should be properties and what shouldn't. But the rvalue vs lvalue is an orthogonal problem. -SteveI hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }For it to be a property, I think you should be able to simplify this example: --- auto k = aa.byKey; writeln(k.front); k.popFront(); writeln(k.front); --- to this: --- writeln(k.byKey.front); k.byKey.popFront(); writeln(k.byKey.front); --- and get the same result. But my understanding is that you wouldn't, in which case byKey doesn't sense to me as a property. It creates and returns a new range object each time you call it, right?
Jan 19 2012
On 19.01.2012 19:17, Steven Schveighoffer wrote:That's like saying this: int[] arr; int l = arr.length; l++; should be the same as this: arr.length++; because it's a property. This is an orthogonal problem. byKey doesn't try to affect the original AA, so the semantics should be the same whether you save a copy or access it in one line. There are no hard-fast rules on what should be properties and what shouldn't. But the rvalue vs lvalue is an orthogonal problem.If the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.
Jan 19 2012
On Thu, 19 Jan 2012 14:06:00 -0500, torhu <no spam.invalid> wrote:On 19.01.2012 19:17, Steven Schveighoffer wrote:I don't know what you mean. You can treat it like one. -SteveThat's like saying this: int[] arr; int l = arr.length; l++; should be the same as this: arr.length++; because it's a property. This is an orthogonal problem. byKey doesn't try to affect the original AA, so the semantics should be the same whether you save a copy or access it in one line. There are no hard-fast rules on what should be properties and what shouldn't. But the rvalue vs lvalue is an orthogonal problem.If the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.
Jan 19 2012
On 1/19/12 4:43 PM, Steven Schveighoffer wrote:On Thu, 19 Jan 2012 14:06:00 -0500, torhu <no spam.invalid> wrote:It's the rvalue aspect. byKey does not hold a range inside the hashtable (as a member variable would do). Each use of byKey gives you a range that you get to iterate from the beginning. AndrieIf the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.I don't know what you mean. You can treat it like one. -Steve
Jan 19 2012
On Thursday, January 19, 2012 17:41:44 Andrei Alexandrescu wrote:On 1/19/12 4:43 PM, Steven Schveighoffer wrote:Well, that's part of the point of properties. They don't have to actually be associated with any particular member variable. They just _act_ like the type has that public member variable. - Jonathan M DavisOn Thu, 19 Jan 2012 14:06:00 -0500, torhu <no spam.invalid> wrote:It's the rvalue aspect. byKey does not hold a range inside the hashtable (as a member variable would do). Each use of byKey gives you a range that you get to iterate from the beginning.If the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.I don't know what you mean. You can treat it like one. -Steve
Jan 19 2012
On 1/19/12 5:57 PM, Jonathan M Davis wrote:On Thursday, January 19, 2012 17:41:44 Andrei Alexandrescu wrote:Yah, but .length acts to a better extent like an lvalue. AndreiOn 1/19/12 4:43 PM, Steven Schveighoffer wrote:Well, that's part of the point of properties. They don't have to actually be associated with any particular member variable. They just _act_ like the type has that public member variable.On Thu, 19 Jan 2012 14:06:00 -0500, torhu<no spam.invalid> wrote:It's the rvalue aspect. byKey does not hold a range inside the hashtable (as a member variable would do). Each use of byKey gives you a range that you get to iterate from the beginning.If the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.I don't know what you mean. You can treat it like one. -Steve
Jan 19 2012
On Thursday, January 19, 2012 18:07:50 Andrei Alexandrescu wrote:Yah, but .length acts to a better extent like an lvalue.True, but that's because it's both a getter and a setter. What's weirder IMHO is properties which are just setters, but they do make sense once in a while. - Jonathan M Davis
Jan 19 2012
On Thu, Jan 19, 2012 at 9:41 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/19/12 4:43 PM, Steven Schveighoffer wrote:I think MSDN has some decent advice on when to use properties vs methods: http://msdn.microsoft.com/en-us/library/bzwdh01d(v=vs.71).aspx#cpconpropertyusageguidelinesanchor1On Thu, 19 Jan 2012 14:06:00 -0500, torhu <no spam.invalid> wrote:It's the rvalue aspect. byKey does not hold a range inside the hashtable (as a member variable would do). Each use of byKey gives you a range that you get to iterate from the beginning. AndrieIf the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.I don't know what you mean. You can treat it like one. -Steve
Jan 19 2012
Jose Armando Garcia wrote:On Thu, Jan 19, 2012 at 9:41 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:us/library/bzwdh01d(v=vs.71).aspx#cpconpropertyusageguidelinesanchor1 Hi Jose, great that you're still around in the newsgroups. Any news on std.log? Is it ready for review?On 1/19/12 4:43 PM, Steven Schveighoffer wrote:I think MSDN has some decent advice on when to use properties vs methods: http://msdn.microsoft.com/en-On Thu, 19 Jan 2012 14:06:00 -0500, torhu <no spam.invalid> wrote:It's the rvalue aspect. byKey does not hold a range inside the hashtable (as a member variable would do). Each use of byKey gives you a range that you get to iterate from the beginning. AndrieIf the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.I don't know what you mean. You can treat it like one. -Steve
Jan 20 2012
On Fri, Jan 20, 2012 at 7:47 AM, Johannes Pfau <spam example.com> wrote:Jose Armando Garcia wrote:std.log still works! hehe. std.log is ready for review but unfortunately it depends on some changes I have made to druntime. I have tried to get those changes into druntime but they are just sitting in there as pull requests. I have recently decided to remove all my druntime changes and just put them in std/log.d instead. I'll have a revised std.log soon and maybe we can have a review soon. Thanks, -JoseOn Thu, Jan 19, 2012 at 9:41 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:us/library/bzwdh01d(v=vs.71).aspx#cpconpropertyusageguidelinesanchor1 Hi Jose, great that you're still around in the newsgroups. Any news on std.log? Is it ready for review?On 1/19/12 4:43 PM, Steven Schveighoffer wrote:I think MSDN has some decent advice on when to use properties vs methods: http://msdn.microsoft.com/en-On Thu, 19 Jan 2012 14:06:00 -0500, torhu <no spam.invalid> wrote:It's the rvalue aspect. byKey does not hold a range inside the hashtable (as a member variable would do). Each use of byKey gives you a range that you get to iterate from the beginning. AndrieIf the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.I don't know what you mean. You can treat it like one. -Steve
Feb 05 2012
On 2/5/12 11:25 AM, Jose Armando Garcia wrote:std.log still works! hehe. std.log is ready for review but unfortunately it depends on some changes I have made to druntime. I have tried to get those changes into druntime but they are just sitting in there as pull requests. I have recently decided to remove all my druntime changes and just put them in std/log.d instead. I'll have a revised std.log soon and maybe we can have a review soon.If the changes make more sense to put in druntime let's do so. Please let me know which they are and I'll take a look today. Andrei
Feb 05 2012
On Sun, Feb 5, 2012 at 3:26 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 2/5/12 11:25 AM, Jose Armando Garcia wrote:https://github.com/D-Programming-Language/druntime/pull/141/files Let me know if there is anything I need to fix and I'll make the changes in a short time. Thanks!std.log still works! hehe. std.log is ready for review but unfortunately it depends on some changes I have made to druntime. I have tried to get those changes into druntime but they are just sitting in there as pull requests. I have recently decided to remove all my druntime changes and just put them in std/log.d instead. I'll have a revised std.log soon and maybe we can have a review soon.If the changes make more sense to put in druntime let's do so. Please let me know which they are and I'll take a look today.Andrei
Feb 05 2012
On Thursday, January 19, 2012 22:30:46 Jose Armando Garcia wrote:I think MSDN has some decent advice on when to use properties vs methods: http://msdn.microsoft.com/en-us/library/bzwdh01d(v=vs.71).aspx#cpconpropert yusageguidelinesanchor1Those do seem like pretty good guidelines. - Jonathan M Davis
Jan 19 2012
On Thu, 19 Jan 2012 18:41:44 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/19/12 4:43 PM, Steven Schveighoffer wrote:The point of a property is to allow for read-only access on something that is logically a property but can only be implemented via a function. byKeys is such a property. There is no way to specify a field that behaves the same. This doesn't make properties invalid or useless. But Torhu, your use of terminology doesn't make sense. The type of byKeys is a Range, and you can use it as a Range. A range on a container is a shallow view, it fundamentally does not affect the container topology. -SteveOn Thu, 19 Jan 2012 14:06:00 -0500, torhu <no spam.invalid> wrote:It's the rvalue aspect. byKey does not hold a range inside the hashtable (as a member variable would do). Each use of byKey gives you a range that you get to iterate from the beginning.If the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.I don't know what you mean. You can treat it like one. -Steve
Jan 19 2012
On 20/01/12 12:57 AM, Steven Schveighoffer wrote:On Thu, 19 Jan 2012 18:41:44 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Can you define what "is logically a property means"? (I assume you meant "field" there) That means different things to different people. For example, in my mind, something that is logically a field would have an address. From what I can see, byKeys is logically a function (not a field) in every way (because it *is* a function).On 1/19/12 4:43 PM, Steven Schveighoffer wrote:The point of a property is to allow for read-only access on something that is logically a property but can only be implemented via a function. byKeys is such a property. There is no way to specify a field that behaves the same. This doesn't make properties invalid or useless.On Thu, 19 Jan 2012 14:06:00 -0500, torhu <no spam.invalid> wrote:It's the rvalue aspect. byKey does not hold a range inside the hashtable (as a member variable would do). Each use of byKey gives you a range that you get to iterate from the beginning.If the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.I don't know what you mean. You can treat it like one. -Steve
Jan 20 2012
On Friday, January 20, 2012 09:29:12 Peter Alexander wrote:Can you define what "is logically a property means"? (I assume you meant "field" there) That means different things to different people. For example, in my mind, something that is logically a field would have an address. From what I can see, byKeys is logically a function (not a field) in every way (because it *is* a function).Usually when discussing properties, taking the address doesn't come into the equation at all. Part of the reason for this is that many of the languages which have properties don't allow you to take the address of anything in the first place. Also, it completely invalidates property anyway, since by definition, using a property function instead of a member variable makes it so that you can't take its address (or that if you do, it means something completely different). So, taking the address of something really can't come into consideration when talking about properties unless the design requires that you be able to take its address, in which case it must be an actual member variable instead of a property function. So, when talking about something logically acting like a property or a field, it really can't have anything to do with addressing but rather the other aspects about how a field is used. - Jonathan M Davis
Jan 20 2012
On Fri, 20 Jan 2012 04:29:12 -0500, Peter Alexander <peter.alexander.au gmail.com> wrote:On 20/01/12 12:57 AM, Steven Schveighoffer wrote:No, I meant property. A property is a more general term. It's a piece of data that is associated with an entity. For example, if you have a ball, you might say that the ball is red, or it's bouncy. Those are properties. In this context (of programming language properties), a property can also be a piece of the entity. For example, the valve stem in the ball. properties do several things: 1. they allow you to avoid storing logically derived data. For example, if I have x and y, and I want to get z = sqrt(x*x + y*y), then I could either store z as a field, and update it every time x and y are changed, or I can just make a property, which logically acts like a read-only field. 2. they allow encapsulation. This means, I can give you information or mutable pieces of data from an object without actually exposing the data to you directly. 3. They allow you to control read/write access to a piece of data, including using contracts to check for errors. byKey is an example of the first -- it's not directly stored, but is generated on request. Since it's not actually stored in the object, the other 2 features don't apply. Which is why I was confused as to the nature of the argument above, it's a derived piece of data. The very nature of calculated properties are that you don't get direct access to the internal data because it doesn't exist! -SteveOn Thu, 19 Jan 2012 18:41:44 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Can you define what "is logically a property means"? (I assume you meant "field" there)On 1/19/12 4:43 PM, Steven Schveighoffer wrote:The point of a property is to allow for read-only access on something that is logically a property but can only be implemented via a function. byKeys is such a property. There is no way to specify a field that behaves the same. This doesn't make properties invalid or useless.On Thu, 19 Jan 2012 14:06:00 -0500, torhu <no spam.invalid> wrote:It's the rvalue aspect. byKey does not hold a range inside the hashtable (as a member variable would do). Each use of byKey gives you a range that you get to iterate from the beginning.If the type of byKeys is Range, I would expect to be able to treat it like one. Not like one, then another, then another, then another... ad infinitum.I don't know what you mean. You can treat it like one. -Steve
Jan 20 2012
Jonathan M Davis wrote:On Thursday, January 19, 2012 22:30:46 Jose Armando Garcia wrote:Then why not add these in a condensed form to http://www.dlang.org/dstyle.html? Convention may be a way to end these discussions. JensI think MSDN has some decent advice on when to use properties vs methods: http://msdn.microsoft.com/en-us/library/bzwdh01d(v=vs.71).aspx#cpconpropert yusageguidelinesanchor1Those do seem like pretty good guidelines.
Jan 20 2012
On Friday, January 20, 2012 11:01:10 Jens Mueller wrote:Jonathan M Davis wrote:Oh, it may be a good idea to add them (or something like them) to the style guide or elsewhere on the site, but it won't really end any discussions. Just like function names are subjective, whether something is a property or not is subjective. You can objectively narrow it down pretty thoroughly based on good naming rules (or good rules on what's a property), but in many cases, it still comes down to a subjective decision. So, there will always be debate. You can't get around that. At best, you can reduce it. - Jonathan M DavisOn Thursday, January 19, 2012 22:30:46 Jose Armando Garcia wrote:Then why not add these in a condensed form to http://www.dlang.org/dstyle.html? Convention may be a way to end these discussions.I think MSDN has some decent advice on when to use properties vs methods: http://msdn.microsoft.com/en-us/library/bzwdh01d(v=vs.71).aspx#cpcon propert yusageguidelinesanchor1Those do seem like pretty good guidelines.
Jan 20 2012
Jonathan M Davis wrote:On Friday, January 20, 2012 11:01:10 Jens Mueller wrote:I was only hoping for a reduction. If a convention works most of the time it's fine, I think. JensJonathan M Davis wrote:Oh, it may be a good idea to add them (or something like them) to the style guide or elsewhere on the site, but it won't really end any discussions. Just like function names are subjective, whether something is a property or not is subjective. You can objectively narrow it down pretty thoroughly based on good naming rules (or good rules on what's a property), but in many cases, it still comes down to a subjective decision. So, there will always be debate. You can't get around that. At best, you can reduce it.On Thursday, January 19, 2012 22:30:46 Jose Armando Garcia wrote:Then why not add these in a condensed form to http://www.dlang.org/dstyle.html? Convention may be a way to end these discussions.I think MSDN has some decent advice on when to use properties vs methods: http://msdn.microsoft.com/en-us/library/bzwdh01d(v=vs.71).aspx#cpcon propert yusageguidelinesanchor1Those do seem like pretty good guidelines.
Jan 20 2012
On 1/17/12 12:48 AM, Andrei Alexandrescu wrote:I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuI tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list. Thanks, Andrei
Jan 20 2012
On Fri, 20 Jan 2012 12:58:28 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/17/12 12:48 AM, Andrei Alexandrescu wrote:I voted property, though not as a direct reply before. -SteveI hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuI tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list.
Jan 20 2012
On Friday, January 20, 2012 11:58:28 Andrei Alexandrescu wrote:On 1/17/12 12:48 AM, Andrei Alexandrescu wrote:I'm divided. If it were keys and values, I'd be all for property, but byValue and byKey are weird property names. Of course, they're weird function names too. I assume that they essentially stand for iterateByValue and iterateByKey, which would be more of a function name, but they don't really iterate. Rather, they return something which you can iterate over. So, from a usage perspective, it definitely makes more sense as a property, but from a naming perspective, it's a bit off. I don't really have a better suggestion though, since values and keys are already taken. So, I'm fine with it either way. There's going to be something weird about it regardless. - Jonathan M DavisI hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuI tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list.
Jan 20 2012
On 01/20/2012 01:43 PM, Jonathan M Davis wrote:On Friday, January 20, 2012 11:58:28 Andrei Alexandrescu wrote:Agreed - if it were keys and values, property would be perfect. The names themselves are a bit weird, though. +1 PropertyOn 1/17/12 12:48 AM, Andrei Alexandrescu wrote:I'm divided. If it were keys and values, I'd be all for property, but byValue and byKey are weird property names. Of course, they're weird function names too. I assume that they essentially stand for iterateByValue and iterateByKey, which would be more of a function name, but they don't really iterate. Rather, they return something which you can iterate over. So, from a usage perspective, it definitely makes more sense as a property, but from a naming perspective, it's a bit off. I don't really have a better suggestion though, since values and keys are already taken. So, I'm fine with it either way. There's going to be something weird about it regardless. - Jonathan M DavisI hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuI tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list.
Jan 20 2012
On 01/20/2012 06:58 PM, Andrei Alexandrescu wrote:On 1/17/12 12:48 AM, Andrei Alexandrescu wrote:sclytrackI hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuI tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu,Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list. Thanks, AndreiCollection properties should satisfy the "torhu" criteria. Collection property. Usually indexed. Conditions: 1) The focus is on collection 2) torhu criteria I know strings can be seen as a collection of chars. Is string a collection or not, that's another vote. Memory aid: torhu criteria --- auto k = aa.byKey; writeln(k.front); k.popFront(); writeln(k.front); --- to this: --- writeln(aa.byKey.front); aa.byKey.popFront(); writeln(aa.byKey.front);
Jan 20 2012
Andrei Alexandrescu:I tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list.I vote for byKey and byValue to be properties. Bye, bearophile
Jan 20 2012
On 20/01/12 5:58 PM, Andrei Alexandrescu wrote:I tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list.I vote function.
Jan 20 2012
On 2012-01-20 17:58:28 +0000, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> said:I tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list.Votes ?!? I think byKey and byValue are oddly named, property or not. Since you asked, I think they should be properties. But I don't care really. What I care about is consistency. Voting on a case by case basis is just nonsensical. What's needed are guidelines and rationales covering how to name things and by extension what should and shouldn't be a property. If something needs to be put to vote, it should be those guidelines. I attempted a while ago to write some guidelines on the wiki, feel free to use them if they make sense to you. <http://prowiki.org/wiki4d/wiki.cgi?DProgrammingGuidelines> -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Jan 20 2012
On 1/20/12 7:31 PM, Michel Fortin wrote:On 2012-01-20 17:58:28 +0000, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> said:Give them better names and convince others. Please don't choose "keys" and "values".I tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list.Votes ?!? I think byKey and byValue are oddly named, property or not.Since you asked, I think they should be properties. But I don't care really. What I care about is consistency.Mindless consistency would probably be unnerving too.Voting on a case by case basis is just nonsensical. What's needed are guidelines and rationales covering how to name things and by extension what should and shouldn't be a property. If something needs to be put to vote, it should be those guidelines. I attempted a while ago to write some guidelines on the wiki, feel free to use them if they make sense to you. <http://prowiki.org/wiki4d/wiki.cgi?DProgrammingGuidelines>A good outcome of this vote might have been the distillation of some simple guidelines, as opposed to enforcing some arbitrary consistency. Apparently the participants in this thread are divided regarding general rules as well as their applicability to this particular case. Andrei
Jan 20 2012
On 2012-01-21 01:43:17 +0000, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> said:On 1/20/12 7:31 PM, Michel Fortin wrote:Well, if the best ones are already taken, I'd say "allKeys" and "allValues" would be the next best ones. And they are obviously properties.On 2012-01-20 17:58:28 +0000, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> said:Give them better names and convince others. Please don't choose "keys" and "values".I tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list.Votes ?!? I think byKey and byValue are oddly named, property or not.Guidelines are guides, not absolutes. If you have a good reason it is perfectly fine to not follow the guideline, and you can amend the document if it happens too often. But you need guidelines as a baseline, and a good reason when you derogate.Since you asked, I think they should be properties. But I don't care really. What I care about is consistency.Mindless consistency would probably be unnerving too.It'd be more useful if the discussion involved several examples of various types. You can't make a guideline from only one case, especially a litigious case. You must start by establishing a consensus by listing more clear-cut cases and then you can extend from that consensual position. -- Michel Fortin michel.fortin michelf.com http://michelf.com/Voting on a case by case basis is just nonsensical. What's needed are guidelines and rationales covering how to name things and by extension what should and shouldn't be a property. If something needs to be put to vote, it should be those guidelines. I attempted a while ago to write some guidelines on the wiki, feel free to use them if they make sense to you. <http://prowiki.org/wiki4d/wiki.cgi?DProgrammingGuidelines>A good outcome of this vote might have been the distillation of some simple guidelines, as opposed to enforcing some arbitrary consistency. Apparently the participants in this thread are divided regarding general rules as well as their applicability to this particular case.
Jan 20 2012
El 21/01/2012 3:05, Michel Fortin escribió:Agree with "allKeys" and "allValues" as the next best. IMO, the name of a property should be a a *noun phrase* (a noun possibly with modifiers, complements, adjectives...) because it represents a thing. And if the property represens a collection of things (an array, a list, a range,...) that noun should be *plural* (giving the idea that it can be enumerable). "allKeys" follows this guideline (plural noun with a complement). byKey is what, an adverb phrase, an adjective phrase? It can't name a range which is a thing.Well, if the best ones are already taken, I'd say "allKeys" and "allValues" would be the next best ones. And they are obviously properties.I think byKey and byValue are oddly named, property or not.Give them better names and convince others. Don't choose "keys" and "values".
Jan 22 2012
On Sunday, January 22, 2012 12:57:14 Alvaro wrote:byKey is what, an adverb phrase, an adjective phrase?Prepositional phrase actually. - Jonathan M Davis
Jan 22 2012
On 1/22/12 5:57 AM, Alvaro wrote:El 21/01/2012 3:05, Michel Fortin escribió: >>> I think byKey and byValue are oddly named, property or not. >> >> Give them better names and convince others. Don't choose "keys" >> and "values". > > Well, if the best ones are already taken, I'd say "allKeys" and > "allValues" would be the next best ones. And they are obviously > properties. > Agree with "allKeys" and "allValues" as the next best.byXyz is in TDPL.IMO, the name of a property should be a a *noun phrase* (a noun possibly with modifiers, complements, adjectives...) because it represents a thing. And if the property represens a collection of things (an array, a list, a range,...) that noun should be *plural* (giving the idea that it can be enumerable). "allKeys" follows this guideline (plural noun with a complement).torhu convinced me byXyz can't be properties. I'll operate the change soon.byKey is what, an adverb phrase, an adjective phrase? It can't name a range which is a thing.It has the implied verb "enumerate", "span". "Span hashtable by key". Andrei
Jan 22 2012
On Sun, 22 Jan 2012 10:27:42 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Actually, it's for each (x) in (y) by key: foreach(i; aa.byKey); The verb is not implied, nor should it be: for each (x) in (y) enumerate by key. This doesn't read well... But... for each (x) in (y) enumerated by key. Hm... still not an action. It's not a noun, but looks more like an adjective (not an english major). Even if you don't use it via foreach: auto x = aa enumerate by key. The call itself didn't *actually* enumerate the values, it just got you an enumerator. Still vote property, but I see it's unlikely to change your opinion. Oh well, back to the winnable battles :) -StevebyKey is what, an adverb phrase, an adjective phrase? It can't name a range which is a thing.It has the implied verb "enumerate", "span". "Span hashtable by key".
Jan 24 2012
On 1/24/12 2:53 PM, Steven Schveighoffer wrote:On Sun, 22 Jan 2012 10:27:42 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:I'm thinking independently of foreach, e.g. auto iter = aa.byKey/*()*/; This should clarify that iter spans aa by key. AndreiActually, it's for each (x) in (y) by key:byKey is what, an adverb phrase, an adjective phrase? It can't name a range which is a thing.It has the implied verb "enumerate", "span". "Span hashtable by key".
Jan 24 2012
On Tue, 24 Jan 2012 15:02:33 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/24/12 2:53 PM, Steven Schveighoffer wrote:I wrote about that. auto iter = aa enumerate (or span) by key. But it doesn't actually enumerate by calling that function. The enumeration is done by iter, which is an enumerator/spanner/iterator. FWIW, I think byKey or byValue is fine for a name. We're not writing COBOL here, it can be shorthand. I just think they are properties, and read in English as nouns/adjectives (not actions). -SteveOn Sun, 22 Jan 2012 10:27:42 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:I'm thinking independently of foreach, e.g. auto iter = aa.byKey/*()*/; This should clarify that iter spans aa by key.Actually, it's for each (x) in (y) by key:byKey is what, an adverb phrase, an adjective phrase? It can't name a range which is a thing.It has the implied verb "enumerate", "span". "Span hashtable by key".
Jan 24 2012
On Fri, 20 Jan 2012 20:43:17 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/20/12 7:31 PM, Michel Fortin wrote:On Sun, 22 Jan 2012 10:27:42 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:I think byKey and byValue are oddly named, property or not.Give them better names and convince others. Please don't choose "keys" and "values".On 1/22/12 5:57 AM, Alvaro wrote:So in other words, please come up with better names, you can't chose "keys" or "values" but you must choose byKeys or byValues, because it's already in TDPL. Got it! Looking in TDPL, it seems byKey and byValue are already functions. Why did we have this discussion again? Looks like you already chose the answer... -SteveAgree with "allKeys" and "allValues" as the next best.byXyz is in TDPL.
Jan 24 2012
On 1/24/12 2:59 PM, Steven Schveighoffer wrote:On Fri, 20 Jan 2012 20:43:17 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Changing parens would be (have been) a smaller change. AndreiOn 1/20/12 7:31 PM, Michel Fortin wrote:On Sun, 22 Jan 2012 10:27:42 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:I think byKey and byValue are oddly named, property or not.Give them better names and convince others. Please don't choose "keys" and "values".On 1/22/12 5:57 AM, Alvaro wrote:So in other words, please come up with better names, you can't chose "keys" or "values" but you must choose byKeys or byValues, because it's already in TDPL. Got it! Looking in TDPL, it seems byKey and byValue are already functions. Why did we have this discussion again? Looks like you already chose the answer... -SteveAgree with "allKeys" and "allValues" as the next best.byXyz is in TDPL.
Jan 24 2012
Andrei Alexandrescu wrote:On 1/20/12 7:31 PM, Michel Fortin wrote:keyRange and valueRange?On 2012-01-20 17:58:28 +0000, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> said:Give them better names and convince others. Please don't choose "keys" and "values".I tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list.Votes ?!? I think byKey and byValue are oddly named, property or not.Since you asked, I think they should be properties. But I don't care really. What I care about is consistency.Mindless consistency would probably be unnerving too.Voting on a case by case basis is just nonsensical. What's needed are guidelines and rationales covering how to name things and by extension what should and shouldn't be a property. If something needs to be put to vote, it should be those guidelines. I attempted a while ago to write some guidelines on the wiki, feel free to use them if they make sense to you. <http://prowiki.org/wiki4d/wiki.cgi?DProgrammingGuidelines>A good outcome of this vote might have been the distillation of some simple guidelines, as opposed to enforcing some arbitrary consistency. Apparently the participants in this thread are divided regarding general rules as well as their applicability to this particular case. Andrei
Jan 21 2012
On 21/01/12 1:43 AM, Andrei Alexandrescu wrote:Apparently the participants in this thread are divided regarding general rules as well as their applicability to this particular case.And this is exactly the problem. There are no general rules because everyone disagrees with what exactly a property is.
Jan 21 2012
On 21.01.2012 02:43, Andrei Alexandrescu wrote:A good outcome of this vote might have been the distillation of some simple guidelines, as opposed to enforcing some arbitrary consistency. Apparently the participants in this thread are divided regarding general rules as well as their applicability to this particular case.I think that the people here have two different views of what a property is: 1) Just way to hook up some code to what looks and (mostly) behaves like field access. 2) A property of some object, in a wider sense. Examples of 1) are: Creating a read-only field, or delaying calculating a value until first use and then caching it for future use. An example of 2) would be saying that the set of keys of an AA is a property of that AA. As I see it, the main difference between 1) and 2) is that with the latter you are giving field access (dot) syntax a new logical meaning that it didn't use to have. Which why I'm weary of things like aa.byKey. What is the gain, not having to type parentheses? That's not a lot.
Jan 21 2012
On 20/01/2012 17:58, Andrei Alexandrescu wrote:On 1/17/12 12:48 AM, Andrei Alexandrescu wrote:I vote property. While the names do not fall in line with the properties-are-nouns pattern, I do see the compound aa.byKey as a noun (especially when aa is something more meaningful, and preferably plural). So I think the names should stay as they are. A...I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... } Thanks, Andrei "I told you" AlexandrescuI tallied the votes. Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary Manzana, torhu. Property: Nick Sabalausky, Simen Kjaeraas. I wasn't able to discern a clear vote from the others. Please correct the list. Thanks, Andrei
Jan 21 2012
El 20/01/2012 18:58, Andrei Alexandrescu escribió:On 1/17/12 12:48 AM, Andrei Alexandrescu wrote:I vote properties. The general rule to me the is a function represents an *action* and usually has a verb in its name while a property is logically something of an object and its name is basically a noun, but nothing is said about whether that thing is stored (a field). A function *does* something, a property *is* something. I'm using "is" in a special way maybe because property values might not actually exist and be created/computed on the fly. "circle.area" is the area of a circle. Whether its value is stored or computed on the fly does not change that. aa.byKey is a range of keys, so, property. Even "a.dup" *is* "a duplicate of a" so it's OK as a property even if it is not a "part" of a. Emphasis on the action of creating that duplicate is removed. BTW, someone said that properties bring something more to remember (is it a.b or a.b()?) but I think they actually reduce doubts: How would I change the radius of a circle in another language? circle.setRadius(2), circle.SetRadius(2), circle.set_radius(2), circle.radius_set(2)? With properties "circle.radius=2;" easier to remember. My two cents.I hate I must ask this: int[string] aa; foreach (k; aa.byKey) { ... } or int[string] aa; foreach (k; aa.byKey()) { ... }
Jan 21 2012
Perhaps I'm out of line, and I haven't looked much at the class/struct specifically in question (Actually I have no clue which one your talking about), but I would wonder one thing. Would it be read/write or just read-only? If it's read-only, I would think there would be no harm in having it as a property. A second thought, is would there be any benefit having it as a method, specifically passing the address as a function rather than just getting the return value (From what I can tell that's unlikely). I'll vote property.phrase? It can't name abyKey is what, an adverb phrase, an adjectivehashtable by key". Actually, it's for each (x) in (y) by key: foreach(i; aa.byKey); The verb is not implied, nor should it be:range which is a thing.It has the implied verb "enumerate", "span". "Span
Jan 24 2012
On Tue, 24 Jan 2012 16:43:33 -0500, Era Scarecrow <rtcvb32 yahoo.com> wrote:The builtin associative arrays of D. i.e.: int[string] aa;Perhaps I'm out of line, and I haven't looked much at the class/struct specifically in question (Actually I have no clue which one your talking about),phrase? It can't name abyKey is what, an adverb phrase, an adjectivehashtable by key". Actually, it's for each (x) in (y) by key: foreach(i; aa.byKey); The verb is not implied, nor should it be:range which is a thing.It has the implied verb "enumerate", "span". "Spanbut I would wonder one thing. Would it be read/write or just read-only? If it's read-only, I would think there would be no harm in having it as a property.If key, it must be read only, since keys must be immutable. If value, it could potentially be read/write.A second thought, is would there be any benefit having it as a method, specifically passing the address as a function rather than just getting the return value (From what I can tell that's unlikely).properties are methods. There should be a way to pass a delegate to a property function, not allowing this would be unnecessarily limiting. Some sort of __traits directive comes to mind... -Steve
Jan 24 2012
The builtin associative arrays of D.=A0 i.e.: =20 int[string] aa;I could tell it was a container. Guess this shows how far I'm not looking = (or behind) with the details of implementation.If key, it must be read only, since keys must be immutable. =20 If value, it could potentially be read/write.That's what I thought... I'd think keys could be mutable; However the hash= would have to be recalculated afterwards. That would be for very rare proj= ects (effectively removing it, adding it back in), but I don't really see i= t happening. Manually doing it is likely safer and easier to follow.properties are methods.=A0 There should be a way to pass a delegate to a=A0=20 property function, not allowing this would be unnecessarily limiting.=A0=A0=A0 Some sort of __traits directive comes to mind...Yes I know that part. Just go with what makes the most sense. In my mind s= omething should be a property if it doesn't do anything really, and has spe= cific limitations on what it decides to do; Example: A Getter: Like (.length), you get the length/size and that's it. No side e= ffects, no generating new objects (not counting dup) A Setter (or lack of): Returning void (or the object/structure called), Ma= y change the structure, but only doing exactly what you expect it to do. I guess more importantly I'd need an example of how passing a method like = that to a delegate could be useful. I'd need a reasonable example, not just= syntax. The only time that might be useful, like if somewhere in the calli= ng it might change size; But for arrays that can reallocate then you may en= d up with the old array and not the newer one defeating the purpose. I'll leave whatever decisions to you guys. And I'm glad to see how fast bu= gfixes have been progressing recently.
Jan 24 2012