Coding: Ruby GUIs, Python, and how to make VIM better for coding

Lately I’ve been checking out Python, partly out of curiosity and partly because I’ve recently been working on a GUI application in Ruby, and to be honest, the GUI tool kits available for Ruby aren’t exactly impressive. WxRuby, which I ended up using, is lacking in documentation and even though it claims to have native look on all platforms, it doesn’t look even remotely native on Windows. No biggie really, but still a minor annoyance. It’s also plagued by a lot of half-implemented and undocumented features, such as the Wx::GridCellEditor, which should allow me to build custom editors for cells in a Wx::Grid, but in reality it allows me to do nothing because of a bug that no one has cared enough to fix. In retrospect I probably should have gone with QT, but hindsight is 20/20 and I’m not going to switch now that I’m nearly done. I actually don’t even need a cross-platform GUI tool kit — a Windows one will suffice — but the state of GUI tool kits for Ruby is so poor that the half-baked cross-platform tool kits are actually the most complete.

So, back to Python. I know there’s an on-going holy war between Python and Ruby, but here’s the exact number of fucks I give about that: 0.00. I’m at the point where I’m thinking “whatever floats your boat”, and Ruby certainly doesn’t float my boat with regards to GUI tool kits, so why not give Python a go? Python and Ruby aren’t that different. Sure, syntax-wise they are, but the basic philosophies of the languages are pretty much the same. I could have gone with C# or even C++ instead, but both of those are very unfamiliar to me and far more removed from the languages I already know.

Python comes with a built-in IDE called IDLE. It’s a pretty decent piece of work done in Python and Tk, but I’m at a point where I can’t use a “normal” text-editor anymore. I constantly hit ‘esc’ followed by ‘dd’ to delete a line, I hit ‘shift-V’ to select multiple lines and try to indent them with ‘>>’, and, without exception, I type ‘:w<enter>’ whenever I want to save the file. In the end, using a normal text-editor (where you save with ‘ctrl-s’, select with the mouse or with ‘shift+<arrow keys>’) actually causes me more problems than just using VIM. While trying out IDLE, I found that I really liked how I could just hit ‘F5′ to run the script (or module), unfortunately VIM doesn’t offer me that. However, VIM being VIM, there is of course a way to set up such a thing. Here’s what I did to my ~/.vimrc in order to emulate IDLE (and other IDEs’) ‘run’ binding:

autocmd BufRead,BufNewFile *.{rb,rbw} map E :!ruby %<CR>
autocmd BufRead,BufNewFile *.{py,pyw,pyc,pyo} map E :!python %<CR>

With this I simply hit ‘shift-e’ in command mode to execute the current file, and depending on the file’s extension (.rb, .rbw, .py, pyw, .pyc or .pyo) it will select the correct interpreter. In GVIM on Windows it will open a Command Prompt and run the interpreter + script in that, while in VIM in a terminal on e.g. Linux it will suspend VIM, open a new shell in the same terminal and execute the script.

Now, I haven’t gotten very far with Python yet, but so far I like it even though I’m still at the point where I’m basically thinking in Ruby code and trying to translate it to Python.

About Anders K. Madsen

Creator and administrator of Lillesvin Networks. Linguist (Master's degree at the University of Aarhus), web developer, Ruby programmer, author of phpCF and amateur musician. Catch me on mail: madsen@lillesvin.net, Twitter: @lillesvin, or Google Talk: lillesvin@gmail.com, if you want to get in touch.
This entry was posted in Computers, Linux, MacOS X, Programming, Python, Rant, Ruby, Windows. Bookmark the permalink.

2 Responses to Coding: Ruby GUIs, Python, and how to make VIM better for coding

  1. Steffen says:

    Interesting. I never really understood the power of dedicated IDEs over a general powerful flexible editor.

    What are you making?

    • Mostly I think it’s just a convenience. You get a compiler, debugger, editor, file manager, tab completion of function/class names, built-in documentation, etc. All in one neat package. However, many IDEs are primarily built for one language, so if you switch language, you’re likely to have to switch IDE too. There are of course exceptions — e.g. Eclipse and Visual Studio. I can understand why people who work primarily in one language use an IDE. I tried out Code::Blocks for C++, but I ended up in VIM again after a few hours. IDEs are cool, but they aren’t for me.

      The Ruby project was a database interface I was doing for a professor in Aarhus to help him organize and search data collected in the field.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>