Ever since the get
and set
keywords came to Javascript / Typescript, I've felt uneasy about them. Something about their nature of hiding computation in what appears to be data never really sat well with me. In some projects, I knee-jerk banned them with lint rules but unfortunately I never really thought deeply about why.
Let's start with some assertions:
- When you're reading through a piece of code, you are mentally executing the program. Symbolically at first and with specific inputs while debugging.
- When you're reading through a piece of code that is new to you, in order to read and mentally execute a piece of code without reading the entire codebase, you need to be able rely on interfaces & type definitions.
- When working in a team, it is natural that you will frequently arrive at parts of the codebase that you have not worked on before or have been modified since you last read the code. As the codebase and team