Archive for August, 2006

Tuesday, August 29th, 2006

Covariance vs. contravariance

Handy covariance & contravariance definition, courtesy of this Wikipedia page.
As used in computer science, in particular in object oriented programming:

Covariance means that the type of arguments, return values, or exceptions of overriding methods can be subtypes of the original types.
Contravariance means that the type of arguments, return values, or exceptions of overriding methods can be […]

No Comments » - Posted in Programming by dkaz

Tuesday, August 29th, 2006

Python list merging

One of my Django views required a two-column display, which required simultaneous iteration over two lists.
I didn’t find a clean way to handle this in Django, so I ended up creating a compound list of pairs to back the display.
Here’s my Python code to merge N lists into a list of lists with N entries. […]

No Comments » - Posted in Python, Programming by dkaz

Monday, August 28th, 2006

Smalltalk Syntax One-Pager

For those of us that have always been fascinated with Smalltalk (but never managed to actually try it), Ralph Johnson has a great one-pager on Smalltalk’s syntax on the c2 wki.

Everything in Smalltalk is an object, and all computation is performed by sending messages to objects. Each object is an instance of a class. All […]

No Comments » - Posted in Smalltalk, Programming by dkaz

Friday, August 18th, 2006

Spring Recipe #2: Spring-backed Factory

If you would like Spring to do the heavy-lifting for your Factory class, you can simply inject ApplicationContext into your factory and delegate your create() methods to Spring’s getBean() methods.

public class YourServiceFactory implements ApplicationContextAware {
private ApplicationContext context;

public void setApplicationContext(ApplicationContext context) {
[…]

1 Comment » - Posted in Java, Programming by dkaz

Friday, August 18th, 2006

kwargs - Python keyword arguments

One of the more unique features of Python is the ability to collect all excess parameters passed to a method in a tuple (positional arguments) or a dictionary (keyword arguments).
This last method parameter often follows the “**kwargs” convention in the code I’ve run into.
When a final formal parameter of the form **name is present, it […]

1 Comment » - Posted in Python, Programming by dkaz

Thursday, August 10th, 2006

Spring Recipe #1: Validating setter injected fields

Here’s a simple recipe I’ve used over and over (wherever auto-wiring constructors was inappropriate). Validating at container startup time is certainly better than relying on NPEs at runtime.

import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

public class FooService implements InitializingBean {
private Dependency dependency;

public void afterPropertiesSet() throws IllegalArgumentException {
[…]

4 Comments » - Posted in Java, Programming by dkaz

Thursday, August 10th, 2006

Hit n’ Run Micromanagement

My favorite fragment of Joel’s post on “Command and Control” management style:
In software development teams everybody is working on something else, so attempts to micromanage turn into hit and run micromanagement. That’s where you micromanage one developer in a spurt of activity and then suddenly disappear from that developer’s life for a couple of weeks […]

No Comments » - Posted in Programming by dkaz

Wednesday, August 9th, 2006

Econ 101 Management (Gaming the System)

Joel has a brilliant post about brainless management method he dubs “Econ 101 Management”. Check it out here.
These two paragraphs sum it up best for me:
When you use Econ 101 management, you’re encouraging developers to game the system.
Suppose you decide to pay a bonus to the developer with the fewest bugs. Now every time a […]

No Comments » - Posted in Programming by dkaz

Wednesday, August 2nd, 2006

BBCode parsing in Python

Looking for a decent Python parser for BBCode?
Luke Plant’s bbcode.py is in Zyon’s Subversion depot and seems do the trick.
BBCode is an abbreviation for Bulletin Board Code, the markup language used to format posts in many message boards. The available tags are usually indicated by rectangular brackets surrounding a keyword, and they are parsed by […]

No Comments » - Posted in Python, Programming by dkaz