Tom Pierce's Blog : Let the geek times roll.
Updated: 6/20/04; 3:16:27 PM.

 

Subscribe to "Tom Pierce's Blog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Monday, August 4, 2003

I'm up much too late, but I've found something that you are really going to like. It's called MyRadio. At a minimum, it's a tool that allows you to categorize your News aggregator feeds into different pages. That way you can browse only entries from the feeds you specify to show on that page. DADDY LIKE! I've been playing with it for about an hour. I think its going to make my aggregator alot more manageable. Go get it.


11:35:08 PM    comment []

I've been coding in Python again in my spare time. I miss Lisp a little, but Python is fun because you get alot for free with the huge module library in the base distribution. I still have a long way to go with on the Lisp learning curve, so I'll be back to it one day.

One of the things that Lisp and Python have in common is that functions are fist class citizens along with classes. That means that you can easily mix and match functional, imperative, and object oriented programming styles. This enables some really expressive and powerful programming experiences.

However, all that flexibility can be a bit confusing to me. I recently struggled with the question of when to use a class and when to just use a function nested in a module. After reading through other people's code, wasting alot of time (and getting nowhere) searching the Internet, and talking to peers, I think I've finally got a handle on it. Even if it's not the answer, I'm going with it.

I believe that most of my Python programming should be OO. OO offers and easy way to separate concerns and map concepts to software. However, there are times when OO seems strained to me. In those cases, I'll use module level functions.

An example that comes readily to mind is persisting objects to a data store. Should your classes have methods that save and load themselves? If they do, then the load method is really strained because it has to populate an instance of the class with data. So, that means you instantiate the object and THEN call load. Doesn't this seem wrong? Shouldn't the instance be instantiated by loading the data?

Perhaps you should make a new class that encapsulates the persistence mechanism for the other class. You could have a data store manager that persists your objects. When the data store manager received a load request, it would instantiate the object with the data from the data store and return it to the requester. This seems cleaner. However, the data store manager class doesn't really encapsulate any instance data. So, it's just a bag of methods. Mmm... strained?

This is an example of where I would use a couple of module level functions. One to store the classes that are part of the module and one to load them. This allows me to separate out a behavior that is not really an object action, but is an action on the object. This makes the solution very clean because, to me, there is much less strain on trying to force object interactions.

Whew! Inner conflict resolved. Breathe out... let the code flow...


9:49:09 AM    comment []

© Copyright 2004 Tom Pierce.



Click here to visit the Radio UserLand website.

 


August 2003
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Jul   Sep

Search

[sgl dagger]
How this works

Emacs Sources
 tsql-indent.el
 user-add-sql-folding-marks
 remove-line-boundary-in-region
 convert-camel-to-underscore

My Subscriptions
 Funny
 KM