[RFC] using `if WINDOWS` instead of `if sys.platform == 'win32'`?

Alexander Belchenko bialix at ukr.net
Thu Sep 6 12:55:25 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil пишет:
>>>>>> "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.

Probably I misunderstand you at first time.
No, I cannot refactor out all 100 places to functions in osutils.
Try to grep for 'sys.platform' and you'll see why.

[µ]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG3+qtzYr338mxwCURAqAEAJ93xIVMXXDsmu2e/3u4ddFVi4UDGACdGd87
nRBpTAR7gMtS+4EMO91qrOM=
=Nx7P
-----END PGP SIGNATURE-----



More information about the bazaar mailing list