Skip to content

Add true properties #13299

Closed
Closed
@a1russell

Description

@a1russell

I believe that Rust would benefit greatly by adding true properties. An old rust-dev thread on getters and setters defended the lack of such by saying that Haskell and ML are fine without them. I think that this defense might be misleading, and I still believe that it would be worth it for Rust to have properties.

Haskell does not have properties because it is a functional language, but it does require the use of functions to access the individual fields of a type. It has the record syntax to generate these accessors for you in order to cut down on boilerplate. As far as I know, Rust lacks the equivalent of even this. Haskell also has lenses to make this even easier.

It is important that Rust distinguish itself from the tried-and-true C and C++ languages by eliminating boilerplate/generated code. My worry is that developers simply won't see much advantage in learning a new language otherwise. I believe that if an equivalent of Scala's unapply method is necessary to keep pattern matching working correctly, it would be worth it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions