lördag 30 april 2016

Python for Cognitive Scientists - Choosing your IDE

In my two previous posts I have shared some good learning resources for Python (here) and a short guide on why you should learn Python as a Cognitive Scientist (here). This post will touch on what I think is a very important tool when it comes to programming Python (but also for programming in any language); namely the Integrated Development Environment (IDE).

Although Python, as well as most programming languages, can be written using any text editor (e.g., Notepad in Windows or Gedit, Vim, Emacs, etc. in Linux) an IDE offers a little bit more (yes, both VIM and Emacs are very powerful but may have a steeper learning curve...). Below you can see a quote from the above linked Wikipedia article:
An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of a source code editor, build automation tools and a debugger. Most modern IDEs have intelligent code completion.
 I think the above quote illustrates pretty nicely why an IDE is a powerful and necessary tool for any programmer.

In this post I will consider three Python IDEs: Spyder, PyCharm, and Rodeo  (there are more. See this link, for example).

Spyder

Spyder is the IDE I have used most of my time and there are some aspects of it that I prefer before PyCharm and Rodeo.
[Spyder is] a powerful interactive development environment for the Python language with advanced editing, interactive testing, debugging and introspection features

Spyder uses iPython as its default command line environment (of course, you can choose to use the regular Python interpreter also). iPython comes with a lot of perks: such as that it has built-in support for Matplotlib. It also alleviates some of the issues with editing modules, since iPython supports auto-reloading modules.

In Spyder you can run a selected part of the script (F9) and a complete script file (F5) from within the editor.

It also offers deep introspection, highlights errors,  warnings, and opens up the docstring information when calling a function (i.e., iPython functionality). Errors and warnings are displayed on the left of the line number. Inspection is carried out by clicking and holding  over the error and warning icons. Highlighting is extremely helpful because when highlighting a variable all instances of it is also highligted; easily tracked, that is!

Furthermore, it has a very similar function to MATLAB (CTRL+D - Open definition feature in MATLAB): Spyder can find the file or line where a function was defined by holding CTRL and clicking the function name.
One really great feature of Spyder's interface is the object inspector. All objects that were created in the iPython console can be examined in the inspector. Note, you can also inspect any variable in the console; by typing the variable name and getting the output. Nice feature! It has been a while since I worked with MATLAB but as far as I remember MATLAB has a similar feature. I am, however, working quite a lot in RStudio which has a similar feature. For sure. I like PyCharm very much and it is free.

PyCharm

The next IDE is PyCharm. I have not worked that much in it and if you are a not a student (or an academic, I think) you may have to pay for the professional version of the IDE (Spyder is FREE!). I got myself a student license of the professional version some weeks ago and I start to like it!

PyCharm is one of the most popular Python IDEs. It’s has so many  features. For instance,  incredible code completion, code analysis,  andcode navigation. It also have very good Django, JavaScript, HTML, and CSS support, great debugger, to name a few!

PyCharm provides smart code completion, code inspections, on-the-fly error highlighting and quick-fixes, along with automated code refactorings and rich navigation capabilities.
 The interface of PyCharm can be customized. There are some themes that are dark (I need dark themes on my software) and you can make it look great.  As far as I understand when you execute your code (SHIFT-F10) your variables are not saved in the console. You can, however, select your code and right-click to choose "Execute selection in Console" (the console seems also to be iPython out-of-the box). I also like that it has good version control support (e.g., GitHub). That is great. I think I will continue using this and making it my number one IDE. Just need to find a way to have an object inspector or something similar. PyCharm supports plugins and there seems to be many (I use markdown many times so I installed a markdown plugin, for instance).  Maybe I will update this section when I have played around more with PyCharm.

Rodeo

I have not used Rodeo that much but I am going to mention it. Why? Well, I really like RStudio and Rodeo is basically RStudio for R. 
Rodeo is an installable app that runs natively (as a standalone application) on your desktop. It’s built with Electron, a cross-platform framework for building desktop apps with good ‘ole javascript and HTML.

Rodeo is light-weight. That is, there are now fancy features such as those in Spyder or PyCharm. The interface is nice and clean. You have a script part, an iPython console, an Environment (object inspector in Spyder), and areas for plots, directories, and so on. Rodeo may be for the RStudio users but if you looking for a lot of features such as does in RStudio; go for Spyder or PyCharm. Give it a try!

To summarize, I would like something that is a mix between Spyder and PyCharm. I like these two IDEs and I think you can use either one of them. If you are coming from MATLAB maybe Spyder is more familiar and the learning curve will be less steep compared to PyCharm. I think. however, that in the end PyCharm is the most powerful one.

Inga kommentarer:

Skicka en kommentar