[Development] [Qt5-feedback] Command line parser in QtCore?
Craig.Scott at csiro.au
Craig.Scott at csiro.au
Sun Oct 23 00:51:54 CEST 2011
On 22/10/2011, at 10:44 PM, Thiago Macieira wrote:
> On Saturday, 22 de October de 2011 11:29:38 Craig.Scott at csiro.au wrote:
>> With that out of the way, I've put the class definition up on pastebin for
>> comment. I've withheld the implementation until I've had a chance to clear
>> it with our legal people. In the meantime, I think the interface of the
>> class is probably enough to get some feedback on whether people think this
>> has the potential to be a viable candidate for a command line parser for
>> Note that the code currently does not adhere to the Qt coding guidelines (it
>> follows ours instead), but if we do end up contributing it to Qt, then it
>> should not be too difficult to bring it into line.
> Hi Craig
> It's not just the coding guideline, it's the architecture. I'm not a fan of
> tool classes with virtuals...
The usage() function should not have been virtual in the first place and could be easily made non-virtual without lose of functionality, so that just leaves validate(). One could potentially leave validate() as non-pure virtual if you want to allow subclasses to not bother validating, but I think that's sending the wrong message to developers. Seems like a poor compromise just to allow people to use the class without having to subclass it. If you want to validate your flags/arguments, you are either going to have to create a new class for it at some point (in which case why not use a virtual validate since you are creating a new class anyway), or you are going to have to inline your validation in the code where you make use of the flags. I guess that latter case seems justifiable, but I'd personally prefer to see all the argument handling code within the one (sub)class - one class, one responsibility and all that. But I do think there's value in making the class encourage devs towards thinking about validation. I've already seen that in our code, it has had the effect that devs think about and implement validation as they go rather than "getting around to it" later.
That said, if you have suggestions for how to achieve the same goals without using a virtual function, I'm open to it. The cases I've seen so far though just seen unnecessarily complex compared to the simplicity of the approach we've gone with.
Dr Craig Scott
Computational Software Engineering Team Leader, CSIRO (CMIS)
More information about the Development