Worst ideas/features in programming languages?
bauss
jj_1337 at live.dk
Thu Oct 14 10:56:00 UTC 2021
On Thursday, 14 October 2021 at 10:55:14 UTC, bauss wrote:
> On Wednesday, 13 October 2021 at 19:55:29 UTC, Jacob Carlborg
> wrote:
>>
>> (int, int) point = (x: 2, y: 4);
>> auto x = point.x + a;
>> ```
>>
>
> This would be better if the identifier was tied to the type.
>
> Like below:
>
> ```d
> (int x, int y) point = (2, 4);
> auto x = point.x + a;
> ```
>
> Because with your example the following fails:
>
> ```d
> (int, int) getPoint1() { return (x: 2, y: 4); }
> (int, int) getPoint2(bool shouldGetPoint1) {
> if (shouldGetPoint1) return getPoint1();
>
> return (left: 2, top: 4); // Possible error since the named
> values will be different??
> }
> auto point1 = getPoint1();
> auto point2 = getPoint2(true);
> auto point3 = getPoint2(false);
>
> writeln("%d %d", point1.x, point1.y);
> writeln("%d %d", point2.left, point2.top); // Error
> writeln("%d %d", point3.left, point3.top);
> ```
>
> However it wouldn't fail if it worked like below:
>
> ```d
> (int x, int y) getPoint1() { return (2, 4); }
> (int left, int top) getPoint2(bool shouldGetPoint1) {
> if (shouldGetPoint1) return getPoint1();
>
> return (2, 4); // Ok
> }
> auto point1 = getPoint1();
> auto point2 = getPoint2(true);
> auto point3 = getPoint2(false);
>
> writeln("%d %d", point1.x, point1.y);
> writeln("%d %d", point2.left, point2.top); // Ok
> writeln("%d %d", point3.left, point3.top);
> ```
Ofc. these are supposed to be writefln and not writeln.
More information about the Digitalmars-d
mailing list