Re: [PATCH 4/5] libusbg: Replace usage of function name with type and instance.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 02, 2014 at 03:34:55PM +0200, Krzysztof Opasiak wrote:
> > -----Original Message-----
> > From: David Laight [mailto:David.Laight@xxxxxxxxxx]
> > Sent: Wednesday, April 02, 2014 3:09 PM
> > To: Krzysztof Opasiak; mporter@xxxxxxxxxx; linux-
> > usb@xxxxxxxxxxxxxxx
> > Cc: Andrzej Pietrasiewicz; Karol Lewandowski; Stanislaw Wadas;
> > ty317.kim@xxxxxxxxxxx; Marek Szyprowski; Robert Baldyga
> > Subject: RE: [PATCH 4/5] libusbg: Replace usage of function name
> > with type and instance.
> > 
> > From: Opasiak
> > > User of library should not use directly function name but
> > > only type of the function and name of instance. Using this
> > > will separate user for naming convention on Config FS.
> > 
> > Personally I'd have thought it much better to pass in a
> > string name rather than a function number.
> > Far less scope for stupid errors.
> > 
> > You probably still want to check that the name passed is one
> > of the expected names.
> > 
> 
> In my opinion both approach are considerable. Currently function type is
> represented in library using usbg_function_type enum. This approach also
> has some advantages, you can simply iterate over function types and
> checking the correctness of parameter is far faster and simpler than
> checking if provided string is one of correct function type. Moreover
> operating on enum is easier for API user than operating on string, think
> about copying, passing to function, memory allocation etc. Of course we
> could provide array of function names and users could use cons char*
> pointer but I don't see any advantages in using such pointer instead of
> enum.
> 
> Moreover, I'm not a fan of writing few times the same string because
> compiler will not notify you about typos. If you make a typo in enum
> value name (and there is no other enum value with such name) you will
> get compilation error. When you will use "acm" string and make a typo
> "amc" you won't get any errors or even warnings.

This was the whole point of having the enumed function types in the
first place, allow the compiler to help us find errors. So yes, I agree,
don't go down the path of passing in a string.

There's other subtle string naming requirements in the gadget configfs
API that ultimately we should hide. Like the requirement on the gadget
instance string or the syntax for configuration instances, for example.

-Matt
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux