Ok, I’m fed up. Here’s the first of a series of Pearls from the Plone Source. Call it The Plone WTF if you like.
Here goes, a loop that does nothing. Notice the ‘locking_info’ adapter is fetched outside the for loop:
for action in workflowActions:
if action[‘category’] != ‘workflow’:
continuelocking_info = queryMultiAdapter((context, request), name=’plone_lock_info’)
And then a few lines below, the same loop repeats, this time it is doing something. The ‘actionUrl’ variable is assigned inside the for loop:
if locking_info and locking_info.is_locked_for_current_user():
return []for action in workflowActions:
if action[‘category’] != ‘workflow’:
continue
actionUrl = action[‘url’]
Sad. I don’t think anyone is really reviewing this code….
Heh, that’s quite bad. :) Obviously some bad merge/copy-and-paste stuff’s happened here.
No-one’s perfect, though. I’m sure your code sometimes contains weird errors and omissions too.
Then again, you could just fix it.
Fix it. That’s why we have unit tests and let people have commit access. :)
Any code base of Plone’s and Zope’s size will have accidents like this.
Unit tests aren’t an excuse for crappy code; the Plone source code is an inspiration for newbies as well as seasoned developers and it’s imperative that we keep a high standard.
–From the Creators of a now infamous IRC bot.