WANT: bad code in python (for refactoring example)

Antoon Pardon antoon.pardon at rece.vub.ac.be
Wed Feb 15 05:49:50 EST 2017


Op 15-02-17 om 07:28 schreef Steven D'Aprano:
> On Wed, 15 Feb 2017 07:44:03 +0900, Makoto Kuwata wrote:
>
>> Hi,
>>
>> Is there any *just right* python code to refactor?
>> In other words, I'm finding bad code example in python.
>
> Try looking at the ActiveState website for recipes in Python. Especially 
> look at the ones with negative ratings, but even positively rated recipes 
> are often nonsense.
>
> E.g. http://code.activestate.com/recipes/580750
>
> does nothing more that define
>
> echo = sys.stdout.write
>
> Why not use sys.stdout.write directly? Or print? If I saw somebody using 
> this recipe in production code, in the way shown, I'd refactor it to just 
> use print. There's no advantage to re-inventing the wheel this way.

On reason to use this is for some easy "logging", you use echo to help
in debugging and afterwards you can either define echo as an empty
function or something easy to find to comment out.

-- 
Antoon Pardon.




More information about the Python-list mailing list