lørdag den 23. juni 2007

Python - first impression

I've tried out some Python now and it is really intriguing.

One of the first thing you meet is the interactive interpreter. Now, I've come across similar things before, like a javascript shell or even, well, an OS shell.
But in Python this is really how everything works.

Atop of the very interactive programming possibilities, the language is very intuitive.
Like this little snippet, which is how I'd like to write boolean statements, but can't in java for an example.

>>> x = 10
>>> if 0 < x <= 10:
... print "true"

In Python, list is a built-in type. If I want to perform a common action like arranging two lists into a set, I do not have to bother with much complexity. As shown.

>>> listKey = range(5,15)
>>> listValue = range(10)
>>> zip(listKey,listValue)
[(5, 0), (6, 1), (7, 2), (8, 3), (9, 4), (10, 5), (11, 6), (12, 7), (13, 8), (14
, 9)]

Not quite clear from the code, but the printout is a list of 'tupple' all of which are built-in types.

I will try to implement the 'stamp' program, for seeing how little complexity I will have to deal with.

Coming up; "The Stamp/Python tutorial"


I've heard good things about Python, so I decided to watch a Tech Talk about it.

Basically the ideas are as follows:
1. trust the programmer
2. don't prevent the programmer from doing what needs to be done
3. keep the language small and simple
4. provide only 1 way of doing a specific task

So I asked myself how would I expect to use Python.
Well instead of using my currently favoured languages Java & C#, I would use the language when working with people I totally trust as good programmers with the right skills and same perspective as I. People the speak the same language.. aye.

Some of the differences lie in 'Trust the programmer', if the language has to trust the programmer, then programmers must trust each other. For an example in Python you do not use 'private' annotation or other permissive annotations. This means a programmer of one class cannot totally ensure correct use of the class from another programmer.

If I were to write a program that will be used in a big corporation, where there are programmers of varying skills I would probably like to encapsulate some properties, for them not to be bastardized out of scope and loosing complete track of its usage. The debugging nightmare. To some extend this is argumented against by the speaker in the Tech Talk. He states 'You don't want your code to be misued by fools, but as we all know fools can be ingenious'. What he means is that they will find some other workaround possible obscuring the usage even further.

Several other benefits of Python are passing of functions, usage of templates, multiple inheritance(careful though!) and more.

I will try it out and update with a little example here.

søndag den 17. juni 2007

Sunday java code guidelines

Avoid using static references.

You are making the code dependent on implementation of a function. This does not scale well. It puts your program at risk because a reference somewhere else might require the implementation to change, without the ability to abstract it by polymorphism.

You can use dependency injection to achieve this.. see Guice f.ex.

Use the final keyword as much as possible.

this reduces the chance that you will change the state of an object inadvertently, greatly stabilizing your code as the program evolves and become larger.


Wow this is a great tool.

A few first impressions:
its sleek and the interface is really nice. The opacity lets me focus on the content while navigating. This has been seen in many a flash webpage. Now I can use it anywhere.

Here's the tasks it's already helping me with:
1. navigating to the correct window
2. opening programs

Because I usually hav a lot of windows open I tend to want to close when I have too many programs open. Which is actually a burden.

When I have to launch some program I don't usually use I have to go through the bookmarks in start-up, which can be somewhat frustrating.

Bookmarks in the browser can also be avoided. Really nice. I'll be updating about this.

Human Computer Interface

I watched this really cool 'talk' video about a way to improve accessing functionality on your computer.

Among other things it advocates the use of services, and I now understand the power of services. Applications are restricting use of their functionality by not providing it as a service. I think in this regard that the OSGI framework used for among other things RCP, is a good approximation.

Having functionality segregated into reusable parts is an idea that has existed for a long time. Think toolkits. But these are so closed in and welldefined that they don't leverage creativity.

I'm going to try out the enzo humanized interface, it looks really good!

Second Life

Just entered Second Life and watched a video about it.

I must admit its sounds intriguing.

I dont' want to describe it here, you can to the website and read about it. What is interesting is that soon it will be able to feed xml and html into second life.

That will be amazing.

Everything is Miscellanous

This is really a good philosophical 'Talk', I'll give it a brief thinking through.

In contructing computer systems I have discovered that categorization itself can be a constriction, that ultimately can lead to severe problems.

For an example in java you have inheritance. As a rule in new generations of development processes everything should be refactorable with the least amount of effort. How can you then defend defining some objects parents, from which all attributes are set in stone. This really emphasizes the problem of the fragile base class. I have seen this sometimes and I have'nt really made any really programmed on any system of a size where changing the baseclass would cost more than a few days of work.

So the definition of anything by it's mere name or conception is fundamnetally flawed in programming. Instead it should be defined by its behaviour. This is generally enforced in the java language, so I can't help wonder why the Class inheritance construct is still is use.

In short, never think you have completely defined anything in you domain. Use interfaces always. Don't extend anything! Always assume that your definition of something will change.

Currently I'm tackling problems with an old system, which really was not designed for the features it now supports. One problem is that in the system a 'Product' is very well defined. So well defined, that changing its structure is basically a rewrite. The product should instead have been defined through interfaces. So a function changing a products price would use it's interface to that extent. A 'pricable' interface perhaps. Define it by behaviour!

Human Computation

In this 'Talk' Louis unveils to the viewer his actually implemented tools for what I might call 'Making work fun'. Something I recently experimented with in using elements of a game in combination with an actual workproces.

In my current employment I have this task of optimizing the flow of a editing images for real estate sales.

How can I make this process feel like a game? - well first you'd have to watch the 'talk' : http://video.google.com/videoplay?docid=-8246463980976635143&q=tech+talk&total=878&start=0&num=10&so=0&type=search&plindex=0

I think I would first try to apply one of the game structures.. maybe the 'synchronous' approach. Have 1 worker edit the actual image and another verify it. This is how the process actual is implemented already. A worker edits the image to fulfill some specifications. Say make the sky appear blue, remove anything unwanted in the picture and so on. Then the QA guy looks at the image and comes with corrections of sorts.

So, the worker gets paid for any image that can be used. He gets rewarded for some effort, with is a common gaming element. Although, how do we make this achievement more interactive and most important FASTER.

Well, one thing we could do is have the QA and the worker, player 1 & 2 if you will, work synchronously. But having 2 employees for a task that can be solved by just 1 is very expensive, therefore we would rather eliminate the QA as a postion and give that task to each of the workers.

By eliminating the QA per se, we can have double the output, but this puts strain on the actual control of the work, because the workers are on the same level and authority is gone. Instead we HAVE to rely on the workers not to 'cheat'. Well this is not a big problem in this case, since in the end, the customers can really easily fulfill the QA task, we just have to have a means of backtracking to the workers involved.

I have to find a concrete implementation of something similar, the ESP game is too simple to use as a model, not that it's no ingenious, it HAS to be simple, because any 1 should be able to do it.

Now we have requirements for the players, that are:
1. has to have skills with photoediting
2. can read/write english and communicate with her peer

In a scenario, the two workers would work on 1 input each parralel, but the tasks would not take an eqaul amount of time to complete, so there's our first problem to be solved. How do we align the proces of each worker and make sure that QA becomes an interactive/dynamic task done by the workers in one effort.

I'll have to research this some more.

Tech Talks

I've just started discovering the rich world of online seminars, when I was introduced to google tech talks.

I must admit, the guys doing these seminars are great inspiration to me.

One thing I started out with was trying to watch seminars that I could use for something. So I started seeing some seminars on test-first development for an example. Quickly though, I ran out of interesting seminars on that topic, but still wanted more.

My couriousity was tingled by the great seminar people who know how to motivate for any lecture. Though a possiblity for gaining knowledge on topics out of my interest, I tried out some new ones.

In this blog I will probably comment on most of them.

søndag den 10. juni 2007

Getters and Setters are evil

In my current employment I am a part of a project that is founding a new system, root up.

What I keep seeing myself doing is adding getters and setters allover my code, but only inside well-defined components. I ask you though, how well-defined must a component be to consider encupsulation for properties?

I have come to the conclusion, that each and every class is a component in it's own right.. so I should drop getters and setter entirely. Ouch, some refactoring to be done.. hmm how to accomplish it, I wonder.

Consider the case of Logging in. The usual way to go about this is to have a user obect compared to some stored data, and then doing some behind the scenes bullshit of connecting to this, and refering to that. What you essentially end up with is a function, like this

boolean login(String username, String password);

and it is placed somewhere on your mother of an application runnable.

void run(){
//Hack info from the User and crack away
loginInfo = gatherLoginInfo();
login(loginInfo.name, loginInfo.pass);

That doesn't seem at all like OO programming though. One would expect this method to be a method of a User. Then the application would ask the user to log themselves in. So instead the implementation would be

void login();

void run(){
//we have a new User here
User user = new User();
//user, could you please log ourself in?

Seems more accurately OO-like... right?

Some good reading:

Comments can be bad and clutter code

Oh my heart bleeds for I have been deceived by my foulishness.
What I usually tell people when I can't understand their code is:
"Write lots of comments"

Which would solve the problem at hand, but maybe the problem is not my lack of insight, I should be able to comprehend most code, shouldn't I?

So instead lets take an example of some code I might misunderstand, an rewrite it so I could. I don't understand this(code segment randomly picked from http://www.google.com/codesearch):
You can look through it, or just press 'Page Down', to skip to the point.. it's hilaroius, trust me ^^

public static void main(String[] args) {
final int NUM_MSGS;
Connection connection = null;

if ((args.length < 1) || (args.length > 2)) {
"Program takes one or two arguments: "
+ " []");

String destType = args[0];
System.out.println("Destination type is " + destType);

if (!(destType.equals("queue") || destType.equals("topic"))) {
System.err.println("Argument must be \"queue\" or " + "\"topic\"");

if (args.length == 2) {
NUM_MSGS = (new Integer(args[1])).intValue();
} else {

Destination dest = null;

try {
if (destType.equals("queue")) {
dest = (Destination) queue;
} else {
dest = (Destination) topic;
} catch (Exception e) {
System.err.println("Error setting destination: " + e.toString());

try {
connection = connectionFactory.createConnection();

Session session = connection.createSession(

MessageProducer producer = session.createProducer(dest);
TextMessage message = session.createTextMessage();

for (int i = 0; i < NUM_MSGS; i++) {
message.setText("This is message " + (i + 1));
System.out.println("Sending message: " + message.getText());

} catch (JMSException e) {
System.err.println("Exception occurred: " + e.toString());
} finally {
if (connection != null) {
try {
} catch (JMSException e) {

- okay I'm dumb I know, I know. In this case, the code was actually substanially commented, I just left out the comments, because then I would have a case. I found that several lines of comment could be left out, just be refining the code a bit. So I put away the code in little neat sections, and then embraced a form of procedural glamour. I came up with this:

public static void main(String[] args) {

Now I understand what it does.. hooray for me! And no time wasted for comments.

Trailing through the Internet with the great firefox add-on StumbleUpon.. I actually stumbled upon something extremely interesting:


It is nice to hear what seasoned programmers think of advice given to me by various colleagues.

Titles in software development

Why are so many titles popping up everywhere?
Programmer is just not good enough for us anymore.
How about 'Software Developer'?
'Software Architect'
'Software Engineer'

or real bogus titles that sound more like a job description:
'Software Qualtiy Assurance Team Leader'

I'll settle for software developer for now, although my current job entails a great list of different tasks. Lets try it out:
'Quality Assuring Software Architect Designer' - boo!