[Haskell-cafe] Proposal: New syntax for Haskell

Tikhon Jelvis tikhon at jelv.is
Sat Sep 14 22:24:57 CEST 2013

My problem with cucumber is not the idea of a high-level DSL for tests. Au
contraire--I think this is a perfect place for a little language. I could
easily see a similar tool being useful for Haskell.

Rather, my issue is with the syntax. Not gherkin in particular but rather
languages that try to look like English in general. For one, these
languages tend to hit the uncanny valley--they're somewhat natural, but not
entirely. Perhaps the code reads like poorly written prose, but you
certainly can't write it in a natural fashion!

More importantly, I do not think prose is a good format for this sort of
thing at all. It's good for reading code, but I almost never read code
directly. Instead, I usually look over large parts of code at a time. I
want code where I can get the structure at a glance and easily separate the
parts that are specific to the current application from ones that aren't.
With prose-like syntax, this is very difficult because everything is made
of words. That programming language syntax you dismiss as line noise? It's
actually the structure of the code, which makes it much *faster* to read!

There's a reason mathematicians user equations and diagrams so much. A
single equation can replace literally pages of text, and you can have a
pretty good idea of what's going on without having to look too closely at
all the details. Think about an integral, for example: from the equation,
you can easily see what sort of equation it is (trigonometric, polynomial,
exponential...), what domain you're integrating over, what the limits are
and, very importantly, that it *is* an integral rather than something
completely different. All just from what the equation looks like, before
you've had to expend much attention on it.

One way to think about it is that the notation factors out the repeated
parts of an integral so that it's easy to visually separate from the
"meat"--the function you're actually integrating. A good DSL uses symbols
to do the same thing.

The main cost, of course, is that you have to learn the notation. But this
is really a one-time cost; if you're going to be seeing a lot of integrals,
it's more than worth doing, especially because there's so much shared
structure between them. Similarly, it's worth doing for tests, for the same
reasons. There's a lot of shared structure--just look at how many
relatively long phrases got repeated even in the simple examples given
here--and you want to look over that structure without actually reading it.
Much easier with actual syntax than prose. In any real app, you will have
hundreds of tests, and learning to deal with the "line noise" gets
amortized over all of them, whereas the benefits (shorter code that's
easier to scan) scale at least linearly.

So I think we should really avoid the faux-natural-language syntax as much
as possible.
I just want to chime in to defend Cucumber, which I use in Ruby at my day
job. I see a lot of people put up the strawman that it can only be used as
a way for business people to write acceptance tests. That idea is
questionable and I've never worked at a company big enough to require that,
or with business people who have ever wanted to write my tests for me.

In Ruby, I use Cucumber purely for myself to drive high level acceptance
tests for products. I think the sweet spot for it is when you're starting
work on a high level feature and you have NO idea how it will be
implemented or even how it will work in detail. I find that writing in the
limited language that Gherkin provides keeps my brain from going right to
implementation details. I write out tests that explore how the system
should work. I write them in the perspective of the user (which you should
be doing in your head regardless because the user is the one who will
actually interact with your program). I then read them back and make sure
they make logical sense. Only then do I start hooking up the steps I wrote
to code that drives integration/acceptance tests, via a browser for
instance. At the end I have a failing cucumber test that describes the
system in an intuitive manner with zero line noise (programming language
syntax). I am now free to think about implementation details, write lower
level unit tests and implement things that can be described in much less
verbose fashion. I really like that process and if I ever had a job to
develop products in Haskell, I'd probably take a similar approach.

Do note that I advocate using Cucumber to create/drive user stories, not to
unit test low level functions like folds. If you don't have a customer of a
particular function who could describe how they interact with it in
layman's term, then Cucumber is the wrong tool. Use quickcheck/hunit/hspec
for that.

On Thu, Sep 12, 2013 at 3:42 PM, Bob Ippolito <bob at redivi.com> wrote:

> Have you tried AppleScript? I wouldn't say it's pleasant to use, but it's
> easy to read.
> On Thursday, September 12, 2013, David Thomas wrote:
>> I've long been interested in a scripting language designed to be spoken.
>> Not interested enough to go about making it happen... but the idea is
>> fascinating and possibly useful.
>> On Thu, Sep 12, 2013 at 2:57 PM, Andreas Abel <andreas.abel at ifi.lmu.de>wrote:
>>> **
>>> +1
>>> Cucumber seems to be great if you mainly want to read your code over the
>>> telephone, distribute it via national radio broadcast, or dictate it to
>>> your secretary or your voice recognition software.  You can program thus
>>> without having to use you fingers.  You can lie on your back on your sofa,
>>> close your eyes, and utter your programs...
>>> We could have blind Haskell/Cucumber programming contests...
>>> Tons of new possiblilities...
>>> Strongly support this proposal. ;-)
>>> Andreas
>>> On 2013-09-10 22:57, Artyom Kazak wrote:
>>> On Wed, 11 Sep 2013 00:20:26 +0400, Thiago Negri <evohunz at gmail.com> wrote:
>>> I hope these jokes do not cause people to be afraid to post new ideas.
>>> Agreed. I would also like to clarify that my message was much more a joke
>>> on
>>> the incomprehensibility of legal acts than on the original proposal.
>>> By the way, I am pretty impressed with this piece of Cucumber
>>> description/code:
>>>    Scenario: Mislav creates a valid task with an upload
>>>      When I go to the "Awesome Ruby Yahh" task list page of the "Ruby
>>> Rockstars" project
>>>      When I follow "+ Add Task"
>>>      And I fill in "Task title" with "Ohhh upload"
>>>      And I follow "Attachment"
>>>      When I attach the file "features/support/sample_files/dragon.jpg" to
>>> "upload_file"
>>>      And I press "Add Task"
>>>      And I wait for 1 second
>>>      And I should see "Ohhh upload" as a task name
>>> I was much more sceptical when I had only seen the example in Niklas’s
>>> message.
>>> _______________________________________________
>>> Haskell-Cafe mailing listHaskell-Cafe at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
>>> --
>>> Andreas Abel  <><     Du bist der geliebte Mensch.
>>> Theoretical Computer Science, University of Munich http://www.tcs.informatik.uni-muenchen.de/~abel/
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe at haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

Michael Xavier

Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130914/3d6af2f2/attachment.htm>

More information about the Haskell-Cafe mailing list