Re: Best Practices
- Posted by jeremy (admin) Jan 03, 2011
- 1888 views
I was looking at cmd_parse() documentation
What about adding "write functions with simple interface" to best practices.
Simple tasks can have simple interfaces. Complex tasks rarely can have simple interfaces. However:
map args = cmd_parse({ { "o", 0, "Output directory", { HAS_PARAMETER } }, { "v", 0, "Verbose mode" } })
Is pretty simple for what you get. Full command line parsing including extras, nicely formatted help screens, argument validation (checking ones supplied are valid and erring with usable information when one is supplied that is not allowed, checking that those that require parameters have parameters). If you take the above 4 lines of code and implement that in your program the old fashioned way... It's pretty simple.
Now, where your tip comes into play is having a simple process with a complex interface. That indeed is terrible. I do not think that rule applies, however, to man:std_cmdline#cmd_parse. The docs can look daunting for that method, I agree. Maybe what is needed is a bare bones example up front such as the one above.
Jeremy
Just added ticket:585 which will be part of 4.0.1 release.