Francesco Bochicchio wrote:
> Heinrich Apfelmus wrote:The goal is of course to make code readable, that's why I recommend
>>
>> Stylistically, one usually uses shorter variable names in Haskell.
>
> <beginner rant>
...
> </beginner rant>
>
> Rant apart, I notice that in my own excercises I tend to shorten names, so
> maybe there is a reason for that.
> Nevertheless readability tends to be a big issue in languages used in IT
> industry, and my feeling is that haskell
> tends to err on the laconic side of the balance.
short names. :D
Abstraction is the one driving force for very short names. For example,
take the definition of foldr
foldr f z [] = z
foldr f z (x:xs) = f x (foldr f z xs)
Since this function is polymorphic, so f , z and the xs can be
anything, using more "descriptive" variable names is simply not
possible; the key point of fold is its generality.
A second, and my main reason for short names, or rather against long
names, is that names should be to the point. None of the names
newPrimes
topPrime
doFactors
doFilter
accurately describe the object they represent. The primes are not "new",
the prime is not "on top". The "do" is a prefix does not carry a meaning
either, it just conveys that doFactors has something to do with
factors . This is best expressed by making doFactors a local
definition in the where-block of factors .
The name eratosthenesFilter is ok, but since there is no other
eratosthenes around, no meaning is lost by shortening it to simply
eratosthenes . Not to mention that the conventional term is "sieve", not
"filter". The documentation has to elaborate on it anyway.
The generality of the name num hints that a single letter name is
preferable.
The names that I think are great because they are to the point are
factors
primes
Convention. Often, an auxiliary function that does basically the same
> Out of curiosity, there is any reason why you called the auxiliary function
> 'go' ?
thing as the main function factors but with an extra parameter will be
named factors' . The apostrophe has the drawback that it's easy to
forget, so some people now name such auxiliary functions go instead.
Regards,
apfelmus