Tell don’t ask

David Lam
David Lam
Nov 3 · 1 min read

I have been programming for about 5 years at this point of time. Over the years, I have read countless articles and dear reader, you probably have too.

One of my favorite programming principle that I came across 2 years ago is ‘Tell don’t ask’.

In layman’s term:

Rather than asking objects about their internal state and doing things on their behalf, simply send them messages and let them decide what to do.

Related concept:

Colocate data and methods that operate on that data.

Source:
https://www.youtube.com/watch?v=ZJ6bH6Df4K8

I love it because it’s so simple to remember, but there are some caveat about it. As highlighted in the video above.

At the end of the day, like all issues with programming, there is no hard and fast rules and it all boils down to what level of abstraction your system is at.

Further reading:
https://martinfowler.com/bliki/TellDontAsk.html

    David Lam

    Written by

    David Lam