[darcs-devel] Greetings and some questions

Dino Morelli dino at ui3.info
Mon Oct 2 19:53:27 PDT 2006


On Mon, 2 Oct 2006, David Roundy wrote:

> Usually this means that we've got some mixed up (and human-unfriendly) code
> organization going on, and the code will benefit in readability from
> adjusting the modules.  In this case, get_long_option really belongs in
> DarcsArguments, which defines the relevant data types.  I also notice, that
> get_long_option seems to be buggy in its treatment of options that have
> more than one synonymous long option.  I'm not sure that we use any such
> options, but it looks to me like get_long_option is potentially buggy.
> This is another danger of "blindly" exporting functions that aren't
> currently exported at all: they might be bugless in their current use, but
> misbehave under different usages.  Ideally, exported functions shouldn't
> behave like this, since they should be designed to be resistant to misuse
> (either in that their name unambiguously defines their meaning, or even
> better if their type can unambiguously define the meaning).

When you say this one is buggy, do you mean that if it received a OptDescr
DarcsFlag that had two or more long option strings (let's say it was
constructed with ["foo", "bar"]), it would construct a string like this:

    "--foo--bar"


If modified like below, it would create comma-separated, human-friendly
strings from flags with any number of long opts:

    get_long_option :: OptDescr DarcsFlag -> String
    get_long_option (Option _ [] _ _) = ""
    get_long_option (Option _ l  _ _) = get_long_option' l where
       get_long_option' [x]      = x
       get_long_option' (x:y:[]) = x ++ " or " ++ y
       get_long_option' (x:xs)   = x ++ ", " ++ get_long_option' xs


Output would be like this:

[]                     -->  ""
["foo"]                -->  "--foo"
["foo", "bar"]         -->  "--foo or --bar"
["foo", "bar", "baz"]  -->  "--foo, --bar or --baz"
... commas from here on out ...


..or maybe I should leave it alone and find something else to do. :)


-- 
  .~.    Dino Morelli
  /V\    email: dino at ui3.info
/( )\   irc: dwm
^^-^^   preferred distro: Debian GNU/Linux  http://www.debian.org




More information about the darcs-devel mailing list