Last active
July 4, 2018 20:50
-
-
Save brun0xff/be8dc463f74fd8222a73084dcb36f28a to your computer and use it in GitHub Desktop.
Revisions
-
brunoathaíde revised this gist
Jul 4, 2018 . 1 changed file with 12 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ 1. Uma boa prática é ao capturar exceções, mencionar sempre que possível as exceções específicas, em vez de usar apenas `except Exception`. Exemplo: ``` @@ -14,4 +15,14 @@ _A good rule of thumb is to limit use of bare 'except' clauses to two cases:_ _1. If the exception handler will be printing out or logging the traceback; at least the user will be aware that an error has occurred._ _2. If the code needs to do some cleanup work, but then lets the exception propagate upwards with raise. try...finally can be a better way to handle this case._ Fonte: https://www.python.org/dev/peps/pep-0008/? 2. É preferível usar list comprehension em vez de filter/map quando uma lista é esperada como retorno, especialmente quando o código original usa `lambda`. Dá uma olhada: _map() and filter() return iterators. If you really need a list, a quick fix is e.g. list(map(...)), but a better fix is often to use a list comprehension (especially when the original code uses lambda), or rewriting the code so it doesn’t need a list at all. Particularly tricky is map() invoked for the side effects of the function; the correct transformation is to use a regular for loop (since creating a list would just be wasteful)._ Fonte: https://docs.python.org/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists -
brunoathaíde revised this gist
Jul 4, 2018 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,4 @@ _A good rule of thumb is to limit use of bare 'except' clauses to two cases:_ _1. If the exception handler will be printing out or logging the traceback; at least the user will be aware that an error has occurred._ _2. If the code needs to do some cleanup work, but then lets the exception propagate upwards with raise. try...finally can be a better way to handle this case._ Fonte: https://www.python.org/dev/peps/pep-0008/? -
brunoathaíde created this gist
Jul 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ Uma boa prática é ao capturar exceções, mencionar sempre que possível as exceções específicas, em vez de usar apenas `except Exception`. Exemplo: ``` try: import platform_specific_module except ImportError: platform_specific_module = None ``` Dá uma olhada: _A good rule of thumb is to limit use of bare 'except' clauses to two cases:_ _1. If the exception handler will be printing out or logging the traceback; at least the user will be aware that an error has occurred._ _2. If the code needs to do some cleanup work, but then lets the exception propagate upwards with raise. try...finally can be a better way to handle this case._ Acho que nesse caso cai em 1, então não vejo necessida de modificações, e fica como fica no caso de você ainda nao ter visto por ai :) Fonte: https://www.python.org/dev/peps/pep-0008/?