Saturday, August 22, 2009

eclipse+ for python (pydev)

This semester i have taken a course in particle methods for fluid flow, whose instructor is a big fan of python, and has written large applications in python. So most of my classmates have indeed chosen to use python for the assignments. As they mostly use MS Windows, it is easier to install some python bundle such as EPD or python(x,y). I'd like to recommend python(x,y) for windows users. Though i myself don't use windows (i use Fedora 11 x64 fyi), i did try python(x,y) at my home this summer. (I know epd since much before that). The only reason for this is that python(x,y) includes eclipse with pydev, and it make much more sense to use an ide in the learning phase than using the silly notepad on windows (or any other advanced notepad). For those who are beginning afresh, here are a few clues why you should use an ide.

  • Code formatting is easily performed in pydev. Try commenting out a 20 line function your editor. (pydev hint: source->comment menu)
  • Syntax checking: You don't need to run you module to find out that you missed a semicolon after an if statement, the annotations in the editor will help you. Many more annotations to guide you to catch errors.
  • Code completion: Do you remember if the function inverse tan (arc tan) in math is called arctan or atan? (pydev hint: try math. and check if its arctan or atan)
    Do you remember the arguments of the asarray function of numpy or whether it makes a copy of the array? (pydev hint: check the documentation by hovering the mouse on the function)
  • Refactoring: Though pydev does not have the awsome refactoring capabilities of the statically typed languages (its difficult in python) it can still rename attributes and methods across modules with sufficient accuracy.
  • Templates: Do you find yourself bored typing the bolierplate code for classes or unittests or new modules? The templates are you friends. Example the new pydev module dialog box will help you easily create boilerplate code for classes and unittests. Typing 'main' in the editor will complete it to "if __name__ == '__main__':" block
  • Debugger: This cannot be emphasised enough. If you are not using a debugger, you have not been coding enough. It simplifies the task of locating the errors in a program. You can pause, continue, step through the code and check the values of any variable defined in the program. You can create conditional breakpoints and watch arbitrary expressions. Hovering over any attribute displays its value, selecting an expression displays its values. You can also switch to any frame. The debugger is probably the biggest benefit of using an ide like pydev.
Ok so all this was just to make programming beginners have a look at pydev ide. If you find anything unclear or want a short guide to do something please leave your comments and i'll try to help if possible.
In future i'd like to post a short note on beginners use of pydev and the common tasks you need to know. Tell me if you'd like to have it soon rather than later

No comments:

Post a Comment