DEV Community

Discussion on: The 14 habits of highly effective developers (Part 1)

Collapse
 
patricktingen profile image
Patrick Tingen

With regard to point 2 (Give meaningful names) I found that the smaller your methods get, the less important it is to have real meaningful names. They can even distract from what the code is doing. If you have a piece of code of - say - 10 lines, then having a one-letter variable is not so bad, whereas that is a real problem if you are digesting a multi-hundred lines piece of code.

An example in the Progress 4GL (where I use to work in) to get the number of orders of a customer. Compare the below two functions:

FUNCTION getNumOrders RETURNS INTEGER (piCustNum AS INTEGER):
  DEFINE VARIABLE iNumOrders AS INTEGER.

  FOR EACH order WHERE order.custnum = piCustNum:
    iNumOrders = iNumOrders + 1.
  END.

  RETURN iNumOrders.
END FUNCTION.
FUNCTION getNumOrders RETURNS INTEGER (piCustNum AS INTEGER):
  DEFINE VARIABLE i AS INTEGER.

  FOR EACH order WHERE order.custnum = piCustNum:
    i = i + 1.
  END.

  RETURN i.
END FUNCTION.

To me, the latter is more clear than the first one, despite the less meaningful name.