Article: 10 Time-saving Tips for Pythonists

Originally published at http://www.sitepoint.com/10-time-saving-tips-pythonists/


Python is a beautiful language, able to inspire love in its users. So if you’re looking to get into programming, or if you’re a bit tired of C++, Perl, Java and the rest, I recommend you give Python a try.

Python has many features that make it attractive to programmers. It’s easy to learn, object oriented, byte-compiled, free and open-source. It also has run-time type checking, full and fast support, and extensive libraries for performing various tasks.

Efficiency with Python

In this article, I want to highlight some of the ways you can save time in Python and thus maximize productivity.

In preparation, I quizzed several Pythonists on their best time-saving tips. Here are the results …

1. Don’t Use Semicolons

Since using semicolons is considered optional in Python—as opposed to other object-oriented programming languages—you don’t need to end each statement of your code with a semicolon.

This may seem simple and not really time wasting; but once your code stretches into thousands of lines, all these semicolons can get a bit distracting, and it’s a lot of unnecessary typing.

2. Get a Good Code Editor

Choosing the right Python editor can be a huge time saver. Many new Python programmers are confused over which code editor to pick—especially with so many available.

It’s very disruptive to get used to one editor and then have to change to another, so it’s best to start with a good one. Make sure whichever you choose does flake8 and PEP8 in real time.

For guidance on which editor to choose, see my previous article on Which Code Editors Do Pythonists Use?

3. Follow the Python Code Style

example of Python style

Following the Python code style can enhance the readability of the code, and thus saves time while walking through your code. (The design philosophy of Python emphasizes the issue of code readability.)

4. Use the help() Function

Python’s help() is a very handy, built-in function that can save a lot of time—for example, when searching for descriptions of other functions. You can simply run this function directly from your interpreter console.

The Python documentation describes the ways you can put this function to good use.

5. Use Libraries

There are lots of Python libraries that save you from reinventing the wheel every time.

For example, you can choose from a range of packages offered by PyPI (the Python Package Index), a repository of Python software.

A nice example of a Python library is scikit-image. It enables image processing tasks like blurring, enhancing contrast and zooming—simply by calling functions.

6. Use Cookiecutter

Cookiecutter is a command-line utility that enables you to create all your Python project boilerplates from project templates, and this can be a big time saver.

7. Comment Rigorously

Getting in the habit of commenting your code will save you—and others—a lot of time, especially down the track. (Yes, we hear this a lot, but many programmers still need to be reminded, it seems!)

Commenting is particularly vital when working on teams—especially ones that change a lot.

8. Test Often

Try to test every component in your program. While it may sound time-consuming, testing as you code saves a lot of time in the long run, and reassures you that there are no hidden bugs. It also reinforces your understanding of what each piece of code is actually doing.

A REPL—a read-eval-print loop—is a common means of testing your code as you go, and is often employed by Pythonists.

9. Focus and Specialize

A common recommendation of accomplished Pythonists is to have a specialized focus or area of expertise. There are lots of things you can do with Python—from coding for web cams to dealing with computations and mathematics.

There are great libraries available to help with these tasks, such as SimpleCV, dealing with computer vision; Biopython, a library for biological computation; and SymPy, a library for dealing with symbolic mathematics.

Digging into areas like these, and mastering a particular framework, helps you learn Python at a deeper level, master a particular style of coding (mentioned in point 3), and deal with specialized types of problems.

10. Write Code Every Day

When you get in the habit of writing Python code every day, solving problems using Python will start to become second nature. You’ll start to think in Python, so to speak, and this ultimately helps you to navigate and solve issues faster.


Continue reading at http://www.sitepoint.com/10-time-saving-tips-pythonists/

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.