Taswar Bhatti
The synonyms of software simplicity
yelling

I remember watching a talk on infoq by Michael Feathers. He said something about growing your software teams organically like a garden. An example he gave is, you don’t yell at the lettuce for not growing, you have to nurture it and help it, try different things so that it grows better.

If you have a co-worker in your team not doing very well, you need to help them to become stronger, guide them, try different things, show them different ideas, pair with them.

The reality is every software project will have weeds (bad code), you need to pull the weeds out as the garden grows, clean it up, so that overall the software is growing more organically. By having a stronger team you will have less weeds.

For your process rather than just focusing on task base feature, one should also focus on code quality features. Don’t just focus on hammering the new feature out, have the time to go over items that need care. Refactor the code that you see lots of bug and write test in those areas.

From my experience, I have seen when a coworker tries to explain their problem to you they already have a solution in their mind and when they try to verbally explain to you they have in the back of their mind solved the issue already. And if its not the case give them ideas of how you perceive the problem and show them your take on it.

But by yelling and not helping the lettuce, the lettuce is not going to grow any better.

linq

Recently I was asked a simple code to improve the performance, and at first I couldn’t see it but as you know your brain starts working when you aren’t thinking of the problem anymore. (It happen to me when I was driving)

Anyway the problem on hand was there is a for loop and when there are 10000 clients it performs bad.
Something along the line of.

So I went and wrote some code to see the perf using Linq and at the end using a Dictionary rather, since a dictionary is way faster in lookup, O(1) in this case.

Here is the code using a List and Linq together

and if we changed the datatype to Dictionary this was the code used

Here is the end result of using it on an i7 8G of ram machine.

console

And the results show that using an index as a dictionary is definitely faster, but one also has to look at the number of data.
Where there are only few data entry using linq is quite insignificant in performance but where there are millions of data, it really shows that it slows down.

Here is the rest of the code.

scala-ubuntu

First one has to get their java working.

To install java

Once java is installed we will install scala, I like using stow for my package management for non apt-get stuff.

Now that we have scala is installed lets get play framework installed

If you get an error when you launch play that means you havent given the rights to the boot folder, check the commands I have listed above again.

linq

Was going through some legacy code recently and found a big for loop that had multiple switch statement inside. So being that I hate something that is fairly large, every method should be small and concise, I went along to refactor it to SRP.

This code is generic so you might see something like this in your code base also.

As you will notice one can go on and keep adding types to it (so did the legacy code).
But if you think about it what this code is basically doing is that its just filtering things out to seperate collections.

Let see how we can answer things with LINQ on this one

First lets remove the if statement for customer IGNORE.

Ok one step done thats better, now lets see that the loop is basically a filter, so lets just take the payingCustomer example and break it down first. Its is going through a loop and finding the A_TYPE customer. Therefore a linq query like

collection.Where(x => x.Type == A_TYPE).toDictionary(t => t.Key, t.Name);

can answer that one.

So lets create a function/method that does this.

So here we have a single responsibility function, that just does one thing and does it well.
Its more of a functional style of programming (data in and data out).
No side effects of any sort. No saving of data to database or file etc.

Now lets go back to our original code, we can now remove the loop and switch statement all together.

Note: we now have a filterCustomer collection, which filters out the ignore customers first.

By doing so we can write a unit test to test the method/function FilterCustomers and we can be 100% sure that all it does is a single responsibility task.
We now have removed complexity in our codebase and the test-ability goes up.

linq

Here is some poorly written code that I had to review today and modify (i.e refactor). I have removed the domain of the code and renamed the variables, so that it remains anonymous, but the just of the code is still intact.

Lets go through the inner loop of the code first.

First the loop is really unneccesary one can find out how many items there are using the
count of if since it is an IEnumerable

Thus it becomes

Now we go to the outer foreach we can put a Where clause to remove the if statement we don’t really need to check for the “0” condition since 1 + 0 is still 1 so why filter for those.

Finally lets remove the entire foreach loop and the count if statement. Since if we have 0 items this code will still not fail.

Now we have replaced all this code with a linq query that would tell us how many items there are with one line of linq. I believe this makes is easier on the eye and readability of it rather than looping and branching of the code. The more branches you have the harder it is to read code.

dotnet C#

Here is a quick way to detect if a text is in Canadian Aboriginal Syllabic in C#.

It is just an extension method that would detect if your string is in that range by using regex.

Enjoy.

eclipse_indigo

So today I came in to work and saw that my wonderful windows machine was restarted due to Windows Update, and yesterday I was working on some java stuff and did not close out my eclipse, thank god that I do regular code check-in 🙂

Anyways tried to relaunch eclipse and it kept hanging on workspace.

To fix that I had to go into my workspace folder C:\workspace\.metadata\.plugins

Then I copied the org.eclipse.core.resources to a backup directory and deleted it from the plugins folder.

I restarted Eclipse and then did a File->Import->Existing Project into Workspace and browse my workspace/project directory

And voila I was back in action 🙂

techchange

Driving Technical Change Book cover
Have wanted to post the review of this book for a while, which I read somewhere beginning of this year.
This book does a very good job in classification of the “typical” stereotypes of people in IT.
– The Uninformed
– The Herd
– The Cynic
– The Burned
– The Time Crunched
– The Boss
– The Irrational

After the first section we go into what kind of techniques we can use to drive technical changes.
– Gain Expertise
– Deliver Your Message
– Demonstrate Your Technique
– Propose Compromise
– Create Trust
– Get Publicity
– Focus on Synergy
– Build a Bridge
– Create Something Compelling

Lastly the author goes into Strategies one can use to drive technical changes
– Simple, Not Easy
– Ignore the Irrational
– Target the Willing
– Harness the Converted
– Sway Management

The book is a short read with only 125 pages, it is a good read but at the same time one should always remember there are people whom you have to deal with that are emotional, and us human’s are not predictable, the classification helps but if we really want to drive the change we have to be the change agent. I would recommend this book for a beginner who wishes to drive technical changes.

Jruby

Have been giving eventmachine a try but I do have issues with it thus wanted to try out the beta version on github.

Here is how you get it to install on your local machine.
– First clone the repo
– Build the gem
– Install the java version

goliath

What the ???? goliath ERROR: While executing gem.
I was wanting to try out goliath.io (Goliath: Non-blocking, Ruby 1.9 Web Server) for more info look at http://www.igvita.com/2011/03/08/goliath-non-blocking-ruby-19-web-server/

In any case I was not able to get it to install on JRuby so went and get me 1.9.2 MRI.

Once installed MRI 1.9.2, I went into the gem dir to gem install goliath and guess what this message pops up.

Really helpful (scarcasim) , then what I had to do to fix this was update my gem

After doing so I was able to

Now its time to try out goliath, wish me luck and if anyone knows how to install it with Jruby please let me know cuz jgem install goliath didnt work for me.

UA-4524639-2