←back to thread

1455 points nromiun | 1 comments | | HN request time: 0.258s | source
Show context
lxe ◴[] No.45075154[source]
Introducing intermediate variables is what I call "indirection". You're adding another step to someone reading the code.

Let's take a recipe:

   Ingredients:
   large bowl
   2 eggs
   200 grams sugar
   500 grams flour
   1/2 tsp soda

   Steps:

   Crack the eggs into a bowl. Add sugar and whisk. Sift the flower. Add the soda.
When following the instruction, you have to always refer back to the ingredients list and search for the quantity, which massively burdens you with "cognitive load". However, if you inline things:

   Crack 2 eggs into a large bowl. Add 200g sugar and whisk. Sift 500g of flower. Add 1/2 tsp soda.
Much easier to follow!
replies(4): >>45075166 #>>45075910 #>>45075921 #>>45076490 #
1. mdaniel ◴[] No.45075910[source]
This probably isn't entirely what you meant, but people who do this code smell drive me starkraving mad

  shipToAddress(getShippingAddress(getStreet()),calculateShipping(getShippingAddress(getStreet())))
because as soon as one needs to update the mechanism for getting the shipping address, congratulations, you're updating it everywhere -- or not, nothing matters in this timeline