A few ideas on code review

After watching a talk about code review1, from the last EuroPython, I got some ideas that I'd like to summarise.

The first one is a point I made on my talk about clean code in Python, about running style checks (PEP-8, for example), automatically as part of the CI. This has several rationales, the first one being that it's the sort of thing machines should do, and not humans. Having software engineers reviewing the tabs, spacing, and such, is just a wasted effort (not to mention, wasted money). As I mentioned on the conclusions during my talk, we should focus on the readability of the code in terms of the logic, by asking ourselves things like "does this code make sense?", rather than "is the space before the comma correct?". Remember, code is for humans, not machines, it's a means of communication with the development team.

Read more...

Glimpses of a Vim configuration

It's been a while since I started tracking versions of my custom Vim configuration, and making it available as an open source software in Github. The best of this project is, in my opinion, to have it under version control, so I can track changes and releases.

Every once in a while, when I find a new setting, or a great new feature, I modify the configuration, so they will become available on the next release. Besides the features that are mentioned in the project, and the customizations made, I feel very comfortable with the colour scheme I made.

Read more...

Default arguments in Python functions

This post is based on a gist I wrote a while ago, about why is not a good idea to pass default mutable objects as parameters in python function definitions.

While the gist is explained through an example that uses lists, the principle is applicable to all sorts of objects (dictionaries, sets, etc.).

{{ gist(owner=“rmariano” id=“7593536” filename=“function_parameters.md” )}}

If you are an experienced python developer, you probably knew this caveat, nevertheless is something interesting to show to new python developers, and to remember even if you have been writing code in Python for years.

Read more...

On returning consistent data types

This post is inspired on an issue I once found, while I was using a well-known library in Python for parsing YAML files. The problem was that when it was loading the content of the file, the result was not coherent, because sometimes it returned the content as a python dict, but if the file was empty, the return value was None.

Do you notice something odd here?

What if I want to use the result? I cannot do it safely, for example:

Read more...