[racket] Looking for feedback on code style
On 9/9/10 9:24 AM, Noel Welsh wrote:
> On Thu, Sep 9, 2010 at 1:09 PM, David Van Horn<dvanhorn at ccs.neu.edu> wrote:
>> What!?
>
> What can I say -- I have low standards.
>
>> Without a purpose statement, contract, or examples, it's difficult to know
>> what this code is supposed to do, much less say if it is doing whatever it
>> is supposed to do correctly.
>
> 'round these parts the term 'median' has widely accepted usage. It is
> pretty obvious that the given function was intended to compute this
> median and further more how it was going about doing so. For
> production code I'd want some tests (which would have caught the
> errors you noted) and a contract. I'm not too hung up on a purpose
> statement for something so simple. But the question was about the
> style and structure of the code as given, for which I responding that
> it is indeed idiomatic and clear.
Sure, median has a well understood meaning, but the contract is subtle
and the first attempt at writing it will likely be wrong. And beyond the
errors I caught, there are other bugs that will surface if examples were
written. As for the structure of the code as given, I would use helper
functions in place of the `let'. The resulting code will be easier to
read and the helper functions can be tested independently, making it
easier to maintain and improve the likelihood that the whole program is
correct; and correctness and ease of maintenance are important aspects
of style.
David