[mercury-users] Preferred coding style for switches

Robert Ernst Johann JESCHOFNIK rejj at cat.cs.mu.OZ.AU
Fri Dec 10 10:44:36 AEDT 1999


On Thu, 9 Dec 1999, Ralph Becket wrote:


> I've just rewritten several predicates from the first style (here N = M = 4
> and not all `bar's need be considered for some `foo's) and, while there is
> less verbiage on the screen thanks to the reduced number of clause heads,
> I'm not convinced that it's any clearer - indeed, the latter style may be
> worse.

I think I prefer the first style (multiple clauses). Even if you do get
more heads, I get the feeling that it is actually a tad neater.
To be fair though, I have been very unconsistant in the past with regards
to this, though.
I will still do a switch in style 2 for things like dealing with a list,
but for a type with many constructors, I lean towards style 1. If
anything, style 1 saves you one level of indentation. ;)

So, in summary - I think that for a type with more than, say, three
constructors the first style is `better'.



Rob
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list