3 ms·
I felt the same way about short variables names until I started using Haskel (which tends to have extremely local scopes). The idea is that if a variable is onl
by gizmo686 14y ago
I felt the same way about short variables names until I started using Haskel (which tends to have extremely local scopes). The idea is that if a variable is only used in 2 lines, it is not much mental effort to keep in your head what the variable is doing, but it is a relatively large amount to read the long name. However, most languages make it almost impossible to use variables with small scopes (in terms of spacing), so we only see good use of short variables in idiomatic places, such as for(i=0; i<10; i++).
For example, consider the parents original code:
def between( a, low, high ):
r = []
for x in a:
if low < x < high:
r.append( x )
return r
Even as someone who 'likes' small variable names, the r make that difficult because of the all distance between its definition and use.
Compare that to this haskel implentation
between a low high = filter f a
where
f x = x>low && x < high
(Actually, I would probably use 'as' instead of 'a')