Sunday, November 21, 2010

PyCharm, Charming Indeed

At my day job, I use Eclipse for writing Java. On other projects, well, it's been complicated. At home I prefer Python and Django over Java and JSF.

In the past, I've cycled between Vim, Eclipse and NetBeans.

Pydev does a great job of supporting Python in Eclipse, but Eclipse itself can be aggravating at times. Firstly, I'm using it on a Macbook, and it eats battery. Secondly, I've had mixed results setting up the mercurial plugin. It had been a while since I had tried (I seem to remember things basically working last time) but on my most recent attempt at Eclipse, I needed to sign-up for an account at javaforge.com to install the plugin. "Annoying," I thought, "but at least it's free." Well, after signing up, Eclipse wouldn't let me agree to the license. I suppose I could have kept fighting with it, but Eclipse starts to feel like paperwork if you have to work too much at configuring it (I hate paperwork). The dialogs for installing/removing/updating plug-ins don't seem like they're well thought-out.

NetBeans, has support for Mercurial that was either easy to setup or out-of-the-box (I can't remember needing to install it, but I may be wrong). I really like how NetBeans highlights uncommitted changes on the left of the editor without doing anything (no need to do a Team > Compare ... as in Eclipse). Very nice. NetBeans also has a much nicer plug-in installation process. I had an OK experience with NetBeans while dabbling with Groovy & Grails earlier this year (would have enjoyed it more if code-completion wasn't abysmally slow) and considered giving NetBeans a try for Python. Unfortunately, it seems that the project to support Python in NetBeans has stalled or died.

These experiences being par for the course, mostly I've been hacking away using Vim. I've learned to really enjoy Ctrl+N (complete word) when you've got your whole project open in buffers. Typing ":b part-of-some-filename<tab>" isn't a bad way to navigate. Setting up indent-based folds and using zM (max folds) and zR (no folds) is a workable substitute for Eclipse's outline. Battery life is fantastic, and my fingers love Vim (ddp, %s/blah/what/, :w).

Still, I missed having something underline my mistakes, having a nice outline of the code, and having side-by-side diffs like those I get with Eclipse at work (where CVS is used, hence side-stepping plug-ins).

I decided to give PyCharm a try today. I'm pretty impressed so far.

PyCharm has a "Power Save Mode", and after watching my battery life while working un-plugged for nearly an hour, it seems to work well.

CVS, Git, Mercurial and Subversion are supported out of the box. Uncommitted changes are highlighted on the left of the editor, just like NetBeans.

The editor doesn't seem to have block selection like Vim. I've yet to find a way to change the color scheme. I miss Vim's key bindings, but it's early.

Copying and pasting code from a web2py project I'm rewriting using Django gave me a little trouble. PyCharm kept nagging me to import web2py symbols that I was busy replacing with the appropriate Django equivalents. It didn't actually interrupt me, I just kept seeing this little tool-tip giving me the key-combo to do an import (useful when I've needed it, but annoying in this case). I can probably switch this off.

Overall, I'd say JetBrains has a pretty good chance of getting some money from me by the time my trial runs out.

Tuesday, September 7, 2010

Cappuccino Book on the Way

I was scanning some groups and noticed this thread on the objective-j list: http://bit.ly/c7E3wX.

Looks like the Pragmatic Programmers will be publishing a book on the Cappuccino framework! This is pretty cool. I'll have to get a copy when it comes out...

Thursday, April 15, 2010

Fixing a GORM/HQL Group By Clause

I was just trying to use a "group by" clause with some Grails domain classes in HQL and ran across the following cryptic message:
"Not in aggregate function or group by clause."

My models looked a little like this:

class Account {
  String name
  static hasMany = [entries:Entry]
}

class Entry {
  Date entryDate
  double amount
  static belongsTo = [account:Account]
}

I wanted to get a balance of all the accounts and ran an HQL query something like this:

def results = Entry.executeQuery(
  'select ent.account, sum(ent.amount) ' +
  'from Entry as ent group by ent.account')

I found that the reason for the failure seems to be that Hibernate adds all the other fields of Account to the select clause of the SQL under the hood. Changing the HQL to this, solved my problem:

def results = Entry.executeQuery(
  'select ent.account.id, sum(ent.amount) ' +
  'from Entry as ent group by ent.account')

Thursday, February 11, 2010

On Web2py and Having Templates

I've been writing an app for some friends using Web2py.

I really like how the generic views let you try out your controllers without worrying about the details of what variables you will or won't pass to the view. Lots of diagnostics are given in the generic views, and you can see how your forms render. Paired with web2py's automatic database creation and modification, you can iterate really quickly with this framework.

I've worked with some ORMs and ran into limitations when you try and do things that would normally require a nested SELECT in SQL. Web2py's DAL (database abstraction layer) can do nested selects relatively easily. The DAL is much more relational than object oriented.

In any event, implementing new features in a web2py app is like eating potato chips! It's hard to stop.

I've toyed with Grails a bit and similarly enjoyed the way the scaffolding makes it easy to move fast. The generic views in web2py also help one avoid that "blank canvas" feel.

I've been itching to do some more work with Django, and I think I'm going to have to put together my own Django skeleton project like they did at the Washington Times (although I'm not sure if I need to go as deep as getting into virtualenv just yet, just some templates and config options I habitually set).