[Zope3-dev] service names
Shane Hathaway
shane@zope.com
Mon, 03 Feb 2003 14:55:57 -0500
Jim Fulton wrote:
> Steve Alexander wrote:
>
>> sean.bowman@acm.org wrote:
>>
>>> hello,
>>>
>>> In all the code I've seen in Z3, the second argument to getService is a
>>> string literal. This smells bad to me -- it seems to violate Once And
>>> Only Once. Would it be a good idea to use a constant instead of a
>>> string
>>> literal? For example::
>>>
>>> getService(context, defaultHubIdsName)
>>
>>
>>
>> Why not just HubIds ?
>>
>> HubIds = 'HubIds'
>> getService(context, HubIds)
>
>
> Why not just 'HubIds'?
>
> I really fail to see the benefit of a variable or a marker interface here.
I've been pondering this for a few days. I like to use global variables
as constants to shield myself from certain typos. In the example below,
'Id' is sometimes misspelled 'ID':
queryService(context, HubIds) -> hub IDs service
queryService(context, HubIDs) -> NameError
queryService(context, 'HubIds') -> hub IDs service
queryService(context, 'HubIDs') -> None
In the last case, the error might go undetected. So there is at least
one benefit to using a variable. It's not terribly important, but I
thought it was worth mentioning. :-)
Shane