[Haskell-cafe] How to decide if a number is an integer?
lrpalmer at gmail.com
Tue Sep 29 06:06:12 EDT 2009
On Tue, Sep 29, 2009 at 2:30 AM, Magicloud Magiclouds
<magicloud.magiclouds at gmail.com> wrote:
> Resolved. As Thomas said, mixing up sure is a bad thing. But then I
> have to name so many meanless (at least I think) computing process....
That is the primary challenge of writing readable code: identifying
the meaningful parts. You can separate out a function into its parts
in many, many ways, but only a few of them will have parts that are
comprehensible in isolation.
Your original question asked "how to decide if a number is an
integer". Surely you would have loved it if isInteger were a library
function. It has a nice, simple meaning, that is completely
independent of what the surrounding code is doing. It is pretty easy
These things often line up. They indicate that the function is most
easily understood outside of its context, as an atomic building block.
It is an ideal candidate for a small function.
An example of a bad constituent function from your example would be this one:
huh a = fromIntegral (a * a + 2 + 2 * a)
What does it mean, why are you doing it? It would be absurd to ask
for this as a library function in any library. Who knows what it
could possibly be named, except something inane like doArithmetic.
This function is most easily understood in its context; the function
that is trying to find integral values of this expression.
Spending a lot of time and thought about how to break up your
functions in the most understandable way will make you a better
engineer. In fact, it's a quality I find missing in many
professional programmers... unfortunately.
More information about the Haskell-Cafe