Skip to content

Instantly share code, notes, and snippets.

@brun0xff
Last active July 4, 2018 20:50
Show Gist options
  • Select an option

  • Save brun0xff/be8dc463f74fd8222a73084dcb36f28a to your computer and use it in GitHub Desktop.

Select an option

Save brun0xff/be8dc463f74fd8222a73084dcb36f28a to your computer and use it in GitHub Desktop.

Revisions

  1. brunoathaíde revised this gist Jul 4, 2018. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion boas-praticas-sw-engineer.md
    Original 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/?
    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
  2. brunoathaíde revised this gist Jul 4, 2018. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions boas-praticas-sw-engineer.md
    Original 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._

    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/?
  3. brunoathaíde created this gist Jul 4, 2018.
    19 changes: 19 additions & 0 deletions boas-praticas-sw-engineer.md
    Original 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/?