Archive for the ‘Object Oriented Design’ Category

More Anti Patterns

June 22, 2007

Scott Berkun and commenters summed up undesirable methodologies like Development By Denial, Never Ending Story Development and Learned Helplessness Development.

Although I believe it’s best to focus on the positive, by visualizing how things should be done, recognizing failing strategies can be fun. And instructive.

Mr. Berkun happens to be the author of The art of project management and The myths of innovation. Both on my wishlist.

Via Vattekkat Satheesh Babu on Planet Python.

Lack of competence

April 5, 2007

In the Names section of JavaScript code conventions, mister Crockford advocates not using the underscore _ to indicate a private attribute. After making his case, he subtly adds:

Avoid conventions that demonstrate a lack of competence.

– Douglas Crockford in Code Conventions for the JavaScript Programming Language

I like it.

Reading his JavaScript site is worth every minute. Provided you’re interested :)

Object Oriented JavaScript the prototype way

March 16, 2007

Since I rediscoved JavaScript, I have made some serious efforts programming single page fun applications in an OO fashion. Nevermind reinventing Todo lists and of course I want my own mashup!

Somehow, I kept bumping my head into the prototype way of OO in JS. For example, losing the this reference to my instance when calling a prototyped method of my own class.

If you recognize my experience, read Object-oriented JavaScript by Greg Brown on xml.com. It sets your OO mind right in 10 minutes.

See also Douglas Crockford’s JavaScript page (from the comments on xml.com)

You can become my colleague

February 28, 2007

sfk logoThe company I work for (SFK) is looking for a full-time Data Warehouse Developer (m/f).

You should know how to program OO, preferably in Python. Be keen on Linux and open source in general. Know how to handle large databases. Your dutch should be fluent (sorry about that).

They’re nice to me.

What’s the catch? You’ll end up working closely with me :)

Five essential phone-screen questions

January 4, 2007

For just five interview questions, it surely ended up as a long read. Nevertheless worth the read:

The Five Essential Phone-Screen Questions — Steve Yegge

I just might translate some of his examples to Python:

Example 1: Write a function to reverse a string

def reverse(text):
....result = list(text)
....return ''.join(result[::-1]) 

or, just

def reverse(text):
....return text[::-1]

Example 2: Write function to compute Nth fibonacci number

def fib(n):
...."""Calculate fibonacci value for given n
....Doctests:
....>>> [fib(i) for i in xrange(0, 10)
....[0, 1, 1, 2, 3, 5, 8, 12, 21, 34, 55]
...."""
....if n 

Example 3: Print out the grade-school multiplication table up to 12x12

def multiplication_table(n):
...."""Generate an n*n multiplication table
....>>> len(multiplication_table(10))
....10
....>>> len(multiplication_table(5)[0])
....5
...."""
....# Create matrix
....table = [[x*y for x in xrange(1, n+1)] for y in xrange(1, n+1)]
....return table

def print_matrix(matrix):
...."""Expects a list of lists """
....for row in matrix:
....|...print "%4d" * len(row) % tuple(row)

if __name__ == "__main__":
...."""Run actual program code """
....print_matrix(multiplication_table(12))

Example 4: Write a function that sums up integers from a text file, one int per line

def sum_file(filename):
...."""TODO: catch exceptions """
....fp = file(filename)
....try:
....|...numbers = [int(line.strip()) for line in fp]
....finally:
....|...fp.close()
....return sum(numbers)

Example 5: Write function to print the odd numbers from 1 to 99

def print_odds():
....for i in xrange(0, 100, 2):
....|...print i 

Example 6: Find the largest int value in an int array

def largest(sequence):
...."""Find the largest occurrence in a sequence ('array')
....>>> largest([0])
....0
....>>> largest(range(100))
....99
....>>> largest([1, 0, -1])
....1
...."""
....return max(sequence)

Example 7: Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string

def format_rgb(red, green, blue):
...."""Convert integer RGB to hex RGB string
....
....>>> format_rgb(0, 0, 0)
....'000000'
....>>> format_rgb(255, 0, 0)
....'FF0000'
....>>> format_rgb(0, 255, 0)
....'00FF00'
....>>> format_rgb(0, 0, 255)
....'0000FF'
....>>> format_rgb(255, 255, 255)
....'FFFFFF'
...."""
....return "%02X%02X%02X" % (red, green, blue)

Test solutions:

def _test():
...."""Run tests on functions in module """
....import doctest
....doctest.testmod()

Please ignore points and pipes. WordPress can't handle code layout well. Python is white-space sensitive. This is the best I could come up with.

Class diagrams with StarUML

October 24, 2006

staruml logoWe’re currently having OO workshops at work. When designing class diagrams, we use StarUML. I’m very content with this product. It’s fast and fairly easy to use.

See their site for info and downloads.

No support for generating Python code, yet.

Humour: Periodic Table of Design Patterns

September 20, 2006

design pattern periodic table

Found at Huston Design Patterns

What is wrong with the MVCs I see?

January 11, 2006

Some minutes hours ago, in a phone conversation with a dear friend, who also happens to be a decent programmer, I expressed my feeling about the Model View Controller pattern Rails is claiming to adhere to. Something feels wrong. And not only MVC in Rails.

Say I have a bunch of recipes, all nicely assigned to a smaller subset of categories. (Does that sound familiar?)
In Rails, if I would want to show all recipes on the recipe index page.

My controller class would look like this:
class RecipeController < ApplicationController
model(:recipe)

def index()
@recipes = Recipe.find_all()
end
end

With an accompanying model:
class Recipe < ActiveRecord::Base
belongs_to(:category)
end

What disturbs me is the find_all() method in Recipe.
Yes, I understand that Recipe subclasses ActiveRecord. But I would not expect the Recipe class to know about all its kin:


Richard.find_all()
paraphrased
"Say Richard, pass me a reference to all people on earth, will you?"

Would it make sense to have some other class that would know about Products and supply the controller with data?

Another thing that bothers me is the php’ish way of having Ruby code in templates.

<% @recipes.each do |recipe| %>
<%= recipe.name %>
<% end %>

Aren’t that model instances we’re massaging in our view? Doesn’t that make our view partly a controller too?

Looking for answers I found an in-depth article (MVC and web apps: oil and water) by Harry Fuecks on MVC and its applicability in web applications. Take your time to read the articles he links to too.

Please let me know what you think.

Pay attention. I’m not bashing Rails. Beautiful apps have been written in that framework. I’m a paying Basecamp user, for example.

I’m just searching for the truth.
the truth is out there
And the truth is out there.

Antipasta versus Pasta

January 10, 2006

A Pattern is a form of solution intended to address a problem. The problem for Pattern readers has always been to identify when and how a Pattern should be used.

An AntiPattern is defined as “a commonly occurring solution to a problem that generates decidedly negative consequences;”
in other words, an AntiPattern is generally a commonly repeated practice in industry that is flawed in some manner and causes symptoms that are more undesirable than whatever positive results were sought.

AntiPatterns and Patterns

Found on The Servlet Framework Antipattern

antipasta antipattern

Design Patterns Club The Hague

December 28, 2005

Is anyone from The Hague interested in forming a “Design Patterns Club”? Like a local Special Interest Group.

Zijn er mensen uit Den Haag ge├»nteresseerd in het vormen van een “Design Patterns Club”?


Follow

Get every new post delivered to your Inbox.