Jeremiah Flaga My thoughts and experiences on programming, life, atbp.

What is the most basic rule when writing code?

Do you like simple rules?

Simple rules

I like simple, but/and/yet all-encompassing rules (partly because I’m not very good at remembering lots of things :smile: ):

You can start anywhere.

“If it sounds good, it is good.” — Duke Ellington

“Everything should be as simple as possible, but not simpler.” — Albert Einstein

If it is hard, it must be wrong.

“The only way to go fast is to go well” — Uncle Bob Martin

“First make it work. Then make it right. Then make it fast” — Kent Beck

Another simple rule

I found another simple rule!

In the introduction videos of the Nand2Tetris course, Noam Nisan and Shimon Schocken calls it “The Main Secret of Computer Science”:

The Main Secret of Computer Science

Don’t worry about the “how”, only about the “what”.

In other words, don’t worry about the “implementation”, only about the “abstraction”.

Steve Freeman and Nat Pryce, the authors of the GOOS book, also said something about it (p. 252):

All code should emphasize “what” it does over “how”, including test code.

Jonathan Boccara declared it as “the principle that rules them all”: respecting levels of abstraction.

… abstraction is characterized by what a particular piece of code intends to do as opposed to how it is implemented

“what” over “how”

Simple, yet all-encompassing rule!

Focus on the “what”, not the “how”

Of course we might still be the one to write the “how” part. But if we focus on the “what” part when writing code, we will end up with code that is, what they call, “intention revealing” code.

“what does this code do?…”

“ahhh!”

And “intention revealing” code is easy to read! Remember that we, and our coleagues (we should think about our coleagues also :smile:) spend more time reading than writing code!

It’s also easy to write, I think.

I should put this in mind always then…

“what” over “how”

“what” over “how”

“what” over “how”

“what” over “how”

:smile:

“what does this button do?”

Comments