Variable naming

Variable naming

Name your variable to improve readability such that it would be hard for you to use it incorrectly.

Below is a subtle bug where I wanted to archive old records:

records = model.objects.filter(status='archived', added__gt=older)

It reads:

get records with status 'archived' which is bigger than the 'older' date

It sounds good however 'bigger than' in terms of date is the opposite of what's needed, getting things after older, which would be newer records.

If the variable name is changed to cut_off which declares a particular date without implying any tense (future/past) leaving it to the author's discretion

records = model.objects.filter(status='archived', added__lt=older)

It would read:

get records with status 'archived' which is less than the `cut_off` date

which would be as was intended.