Kore Nordmann wrote:
> On Wed, 2009-02-04 at 11:46 +0100, Jakob Westhoff wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Frederik Holljen wrote:
>>>>> Design goals ============
>>>>>
>>>>> The workflow of a creating a SystemProcess object applying 
>>>>> certain arguments as well as options to it and finally spawning 
>>>>> the process should be intuitive as possible. The best way to 
>>>>> achieve such an intuitive API would be to design it having the 
>>>>> fluent interface pattern in mind. The used interface should look 
>>>>> something like this::
>>>>>
>>>>> new ezcSystemProcess( 'echo' )->argument( 'foo' )->execute();
>>>> Method chaining can not be done with "new classname", so it has to 
>>>> be:
>>>>
>>>> $p = new ezcSystemProcess( 'echo' ); $p->argument( 'foo' 
>>>> )->execute();
>>> I don't see why the fluent interface pattern makes this more 
>>> intuitive. I'd say it makes it less intuitive as a command is really 
>>> not complicated at all and the fluent interface pattern is to make a 
>>> complicated API more intuitive to use.
>>>
>>> Consider: cmd = array( 'program_name', 'arg1', 'arg2', 'arg3', 
>>> 'arg4', 'arg5', 'arg6', 'arg7' ) pOpbject = 
>>> ezcSystemProcess::execute( cmd )
>>>
>>> vs $p = new ezcSystemProcess( 'program_name' ); $p->argument( 'arg1' 
>>> )->argument( 'arg2' )->argument( 'arg3' )->argument( 'arg4' 
>>> )->argument( 'arg5' )->argument( 'arg6' )->argument( 'arg7' 
>>> )->execute();
>>>
>>> Which one is easier to read and less hassle to write? Another 
>>> advantage of the top one is that you can easily alter one parameter 
>>> and then run the command again.
>> I agree with you, that in the case presented above the array seems to be
>> more readable. But as soon as arguments tend to get a little bit longer
>> or contain variables in my opinion the fluent interface provides much
>> more readability, especially with proper formatting.
> 
> Also, it allows to extend the functionality with "special" arguments,
> which require processing, like ->pathArgument() with some applied magic
> to work cross different OS.

I guess all ways of calling should be supported in order to please 
everybody. So you can write:

$p->argument( 'arg1' )->argument( 'arg2' )->execute();

or:

$p->arguments( 'arg1', 'arg2' )->execute();

Some questions about SystemProcess:

* Are arguments values abstracted? If I use $p->argument( 'arg1' ) does 
it mean the command takes the argument 'arg1' or does it mean it takes 
the argument '-arg1' or '--arg1' or '/arg1'? Also some commands require 
quotes around arguments if they contain spaces. How about arguments like 
'-D sqlite://:memory:' - is this one or two arguments in SystemProcess?

* Is there some abstraction about the arguments' order? Some commands 
require the object (file, dir etc) first then the options, while others 
require the options first and then the object. Some commands require 
'--' between the options and the object. Do you need to know the command 
by heart before calling it or can some of the command's details be 
abstracted?

-- 
Alexandru Stanoi
System Developer
eZ Systems | http://ez.no
-- 
Components mailing list
Components@lists.ez.no
http://lists.ez.no/mailman/listinfo/components

Reply via email to