Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  testing and the culture of Haskell
      (Stephen Blackheath [to Haskell-Beginners])
   2.  Re: testing and the culture of Haskell (Heinrich Apfelmus)
   3. Re:  testing and the culture of Haskell (Amy de Buitl?ir)
   4. Re:  Re: testing and the culture of Haskell (Stephen Tetley)
   5.  HUnit or QuickCheck for test-driven developing a parser
      (Adam Cig?nek)
   6. Re:  HUnit or QuickCheck for test-driven  developing a parser
      (Stephen Tetley)
   7.  Re: testing and the culture of Haskell (Heinrich Apfelmus)
   8. Re:  Re: testing and the culture of Haskell (Isaac Dupree)


----------------------------------------------------------------------

Message: 1
Date: Wed, 20 Jan 2010 11:36:57 +1300
From: "Stephen Blackheath [to Haskell-Beginners]"
        <[email protected]>
Subject: Re: [Haskell-beginners] testing and the culture of Haskell
To: Michael Easter <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Michael,

 > A friend asked me about Test-Driven Development (TDD) within the FP
 > community.

My brother is a TDD (Test-Driven Development) guru but not a Haskeller, 
and I'm a Haskeller, and I've thought a lot about this question and 
asked around in the community.  My brother and I are always attempting 
to brainwash each other.  It's been quite effective so I essentially 
agree with TDD.  Here's my 2c worth on your questions:

 > Q: Is TDD advocated the Haskell community? Is it controversial? Is it
 > even on the radar?

I've never heard of anyone advocating TDD in the Haskell community.  It 
isn't controversial - it's on the radar for a minority, presumably in 
proportion to how much of their heads are in the mainstream community 
vs. the functional community.  So the functional community doesn't 
generally talk about TDD.

 > Q: If TDD is not advocated: why? Is there something about the Zen of
 > Haskell development that
 > is an impedance mismatch with TDD?

After much pondering, and with the proviso that everything is In My 
Humble Opinion, I believe there are some very sound technical reason why 
TDD doesn't quite work for Haskell.  TDD is really intended to catch two 
kinds of errors:  Programming mistakes, and wrong logic.  TDD proponents 
say "test logic only", but as a happy side effect they're catching a lot 
of programming mistakes too, and this adds significantly to the value of 
TDD.

Another reason behind TDD is that if your code is testable, then it 
forces it to be detachable from its "environment".  This makes the code 
more composable, but it goes much further than that:  The TDD process 
actually drives the design, and, one step further still - leads to an 
"emergent" design method.  So, adding a fourth point, the summary is 
that TDD is for

1. verifying logic;
2. detecting programming mistakes;
3. promoting a clean, and even emergent design;
4. making it so you can re-factor without breaking your code.

(apologies to TDD people if I misunderstand something)

Now, Haskell is *very* good at giving you 2, 3 and 4.  I have no idea 
whether Haskell gives 2, 3 and 4 better or worse than C# or Java coded 
in a TDD style.  Certainly it gives it to you with a whole lot less typing.

Haskell also contributes to 1, in that the type system *can be used* to 
significantly tie down your logic, and make mistakes less likely.  But 
ultimately Haskell can't make you write your logic correctly.

I am saying that I think Haskell gives you about 70-90% of what TDD 
gives you, but with less fuss.  The remaining 10-30% you still need 
testing for.

The key point, is that in functional programming, TDD is not really 
needed to "drive the design", because the language itself does the same 
job, but in a slightly different way:  Good design is the path of least 
resistance in Haskell, and since re-factoring is so safe and easy, it 
almost automatically tends in that direction.

So I think the main purpose of TDD ("driving the design") doesn't apply 
in Haskell.  The only part of TDD that applies to Haskell is verifying 
logic, but this can be done after the fact, with the added risk (not 
shared by TDD) that you won't bother.  The way Haskell programmers 
usually work, which I think is the best practice for the language, is to 
drive the design just through plain Haskell coding, but to have enough 
self discipline to recognize where your logic needs to be verified, and 
write tests in those cases.  (QuickCheck makes it so easy!)

I would certainly urge functional programmers to grasp the (actually 
somewhat subtle) philosophy behind TDD.

 > Q: Note that TDD and "writing tests" are different things. With respect
 > to "writing tests", I know
 > that HUnit exists and that RWH has a chapter on quality assurance.
 >
 >
 > Given that, I'd like to know: how widely is HUnit used? If you were to
 > start a new Haskell project, would you
 > include HUnit (a) immediately (b) eventually (c) maybe (d) another
 > adjective ?

I personally use HUnit a lot, so I use test-framework, which gives both 
QuickCheck and HUnit.  I think the best way is to use QuickCheck if you 
possibly can, and if not, use HUnit (either for IO-bound code, or for 
situations where it's easier to specify the test cases yourself than to 
induce QuickCheck to generate them).

I do about 1/5th of my tests in HUnit, so I would always anticipate that 
I would want it, so my answer is (a).


Steve

Michael Easter wrote:
> 
> Folks,
> 
> A friend asked me about Test-Driven Development (TDD) within the FP 
> community. I realize
> the FP community is larger than a Haskell mailing list, but I wanted to 
> get a sense from this
> camp.
> 
> I'm a fan of Haskell but I can't say that I know the culture yet. That 
> said, I'm writing as *a fan* and
> not a critic. These are genuine, earnest questions.
> 
> Q: Is TDD advocated the Haskell community? Is it controversial? Is it 
> even on the radar?
> 
> Q: If TDD is not advocated: why? Is there something about the Zen of 
> Haskell development that
> is an impedance mismatch with TDD?
> 
> Q: Note that TDD and "writing tests" are different things. With respect 
> to "writing tests", I know
> that HUnit exists and that RWH has a chapter on quality assurance.
> 
> Given that, I'd like to know: how widely is HUnit used? If you were to 
> start a new Haskell project, would you
> include HUnit (a) immediately (b) eventually (c) maybe (d) another 
> adjective ?
> 
> 
> sincerely
> Michael Easter
> 
> -- 
> ----------------------
> Michael Easter
> http://codetojoy.blogspot.com -> Putting the thrill back in blog
> 
> http://twitter.com/patentlyfalse -> Satirical tech headlines (and 
> nothing but)
> 
> http://youtube.com/ocitv -> Fun people doing serious software engineering
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners


------------------------------

Message: 2
Date: Wed, 20 Jan 2010 10:47:21 +0100
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: testing and the culture of Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

Michael Easter wrote:
> Q: If TDD is not advocated: why? Is there something about the Zen of Haskell
> development that is an impedance mismatch with TDD?

Static typing is a great help, it is not uncommon for Haskell code to be
correct on the first try once you convinced GHC that it's type correct.
There is much less need for TDD than in other languages.

Moreover, programming with pure functions offers a whole new approach to
program design. For instance, you can start with an inefficient but
obviously correct program and use laws and equations to rewrite that to
an efficient one. (You could call that "Proof Driven Design"). Here a
prime example:

   Richard Bird. A program to solve Sudoku.
   http://www.cs.tufts.edu/~nr/comp150fp/archive/richard-bird/sudoku.pdf

> Q: Note that TDD and "writing tests" are different things. With respect to
> "writing tests", I know
> that HUnit exists and that RWH has a chapter on quality assurance.

The purpose of HUnit seems to be testing code that mainly involves IO.
For the purely functional part, people usually use QuickCheck because
you don't have to think about test cases, it will generate them
automatically!


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



------------------------------

Message: 3
Date: Wed, 20 Jan 2010 10:31:16 +0000
From: Amy de Buitl?ir <[email protected]>
Subject: Re: [Haskell-beginners] testing and the culture of Haskell
To: Michael Easter <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I'm pretty new to Haskell, so take what I say with a very large grain
of salt. But this is a topic I've been thinking about because I happen
to be teaching a lab on TDD to Java and C developers at the moment,
while I myself am programming in Haskell in my research. So perhaps my
impressions will be of some use to you.

There are two reasons why I'm less likely to do TDD in Haskell. By far
the most important is the availability of a tool like QuickCheck.
QuickCheck changes everything. I don't write tests, I write
properties. QuickCheck generates the tests on the fly, and does a
better job than I could. There's a big difference between writing
properties and writing tests. If I were going to develop a large
application in Haskell, I'd try to honour the spirit of TDD by
defining properties before implementing functions.

A secondary reason is the availability of the interpreter. I test
functions in the interpreter as I write them. Of course, I'm not doing
a very thorough job, but I'll use QuickCheck to do the "real" testing.
I use the interpreter to test whether the function does what I
designed it to do, with some typical inputs. I then use QuickCheck to
verify that the function behaves nicely no matter what inputs it gets,
including inputs I might not have even thought of trying.

FWIW, I do plan to use HUnit to test the non-functional part of my application.


------------------------------

Message: 4
Date: Wed, 20 Jan 2010 11:02:08 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Re: testing and the culture of
        Haskell
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

2010/1/20 Heinrich Apfelmus <[email protected]>:
> Static typing is a great help, it is not uncommon for Haskell code to be
> correct on the first try once you convinced GHC that it's type correct.
> There is much less need for TDD than in other languages.

Ah, maybe the type checker is given all credit here, when perhaps it
should be shared?

With functional programming languages you are largely programming with
expressions - Scheme has the (begin ... ...) form for sequencing and
ML has sequence control structure (;), but there is simply less
control flow in typical functional programs than imperative ones
(there is also less use of assignment but that's hardly news of
course).

Figuratively speaking, functional programs have 'fewer movable parts'
to go wrong (vis-a-vis incrementing variable for loop indexes etc.
whereas map, fold, unfold, ... can be written once and used anywhere),
hence static-typing + control-flow reduction (+ limited use of side
effects) hopefully leads to first-time correctness.

Best wishes

Stephen


------------------------------

Message: 5
Date: Wed, 20 Jan 2010 20:48:47 +0100
From: Adam Cig?nek <[email protected]>
Subject: [Haskell-beginners] HUnit or QuickCheck for test-driven
        developing a    parser
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hello there,

Let's say I'm writing a parser for a toy programming language, and I
want to do it following a test-driven development philosophy. Which
would be better testing tool for this task, HUnit or QuickCheck (or
perhaps something else)?

Cheers,
adam.


------------------------------

Message: 6
Date: Wed, 20 Jan 2010 20:09:06 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] HUnit or QuickCheck for test-driven
        developing a parser
To: Adam Cig?nek <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi Adam

Presumably you would be doing the obvious thing and testing that the
parser fails for ill-formed files and works for well-formed files?

For well formed files - as you have a parser you would likely have
defined an abstract syntax tree, so you could use QuickCheck to
generate random syntax trees, pretty print them, then run the parser
on them to test them. Alternatively you might want a test generator
that builds all abstract syntax trees up to a certain nesting depth
rather than random ones (I think the GAST tool does this in Clean, I
suspect there is a similar Haskell tool).

For ill formed files, I think you would have to create them yourself.
You could write a 'sloppy printer' rather than a pretty printer that
injects syntax errors if you really wanted to do it automatically.

Myself, I would just keep a library of hand written example files,
both ones that should pass and ones that should fail, rather than try
to generate them.

Best wishes

Stephen


------------------------------

Message: 7
Date: Wed, 20 Jan 2010 21:48:29 +0100
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: testing and the culture of Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

Stephen Tetley wrote:
> Heinrich Apfelmus wrote:
>> Static typing is a great help, it is not uncommon for Haskell code to be
>> correct on the first try once you convinced GHC that it's type correct.
>> There is much less need for TDD than in other languages.
> 
> Ah, maybe the type checker is given all credit here, when perhaps it
> should be shared?
> 
> With functional programming languages you are largely programming with
> expressions - Scheme has the (begin ... ...) form for sequencing and
> ML has sequence control structure (;), but there is simply less
> control flow in typical functional programs than imperative ones
> (there is also less use of assignment but that's hardly news of
> course).
> 
> Figuratively speaking, functional programs have 'fewer movable parts'
> to go wrong (vis-a-vis incrementing variable for loop indexes etc.
> whereas map, fold, unfold, ... can be written once and used anywhere),
> hence static-typing + control-flow reduction (+ limited use of side
> effects) hopefully leads to first-time correctness.

Fair enough.

However, in a sense, one can interpret the pure in purely functional as
a property of the type constructor (->) , i.e. a function of type  (a ->
b)  is guaranteed to not have side effects. In this light, ML and Scheme
are lacking a very important type: they only have functions with side
effects. Or more precisely, their type system does not distinguish
between functions with and without side effects.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



------------------------------

Message: 8
Date: Wed, 20 Jan 2010 18:13:07 -0500
From: Isaac Dupree <[email protected]>
Subject: Re: [Haskell-beginners] Re: testing and the culture of
        Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

Heinrich Apfelmus wrote:
> However, in a sense, one can interpret the pure in purely functional as
> a property of the type constructor (->) , i.e. a function of type  (a ->
> b)  is guaranteed to not have side effects. In this light, ML and Scheme
> are lacking a very important type: they only have functions with side
> effects.

> Or more precisely, their type system does not distinguish
> between functions with and without side effects.

that's not actually more precise! Haskell doesn't entirely do that 
either. consider:
f :: Int -> IO Int
f x = return (x + 1)
No side effects! But other ->IO typed values do yield side-effects.

It is exactly as if ML and Scheme contain only the type of (->) composed 
with IO.  (Well, actually Scheme is dynamically typed so it's a bit 
silly to say so..)  (and Scheme allows functions with zero arguments, 
which are different from its non-side-effecting values.. not sure about ML)

-Isaac


------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 19, Issue 16
*****************************************

Reply via email to