2014-05-12

 



Great chance are, that you will going to love this cross platform Python IDE 

As with any open source software development platform, Python was blessed (or cursed?) with myriad of ways to develop program written on it: "With what IDE/Text Editor should you develop your next killer Python application?". A free and open policy, does initiate and keep energetic programmers to stay awake in this awesome Python world. But for newcomer, choosing the right IDE can become a daunting task. Add that with the phenomenon of epic war between IDE/Editor community, and you may find your way to choose a Python IDE not as trivial as it is in .NET development: any Visual Studio contender anyone?

Hereby, I started a new line of series on this blog that specifically review Python IDE at my disposal. Although it's not easy to stay away from subjectivity of certain IDE, but I am trying to do so, by deciding several important features that must be existed in a Python IDE: its overall value will be increase if it posses these features.

This article will also serve as an important article for Python for Beginner series: I believe coding Python in an IDE will bring much more advantages for beginner out there. Great. Let's start the review with a cross platform IDE : PyCharm from Jetbrains. 

But, wait a minute, what is an IDE?

IDE stand for Integrated Development Environment: a software designed with special purpose to ease programmer in developing computer programs. The term INTEGRATED literally means that you will only need this piece of software in your programming activities. No more external application needed. Or to be exact, even though there are cases that IDE will eventually use external application, at least this was handled automatically. No manual configuration steps needed in your part. You just know that it is works!

IDE will undoubtedly, boost programmer productivity (although not necessarily their code quality). There are voices in the internet that oppose the use of an IDE: what they want is a vanilla working environment. This means a working environment consisted with a general purpose Text Editor (such as ViM, Emacs, Sublime, TextMate, etc) complemented with built-in programming language (command line) tools. And as I have principle that there are really nothing truly right or wrong in this world, there are only preferences, so I am unable to say that this choice is wrong. There are groups of people who love to work in an IDE and there are others that love to work with a Text Editor. Me? To be honest, I often switch side. I'll let you know in great detail in the subsequent Python IDE article.

But, my prejudice is, in the context of newbie who just come to Python programming or programming in general, you will definitely love an IDE more than just a general Text Editor. Let me know if my prejudice is wrong!

Features to Be Expected in an IDE

Actually, if you are a programmer in just this recent years, you won't be surprised at these features. You will even think that this expected features to be .. well, standard features. The truth is, it's not. Programmers have been crafting these "modern" IDE features for years. And now we have it!

What are those? Here they are:

Project files navigation

Present your application source code files and its related resource in an easily navigable view

Code coloring (including syntax coloring and error hinting) and proper indentation.

It will allows you to have a quick glimpse at the code and able to identify instantly whether an identifier is a reserved word, your own identifier or an unknown identifier.

Go to definition.

Ever have to read a new code coming from an open source project? You will greatly benefit yourself from the ease of use IDE feature that let you CTRL+Click (or other shortcut) an identifier to go to its definition (if available). Add that to the fact that an identifier may be defined from external file three level nested down the current active directory (or may even defined in external directory hierarchy). Phew, this feature alone will make me stick to choose an IDE when doing coding activities. 

Smart code completion (or intellisense in Microsoft term).

You start with a blank *.py file... so, what's next? Try to type CTRL+SPACE... voila! You will get all the available identifiers known to the current context. Or, by just typing two alphabet for a given 16 characters long identifier, you will presented with all matching identifiers starting with that two characters. Simply pick the one that you like and press ENTER. The IDE will automatically completes your long identifier for you.

But I believe the most important feature is the ability in displaying all methods and properties for a given object when you hit the dot character. In most cases you will stay away from API documentation page and proactively inspect this dot character code completion list.

Walk through debugging.

In my early programming education, I always love to debug the application that being created one step at a time. It teaches me how the code get executed in a visually pleasing interactive experience. Now, in my professional career, this feature is extremely important when you have to find a needle in haystack that create strange result in your application.

Refactoring.

Refactoring is the term popularized by Martin Fowler, which is a continuous process taken to restructure current code into better quality code. This process maybe the most complex feature needed in a software development process. Given the nature of code that will be scattered into many files, the task of restructuring code can prove to be daunting task if done incorrectly. Imagine if you have to rename an identifier. Manually renaming them will be too tiresome to accomplished. With a good IDE, this process will be so much fun to do.

Integrated console.

Your applications will eventually get executed by the operating system. The feature to run them and inspect its console output within the IDE is greatly important when you have to deal with multiple applications.  

Those seven features are features that must existed in an IDE (or a Text Editor) for a convenience programming experience. Try to lose one of them, and I believe you will always seek for another IDE.

Great. Now let's move on to our PyCharm Python IDE Review!

PyCharm : Brief Introduction

If you are a Java Programmer, chance are that you have already use its Java IDE: IntelliJ IDEA. IDEA users will feel right at home when they have to use PyCharm to do Python development. PyCharm source code base must be branched from IDEA itself. PyCharm (like IDEA) is also built with Java technology, hereby, making it a cross platform application.

Thanks to folks at Jetbrains, PyCharm is coming with two versions: Community Edition (free to use at any condition whatsoever) and Professional Edition (paid version, with free version for selected open source project). Some of you maybe thinking that the Community Edition is far inferior than the Commercial Edition. You will amaze that actually, it is not. Or, to be exact, your daily coding activities my not required professional features which are there in Professional Edition. Click here for full comparison of both version.

Even though PyCharm is a Java application, you don't have to download and install separate JRE for it: it already shipped with JRE ready to use. Just download PyCharm from here (either the Community or Professional Edition),  and install it. In a short moment, you will have yourself a cross platform and versatile commercial quality Python IDE: at no cost. Isn't that great?

Study Case: PythonIDE Class

For the subsequent subtopics, I am going to demonstrate PyCharm features using the following class stored in a module named pythonide.py:

The above is a simple Python class to represent a Python IDE properties and methods. Also, we are going to need a main module named main.py below to use the above class:

Using the above two modules will ease us in understanding the expected IDE features more easily.

Feature 01 : Project Navigation

To be considered as a project, PyCharm will identify a source code directory by the existence of .idea/ directory within that directory (hence, you may want to add this directory in your .gitignore file). Inside this special purpose directory, PyCharm will store the current state of the project, project files content, configuration etc. To open a directory as a project, simply choose File->Open Directory menu item and choose a directory to open. The above two modules which were stored in a directory python-for-beginner\IDE_review will be displayed in a tree view as follow:

Project view in PyCharm

 

To open a file simply double click it in the navigation pane displayed as tree view above. 

Feature 02 : Code Coloring

Have a look at below picture that display an active editor showing the content of pythonide.py:

Charming code coloring for a *.py file

Even if this is your first time in seeing Python code (which is not that unlikely), by seeing the above screenshot I am sure you can easily distinguish Python identifier groups by the different colors used. For example, somehow you know that the method __init__() and __repr__() were lies in different group than the method the_best(). The first is a special purpose method or a method override, while the second is your own user defined method.

Also, how Jetbrains choose a color scheme in my opinion is very clever. For example, you do realize that the comment was drawn with a faded gray color, right? It gives the effect of a not so important piece of code. While literal string was emphasized from the rest by using a green coloring. Notice also how PyCharm has spell checker that was great, but still with any overactive spell checker, it has annoying effect of trying to suggest me that my name was incorrectly spelled. "Thank you very much PyCharm. But I am happy with my last name. Please don't tell me that it was a mistake.." 

Another great thing about PyCharm, which I believe to be the most lovable feature, is how it display visual clue when we violate from the PEP 8 code convention guidelines. For example, if we delete a vertical space from the above class construct, PyCharm will gives us this visual clue that we violate a convention.

We violate a convention here!

 

I found this to be the best way to follow this PEP-8 guidelines! 

Feature 03 : Go to Definition

Simply press CTRL key and hover to any recognized identifier in your source code, PyCharm will change your mouse cursor into hand icon and draw underline in the given identifier, to give visual clue that you can click it.

Click it to jump to the above identifier definition

Upon clicking it, the cursor will be moved to Python module containing the definition of PythonIDE method constructor. To go back to previous edit position, hit the key CTRL+SHIFT+BACKSPACE. Also, notice how PyCharm display method comment in the popup above. This feature will be greatly useful in your code review/reading purpose.

 

Feature 04 : Smart Code Completion

As previously said about dot character code completion list, below picture is what we get when we try to display all known methods and fields in PythonIDE class.

All class contents, sorted by most likely used identifiers

 

You can hit ENTER to choose the highlighted identifier (stars in the above case). Although you can use UP and DOWN key to scroll to the correct completion identifier (if for example what you really want is to use _repr__ method), in my opinion it will be ineffective. At least try to type several characters in the intended identifier (e.g. re to directly go to __repr__ method). It will gives you higher precision than to manually hit UP and DOWN arrow keys several times.

In retrospect, I remember the old days when there is no code completion feature in programmers IDE. And all that left to us is to have a reference guide standby nearby. It has important purpose actually. That is, programmers will be forced to read reference guide before/while coding, and memorize it...

 

Feature 05 : Walkthrough Debugging

When you doubted your code and want to step by step walk through to your code or simply want to inspect some variable values, you can do so by creating a debugging bookmark and run your application in debugging mode. The execution of your code will then halt at specified bookmark, which then you can inspect your code at that bookmarked state. Below is a given PyCharm state when debugging the main module. Notice how easy it is to inspect all variable values or watch just certain field values.

Debugging Python application using integrated PyCharm debugger

 

 

Feature 06 : Refactoring

The usual case to refactor code in Pycharm is to put the cursor in an identifier, right click it, go to refactor command item and choose all the available refactor features. For example if I want to rename the_best into mark_the_best, PyCharm will optionally display the following refactor code preview:

All the code changes that will be affected by refactor action

Just imagine if this variable is in use by 15 other modules, and you have to rename them manually. Phew..

Feature 07 : Integrated Console

When you run a Python module in PyCharm, it will run it in integrated console. There, you can inspect its console output or even terminate a long or hang process. This feature is inseparable feature in a complete Python IDE. If it is inexist, you will have to open a dedicated terminal/console and manually run Python interpreter to execute a given module. Not nice, eh?

Running a Python application in integrated terminal console

PyCharm also have integrated and interactive Python console, so you can run Python interpreter interactively like you always did in dedicated terminal / console. Below is what I meant by integrated and interactive Python console:

Interactive Python interpreter integrated in PyCharm

 

Conclusion

This first IDE review article that I presented to you, will act as the opening article for subsequent articles in this series. Any further articles will compare itself with this article. We will then will have a rather complete look of how to choose a particular IDE over another one. One thing to note is, those seven features discussed mainly serve as basic starting point to discuss IDE capabilities. There are of course unexplored features that maybe what you like most in an IDE.

But in the end, the IDE that you choose will depend greatly on your liking and personal preference. There is really nothing right or wrong with it. It simply your preference.

Stay tuned for my next articles!

 

 

Show more