RetroFed Forums
Your home away from modern life.
"foo bar baz" is crap - use representative names ffs
Post Reply
AuthorMessage
onlinepersona programming.dev onlinepersona@programming.dev
Joined: 2023-09-01
Quote

Code examples that use this convention are in my opinion terrible for comprehension - especially for domain specific examples.

Say you have a library called libprefix and you want to demonstrate how to use it

foobar example

import prefixer

foo = "foo"
bar = prefixer.prefix(foo, "bar")
print(bar) # foobar

vs representative

import prefixer 

to_prefix = "to prefix"
prefixed = prefixer.prefix(to_prefix, "not ")
print(prefixed) # not to prefix

The variables tell you what they represent

  • to_prefix a string that has to be prefixed
  • prefixed contains a string that has been prefixed

This is just a small example, but some example have 10, 20, 50 lines of code and when I start reading and it uses this foobarbaz crap, it makes me want to close the tab and move on. Naming things is hard, but come on...
Sometimes there are even domain specific examples where the effort is made to convert it to foobar convention just for the sake of it.

import traffic_light

foo = traffic_light.intersection("cross", 2) # 2 roads intersect
bar = { "north": 4, "east": 1, "south": 10, "west": 0} # vehicles at each light
baz = foo.simulate(bar) # creates a simulation object

print(baz) # print out the state of the intersection (bar in this cas)
quux = baz.step() # state of intersection after one step
print(quux)

We have all seen worse than this. Seriously, why?

12   Original
Post Reply
Back to top