March 29, 2015
On Sunday, 29 March 2015 at 19:13:32 UTC, bitwise wrote:
> Interesting, but I still don't understand why D doesn't have something like this:
>
> const Test test;    // or const(Test) test;
> test = new Test()  // fine, underlaying data is const, the reference is not
>
> Test const test = new Test();
> test.a = 5;              // fine, test is read-only but underlaying data is not const
> test = new Test();  // error: test is read-only
>
> const(Test) const test = new Test();
> test.a = 5;              // error, underlaying data is const
> test = new Test();  // error: read-only

I think the semantics you propose here are not good. The first example would change the meaning of existing syntax (bad). The second one shows a const reference to mutable data (head const), which is a no-go for D so far.

Shuffling things around, this could be less disruptive addition to the language:

Test const test; /* mutable reference to const data */

But:

1) Such placement based syntax is foreign to D.

2) It would be special syntax just for class types.

3) It's not how C++ rolls.
`const Test test;` and `Test const test;` are equivalent in C++. You need that '*' in C++, too, to make a distinction between reference and data.

4) Rebindable works reasonably well, as far as I know. So there is not that much pressure to change the language.
March 29, 2015
> 1) Such placement based syntax is foreign to D.

I would have to agree that this is a strange way to do things in any language.
The great "int* a" vs "int *a" debate...

> 2) It would be special syntax just for class types.
IMO, it would be worth it

> 3) It's not how C++ rolls.
> `const Test test;` and `Test const test;` are equivalent in C++. You need that '*' in C++, too, to make a distinction between reference and data.

I'm a little confused. I was comparing a C++ pointer-to-class to a D reference, which are basically the same under the hood. I wasn't trying to bring up C++ value types. I'm not sure how they're relevant to the argument.

> 4) Rebindable works reasonably well, as far as I know.

The verbosity and blatant disregard for DRY makes me CRY.
See what I did there.. ;)

Anyways, IMO, D could benefit from having "tailconst" but I think it's a moot point.
March 29, 2015
On Sunday, 29 March 2015 at 20:29:50 UTC, bitwise wrote:
>> 3) It's not how C++ rolls.
>> `const Test test;` and `Test const test;` are equivalent in C++. You need that '*' in C++, too, to make a distinction between reference and data.
>
> I'm a little confused. I was comparing a C++ pointer-to-class to a D reference, which are basically the same under the hood. I wasn't trying to bring up C++ value types. I'm not sure how they're relevant to the argument.

`Test` can be a pointer type:

class C {};
typedef C *Test;
const Test test1 = 0;
Test const test2 = 0; /* same type as test1 */

The point is that C++ shares the problem: If all you have is one identifier (and no pointer star), you can't distinguish the data from the pointer.

So C++ syntax could only be properly adopted into D, if D class references got something like the pointer star. At that point, current D syntax with parentheses would work, too.

>> 4) Rebindable works reasonably well, as far as I know.
>
> The verbosity and blatant disregard for DRY makes me CRY.
> See what I did there.. ;)
>
> Anyways, IMO, D could benefit from having "tailconst" but I think it's a moot point.

Yeah, I don't like Rebindable very much either. But it works ok, so whatever. If you have strong arguments, maybe post to the general forum. For me it's just about aesthetics.
March 30, 2015
On Sun, 29 Mar 2015 20:29:49 +0000, bitwise wrote:

> The verbosity and blatant disregard for DRY makes me CRY. See what I did there.. ;)

you can always `alias` it to something funny or obscene.

1 2
Next ›   Last »