19 March 2011

Interesting Tools on Bytecode Manipulation

The last week, i got a chance to experiment on couple of bytecode manipulation APIs/tools and thought i can share my learning here.

Javassist is one of bytecode manipulation APIs that helps you to manipulate bytecode and it is simpler to use. I wrote a simple method profiler that takes class files as input and instruments the bytecodes in each method. Added, method start time, complete time and measured the time spent in the method. One good thing about Javassist is that you can directly add code written in Java that compiles on the fly while instrumentation. Seems like bytecode instrumentation is bit easier in Javassist. With Javassist, you can also do on the fly instrumentation during classloading phase.

Retroweaver is another bytecode manipulation tool that back ports the code compiled by Java 5 to Java 1.4. If you have written classes (or a third party classes/libraries) in Java 5 and if your production system still runs with Java 1.4/1.3/1.2, you may want to check out this tool. It is really cool to use latest APIs/libraries in old JVM. Retrotranslator is a similar tool.

Bytecode engineering seems to be very interesting.

07 March 2011

Why Contemporary Leadership?

In the ancient times, when locomotive motor was not invented, people who could afford, traveled using bullock carts and the people who weren't able to afford a pair of horses and cart traveled by legs. After the invention of motor and after having undergone industrial revolution, people travel by cars or public transportation. The means of transport has changed but the travel hasn't (moving from one point to another point).

Today, many of the organizations are finding ways for transportation of their organizations from point a (current state) to point b (the transformation state) and they are ready to do anything that ought to be done. They are not ready to travel using bullock carts. I think criticisms and cranky jokes of obsessed Gen Xs on Gen Y are fading away and by now people who will be getting old in near future have to anyway deal with Gen Ys by their sheer numbers. If they continue to criticize, i think it is not going to help the organization at large. Any organization needs contemporary ways of brining in more effectiveness.

These days, the people who join workplace (predominantly often called as Gen Ys) are value conscious and by their virtue of exposure, they tend to make decisions based on how things affect them. We can't question and debate on their way of thinking because this thinking is not unique to Gen Ys. It is part of human evolution. The evolution says, the size of human brain shrinks but its processing power increase every day and the way a 22 year old youth thought 20 years back and the way in which modern day youth thinks varies (greatly?).

While we talk about culture, workplace ethics, work ethics or professionalism, we got to understand that those are things that were once practiced and if we get too much carried away (or adamant) with yesteryears, it will be living in the past or reliving the past and who knows we may fail utterly when we relive. Our thoughts, approach and the way we achieve the vision has to be contemporary. This has to be freshness.

While leading, we ought to be contemporary and forward looking taking good things of the past which just gives enough direction and propulsion needed for the escape velocity and to puts us into the orbit. 

Freshness, productive, creativity and innovation applies even for leadership.

05 March 2011

Democratization of Organization

There are two ways of getting things done - in your own way, dictatorially and in the way others like. With the machines, you can be dictatorial meaning that you decide when the machine has to produce products. Switch on the power, boot up the machine, make sure that all parts work in unison and the product is produced. It is a continuous system where the output is predictable. But in the place where human beings are involved and the factor of motivation/passion more appropriate than fear, democratization or knowing what people have in their mind becomes absolute need. Human beings are discrete systems and they become quite unpredictable as mind and emotions are involved. 

There are two reasons why you democratize anything. First is due to the fact that you cannot make decisions or you don't feel responsible for something that is going to happen and the second reason is that you want to democratize to align your people towards the vision - may it be vision of a company or a country or the mankind. The first reason actually paves way to collective irresponsibility (like the climate change where everyone talks but no one does anything) and the second approach involves a lot hard work (likes of Mahatma Gandhi, Martin  Luther King). In order for effective democratization to become reality, first we have to accept that we can achieve it after a lot of failures. Initially, people tend to misunderstand the process of democratizing before understanding it completely which at the initial stage results to a lot of failure. After the initial failures and if you rally around your people during the failures, the democratization takes shape and becomes effective.

What are the signs of effective democratization? If you have at least few souls who give back far more than what they take back and if the ratio of number of souls that give back to the number of souls take back increases as the function of time, then you are staging yourself for better democratization.

22 February 2011

Puzzle - Who is Knight and Who is Knave

This is a puzzle that i read in internet sometime last week and thought of sharing it here.

There is an island that has people who always speak truth (knight) or people who always lie (knaves). Unfortunately, you need find the way to the capital of the island. You are standing at the fork and there are two roads - left and right. There are three people, let us call them A, B and C, who are native of the island standing near the fork. You approach them, they tell you the following statements

Two of us are knaves, one of us is knight and the road in the left goes to the capital.

Will you be able to find which road goes to the capital - is it left or right? 

19 February 2011

Simplification and Generalization in Problem Solving

You scatter toy towers of varying heights on the floor and ask some five old kid to arrange the towers in increasing order of heights. Most likely, he is going to knock of the puzzle. His first problem (and yours) will be understanding the problem - what needs to be done. Once he understands, he will complete the puzzles with your help here and there.After sometime, you ask him to sort toy circles in increasing order to circumference. Most likely he is going to finish off this taking lesser time than his previous. 

Both the instances are specialization of sorting - a basic algorithm that is known to human being. Human beings were sorting objects in life much before sorting algorithms were put forth. All those sorting were merely specializations and they work in specific scenarios but not all. Rather than saying it won't for all scenarios it is better to say that it was not tried having "all scenarios" in mind.

It is when we think about "all scenarios" we forget the specifics and the properties that is unique to the given problem and start to think about the "commonalities". When we think about "commonalities" we abstract ideas/concepts and bring many levels of abstraction based on the "commonalities". The specifics that are known at the time of abstraction forms as a boundary condition for abstraction. So, it is also very important to think widely about a specialization so as to make the abstraction more flexible & accommodative. Moving from specialization to a broader generalization is possible only when we simplify the problem domain and think about "many scenarios".

In order to understand the problem, you have to travel towards specialization and in order to solve it after understanding it requires simplification and generalization (and for achieving this you have travel further in time, by time i mean experience).

In next post, we will see some of the ideas on generalization from neuroscience's point of view.

16 February 2011

Software Design Puzzle #7.2 - Thread Pools & Tasks

Please refer to previous two posts on the same problem - Implementing Thread Pools and Tasks. Here is the link for your convenience.
Yesterday, i added a requirement that i want to have a priority for tasks (a problem on data structures and algorithms). Today, i thought about another feature that gives a lot of flexibility (real OO design). In the above examples, we didn't talk much about the threads in thread pools. Can we try to make threads in thread pool dynamic entity - based on the need, the number of threads in thread pool should grow or shrink. Here are my next set of questions.

  1. What are the design decisions that i should take so as to make thread pool dynamic.
  2. How can i make threads, tasks, thread pool at the topmost level of abstraction and yet get many different concrete implementations.
  3. How can i ensure that the code I am going to develop after two years (due to new requirements) doesn't affect my code now (seal the code from modification for new requirements)
  4. How can i bring in hierarchy, levels of abstraction and modularity for better design?
  5. Do i have any design patterns?

15 February 2011

Software Design Puzzle #7.1 - Thread Pools & Tasks

Refer to the previous post, Software Design Puzzle #7 - Thread Pools & Tasks. This post is an addendum to the previous post.

I m going to add one more enhancement to the thread pool design. The enhancement is to come up with a priority queue for tasks. Each task will have certain priority, an integer that increases as priority increases. At any given time, the task with highest priority has to be selected and run by threads in thread pool.

Can you refactor your design?

13 February 2011

Software Design Puzzle #7 - Thread Pools & Tasks

We know what is thread. The thread is an independent execution path or entity in a process. When you want to exploit multi-core (increased processing) or do some blocking operations, the thread is the default destination (increased interactivity, heavy input/output operations). In any programming language that supports multi-threading, you run the code that can be run as independent execution path as thread with each having its own context. The infrastructure that is needed to run threads in parallel like stack, program counter, registers are tightly coupled with the code that runs. Due to this tight coupling, each time you need an independent path (let us call it as task), you create a thread (the infrastructure) which has its own overheads. Is it possible to change code of the thread?

Obviously the next step is to separate out the infrastructure and the task which is achieved using thread pools. Here is the next problem.

Write a simple thread pool in Java with following requirements

  1. Have a fixed but configurable number of threads in thread pool. At any point of time, you can run up to N threads.
  2. Have a task queue (or a suitable data structure). This can be much bigger than number of threads. The tasks wait in the queue for their turn.
  3. The thread should consume tasks from the task queue and execute it. It can be any task (but you have to ensure some fairness). The role of the thread is to run task without bothering too much on what it does and how it does.

06 February 2011

Puzzle - Help the Painter

Your friend is a painter and he paints houses for quite sometime. He is highly professional and highly sought after as he known for his quality work and fair painting charges. Throughout his life he has painted lot of houses that are regular sizes - rectangles, squares and circles. He charges his customer based on the area he paints. (you see calculating area for regular shapes is cake for him)

Last week, a new potential customer called him up for a huge order that will keep him and his team busy for next five to seven months. The catch here is that the customer is not willing to pay a penny more and even your friend being a professional painter wants to quote a fair pricing strategy to his new potential customer to win this order. BTW, did i tell you that the area to be painted are irregular shapes.

The painting area is

  • Irregularly shaped like amoeba
  • Each surface is uniquely shaped (bare minimum he needs to paint 1000 such surface different in 1000 ways)


What is the pricing strategy that your friend can offer to his customer so that both your friend and his customer is happy.

03 February 2011

Organizational Entropy

Entropy (thermodynamics) is the energy that is not available for any useful work. Entropy in software measures the degree to which it is unordered, degree to which it can't be maintained. Entropy in organization measures the degree to which the workforce is unfocused & unordered. Though the field of application is different, by the very definition we understand that entropy is not a thing to boast about. The system continue to go in favor of entropy unless it is taken out in the form of heat.

Entropy in organization implies that energy that is available and that will eventually be spent on matters that is not so useful to the organization either be it taking too much of tea for a prolonged period in cafe or putting up a strategy in a conference with tea (or beer). All these are efforts which won't necessarily be converted to results. The next question that may come you mind - "is entropy same as that of being unproductive?".

Being unproductive is the result of having an entropy at higher side. Productivity is a metric that is measured after the event has happened. You have to wait for a week, a month, a year or until you have next meeting. But entropy measures how much of energy you have and what portion of it will be spent on things that will have little to no impact.

I feel like measure on entropy, and trying to reduce it, is a proactive approach than doing with measuring productivity alone. You better remove entropy periodically. Keeping a check on entropy increases the awareness and anticipation which in turn increases the probability of producing productive work/results.

Either in software or organizations, the entropy has to be worked against.

Related Links

31 January 2011

Can't Find a Better Leader, Be one

Often we complain that we are not able to find a perfect leader. The word perfect is the word that denotes excellence and such a leader cannot be found. Even found, the perfect leader never accepts that she is perfect as the excellence is not a destination. Let us come to the complain part. We generally tend to have a lower expectations and want the benchmarks to be lowered, tweaked until we get in. Once we get on board, we generally argue in favor of excellence and raise the bars. We clearly eliminate our roadblocks in the name of eliminating inefficiencies [that creates double standards]. Pretty weak way of looking either life or work.

How many times we thought that we have to be a better leader? We stop our thinking just with wanting to have a perfect leader. If you can't find a perfect leader, it doesn't mean that it can't be made, it just means that nobody has guts or conviction to be a perfect leader. Because, trying to be a perfect leaders hurts a lot and pains a lot as we need to work a lot and sacrifice a lot. The building cannot be raised without foundations and the leadership cannot be built without sacrifices. Sacrifice and see what happens. That is why people say, "the leadership starts with self".

If you haven't found any perfect leader in front you, go ahead and try to make yourself a perfect leader. The leadership is nothing to do with power/positions/designations and it is more to do with your virtue of thinking & action.

If Mahatma Gandhiji said, "Be the change you want to see", there has to be some reasons. :-)