Why is this not allowed?

Nick Treleaven nick at geany.org
Wed Oct 9 11:12:28 UTC 2024


On Wednesday, 9 October 2024 at 01:16:29 UTC, Boaz Ampleman wrote:
> I'm not a big fan of using declarations as type either:
>
> ```d
> bool doWeWantThat( struct{ int notsure;} p)
> {
>     return false;
> }
> ```

Here `(int notsure) p` would read much better. And we want tuple 
syntax in the language anyway so we can do destructuring.

> in the same way, named fields in tuples is an aberration to me, 
> because "why not use a struct instead ?"

When it's a singleton type used in a place you can't declare a 
struct. Naming tuple fields makes for clearer code rather than 
having to remember an index in code reviews to decipher what's 
happening.


More information about the Digitalmars-d-learn mailing list