# Idea: Properties

**URL:** <https://internals.rust-lang.org/t/idea-properties/11152>\
**Category:** language design\
**Created:** [October 19, 2019, 11:36pm UTC](https://internals.rust-lang.org/t/idea-properties/11152 "2019-10-19T23:36:39Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Aloso](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/aloso/32/5039_2.png) [@Aloso](https://internals.rust-lang.org/u/Aloso)\
**Post date:** [October 20, 2019, 7:41pm UTC](https://internals.rust-lang.org/t/idea-properties/11152/12 "2019-10-20T19:41:22Z")

</div>

Here are a few motivations:

- Properties are more concise and easier to read than method calls. Consider these examples:

- Properties are used for _state_, whereas methods are used for _behavior_. Without properties, it's not always clear which is which. If you have a method `bar()`, how do you know if it does an expensive computation, or just returns a field?

- Following good practices, getters and setters

One important concern is that properties hide where computations are happening. However, IDEs like IntelliJ disambiguate properties from fields by using different syntax highlighting colors. This would also be possible in IntelliJ-Rust/RLS/rust-analyzer.

The purpose of properties is to expose state with a nice API, so it usually doesn't matter what the property does under the hood.

I found properties in Kotlin very useful. Kotlin even goes one step further and automatically converts getters and setters from Java APIs into properties. For example, this Java code: `editText.setHint("...")` is written like this in Kotlin: `editText.hint = "..."`

> [@josh](#):
>
> we tend to discourage anything that might use the words "clever" and " `Deref` " in the same sentence.

I think the same applies to properties. Properties can log a message when they are modified, or calculate a value lazily (e.g. the circumference of a circle from its radius, or a person's full name from their first and last name). Doing something more sophisticated is discouraged.

---

_[View the full topic](https://internals.rust-lang.org/t/idea-properties/11152)._
