[RFC] using `if WINDOWS` instead of `if sys.platform == 'win32'`?
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Sep 6 12:39:06 BST 2007
>>>>> "bialix" == Alexander Belchenko <bialix at ukr.net> writes:
bialix> Vincent Ladeuil пишет:
>>>>>>> "bialix" == Alexander Belchenko <bialix at ukr.net> writes:
>>
bialix> There are around 100 places where bzrlib code try to check
bialix> if it run on Windows by comparing `sys.platform == 'win32'`
bialix> or similar. About the half of this checks is inside core code,
bialix> and another half in tests.
>>
bialix> I'd like to change this places by defining in bzrlib/__init__.py
bialix> constant with name 'WINDOWS' or something similar and use
bialix> this constant where needed.
>>
bialix> WINDOWS = sys.platform == 'win32'
>>
bialix> ...
>>
>>
bialix> if WINDOWS:
bialix> do_something_crazy()
>>
bialix> if not WINDOWS:
bialix> do_another_thing()
>>
>>
bialix> Proposed change should make code more clear.
bialix> Anyone have objections or suggestions?
>>
>> Can you try to reduce the 100 places to functions inside osutils
>> instead ?
bialix> Why for?
To insulate the platform specific code. That will reduce the
number of places we (in that case mostly you) will have to fix if
other problems occur.
The code will be clearer and newcomers will be less likely to use
non os-independant idioms.
bialix> Calling a function in Python is expensive operation.
bialix> Check boolean variable should be much faster.
If you're about to make an io-related operation, the function
call time will be lost in the noise.
Vincent
More information about the bazaar
mailing list