digitalmars.D - IDEA: Use Unix-style chmod values for const and invariant
- Russell Lewis (12/12) Nov 29 2007 Ok, I was pondering, trying to figure out some sort of syntax which
- Kenny TM~ (4/20) Nov 29 2007 But it's hard to read IMHO.
- Chad J (20/36) Nov 29 2007 I think I like where this is going. Of course, I like any attempt to
- Jesse Phillips (9/25) Nov 29 2007 Looking at this, I like the way it can be used to explain what they are,...
- Janice Caron (3/10) Nov 29 2007 Has anyone thought of using "in" for readonly view? Keywords don't
- Bill Baxter (5/18) Nov 29 2007 Or how about 'is'? Or 'do'? Those are pretty short too!
- Regan Heath (6/19) Nov 30 2007 We already use it for function parameters...
- Janice Caron (13/18) Nov 30 2007 And yet, this compiles and runs in D2.0
- Regan Heath (13/36) Nov 30 2007 So, the questions become:
- Janice Caron (2/3) Nov 30 2007 Specifically, D2.008
Ok, I was pondering, trying to figure out some sort of syntax which would allow us to communicate "const" and "invariant" in a way that's easy to learn & remember. Maybe we could learn from UNIX file permissions, where you can see both the owner's permissions to the file, and "other's" permissions. In that case, we have these comparisons: const: rw-r--r-- invariant: r--r--r-- Which leads me to this concept for alternative keywords: const: const_wr invariant: const_rr Sure, the first time that a C++ programmer sees this, he won't know exactly what it means, but it is (IMHO) easy to learn & remember.
Nov 29 2007
Russell Lewis wrote:Ok, I was pondering, trying to figure out some sort of syntax which would allow us to communicate "const" and "invariant" in a way that's easy to learn & remember. Maybe we could learn from UNIX file permissions, where you can see both the owner's permissions to the file, and "other's" permissions. In that case, we have these comparisons: const: rw-r--r-- invariant: r--r--r-- Which leads me to this concept for alternative keywords: const: const_wr invariant: const_rr Sure, the first time that a C++ programmer sees this, he won't know exactly what it means, but it is (IMHO) easy to learn & remember.But it's hard to read IMHO. -- -- Kenny.
Nov 29 2007
Russell Lewis wrote:Ok, I was pondering, trying to figure out some sort of syntax which would allow us to communicate "const" and "invariant" in a way that's easy to learn & remember. Maybe we could learn from UNIX file permissions, where you can see both the owner's permissions to the file, and "other's" permissions. In that case, we have these comparisons: const: rw-r--r-- invariant: r--r--r-- Which leads me to this concept for alternative keywords: const: const_wr invariant: const_rr Sure, the first time that a C++ programmer sees this, he won't know exactly what it means, but it is (IMHO) easy to learn & remember.I think I like where this is going. Of course, I like any attempt to generalize const into something more useful and maybe not so horribly named. I am having a bit of a problem making sure I understand the analogy though. So who is the "owner"? I'm guessing it's the variable being declared. Then who is "user" and "group"? I'm guessing those are subsumed into one entity who is other variables that reference this data. I suppose 'w' means read-write, not write only. Also, 'r' means read-only. The one on the left is the owner/decl, the one on the right is the user/group/others. Now just drop the horribly misleading term "const". Also, the underscore doesn't jive with me. const -> accesswr invariant -> accessrr Perhaps better can be done than "access". Maybe we can resurrect the notion of head and tail constness. const -> tailwr invariant -> tailrr More rambling (by me) is possible as well. ;)
Nov 29 2007
On Thu, 29 Nov 2007 10:32:56 -0700, Russell Lewis wrote:Ok, I was pondering, trying to figure out some sort of syntax which would allow us to communicate "const" and "invariant" in a way that's easy to learn & remember. Maybe we could learn from UNIX file permissions, where you can see both the owner's permissions to the file, and "other's" permissions. In that case, we have these comparisons: const: rw-r--r-- invariant: r--r--r-- Which leads me to this concept for alternative keywords: const: const_wr invariant: const_rr Sure, the first time that a C++ programmer sees this, he won't know exactly what it means, but it is (IMHO) easy to learn & remember.Looking at this, I like the way it can be used to explain what they are, but I don't like the suggestion for new syntax. In my opinion invariant is a great keyword for what it does, don't ever change. But const like others is very much not descriptive of its use. I would think the two keywords should be, invariant I'm not saying a name change is needed but maybe it should be looked into?
Nov 29 2007
On Nov 29, 2007 10:51 PM, Jesse Phillips <jessekphillips gmail.com> wrote:In my opinion invariant is a great keyword for what it does, don't ever change. But const like others is very much not descriptive of its use. I would think the two keywords should be, invariant I'm not saying a name change is needed but maybe it should be looked into?Has anyone thought of using "in" for readonly view? Keywords don't come much shorter. Its existing use is about as useful as unary plus.
Nov 29 2007
Janice Caron wrote:On Nov 29, 2007 10:51 PM, Jesse Phillips <jessekphillips gmail.com> wrote:Or how about 'is'? Or 'do'? Those are pretty short too! I think it hasn't been suggested because it doesn't jump out at anyone as meaning 'const' anywhere besides on a function parameter. --bbIn my opinion invariant is a great keyword for what it does, don't ever change. But const like others is very much not descriptive of its use. I would think the two keywords should be, invariant I'm not saying a name change is needed but maybe it should be looked into?Has anyone thought of using "in" for readonly view? Keywords don't come much shorter. Its existing use is about as useful as unary plus.
Nov 29 2007
Janice Caron wrote:On Nov 29, 2007 10:51 PM, Jesse Phillips <jessekphillips gmail.com> wrote:We already use it for function parameters... http://www.digitalmars.com/d/function.html "The in storage class is equivalent to final const scope" :) RIn my opinion invariant is a great keyword for what it does, don't ever change. But const like others is very much not descriptive of its use. I would think the two keywords should be, invariant I'm not saying a name change is needed but maybe it should be looked into?Has anyone thought of using "in" for readonly view? Keywords don't come much shorter. Its existing use is about as useful as unary plus.
Nov 30 2007
On Nov 30, 2007 9:16 AM, Regan Heath <regan netmail.co.nz> wrote:And yet, this compiles and runs in D2.0 int f(in int x) { ++x; return x; } void main() { int n = 42; int m = f(n); } It doesn't seem to mean const to me. (Anyway, "final" has been ditched).Has anyone thought of using "in" for readonly view? Keywords don't come much shorter. Its existing use is about as useful as unary plus.We already use it for function parameters... http://www.digitalmars.com/d/function.html "The in storage class is equivalent to final const scope"
Nov 30 2007
Janice Caron wrote:On Nov 30, 2007 9:16 AM, Regan Heath <regan netmail.co.nz> wrote:So, the questions become: 1. does "in" still mean "const scope" (final being ditched) suspect. Or get an answer from Walter answer. Or, code two functions one using "in" and the other "const scope" and see if the behaviour is identical. happens when you try the above with a class reference instead of an int? I haven't taken the time to really get inside the new system yet, which is why I'm asking the questions instead of answering them. ReganAnd yet, this compiles and runs in D2.0 int f(in int x) { ++x; return x; } void main() { int n = 42; int m = f(n); } It doesn't seem to mean const to me. (Anyway, "final" has been ditched).Has anyone thought of using "in" for readonly view? Keywords don't come much shorter. Its existing use is about as useful as unary plus.We already use it for function parameters... http://www.digitalmars.com/d/function.html "The in storage class is equivalent to final const scope"
Nov 30 2007
On Nov 30, 2007 9:56 AM, Janice Caron <caron800 googlemail.com> wrote:And yet, this compiles and runs in D2.0Specifically, D2.008
Nov 30 2007