Categories
Life

Who am I

I am a human,
I am an individual,
I am a son,
I am a brother,
I am an uncle,
I am a mentor,
I am a husband,
I am a father,
I am a friend,
I am.
Or, Am I.
Is everything, just an illusion?

Categories
Life

Positive Thinking

I got this sms today –

POSITIVE THINKING is not about EXPECTING the Best to happen. But, its about ACCEPTING that whatever happens is Always for the Best

I agree with the sentiment. Whatever will be, will be. Acceptance is the best way to be peaceful. But, it does not mean that we should avoid taking an appropriate action, which each moment, requires from us. Every moment, is full of choices. It is up-to us, to select a choice which reflects our temperament or, we select that choice which we know will be the best for the given situation. The choice we make, may lead to an unpleasant result. But, we should just reflect and move on.

Categories
Django

Django Lessons – #2

I needed to record the IP address of the user as well as the admin for every action completed. And, this IP must show with each log entry. So, I used user_ip=request.META["REMOTE_ADDR"]). But, this did not work on the server. The IP was getting recorded as 127.0.0.1. Why so? The information I got from the webfaction support was that

REMOTE_ADDR is 127.0.0.1 because requests for your site are proxied through our front-end web server, which of course is on the local host.If you want the original IP of the request, then use
request.META[‘HTTP_X_FORWARDED_FOR’].

I did some research, and found about the concept of reverse proxy.

Some links
Forum
Apache

Categories
Programming

Experience Report – From Zero to 500

Every experience teaches something. It is upto us to imbibe the lessons. Sometimes worrying about success and failure takes away the of joy of just doing.

I started working on the current project in September 2009. The technology stack is .net 3.5, Windows Forms, SQL Server 2008 and LINQ-To-SQL. The Project Manager hired me. When I joined the team, the software had been in development for 4-5 months. All of us are from different regions(Middle East,Europe) and work remotely. We communicate by using software like Skype, TeamViewer, and of course, email. We use a wiki for documentation, and a web-based bugtracker. Initially, I was given the task of understanding the software, and writing the documentation. I found this a bit strange. But, it turned out to be a good way to understand the software. Also, I was happy that a wiki was used for the documentation. My many doubts were clarified either by the PM or, the client(end-user). Soon, I found there were many problems –

1) The wiki had all the information related to the system to be developed, and tutorials for the users. But, there were many ambiguities in the system documentation. Also, it was a bit outdated, and not in sync with the state of the software.Most of the domain knowledge was with the PM. And, one of the reasons, he had asked me to do the documentation was to capture that knowledge.

2) The codebase had huge amount of duplication. There were no tests.

3) There was an architecture – 3 logical layers – windowsforms , business layer and data access layer. But, there was lot of logic which was in the forms.

4) All the features which had been implemented were incomplete and had bugs.

5) One of the developers involved had this strategy – he would fix the bug assigned to him and close it.He did not check all the scenarios. So, other bugs cropped up. The software was unstable. I felt very uneasy about this situation.

6) We were using LINQ-to-SQL, but did not have good understanding of this technology. This was creating problems like too many queries getting fired. We realized later when we started facing performance issues.

7) The database was not well designed. There were some columns in some tables not being used. Most of the columns had “allow nulls”. It was not under version control. We had views which were doing lot of calculations.

The PM knew about these issues, and was eager to overcome them. One thing I appreciate about him is his persistence and eagerness to solve problems. We started talking about testing, and he suggested to write functional tests. But, we found that the Devexpress controls did not support UI testing using Microsoft framework. Then, I told him we should start writing unit tests, and he was open to this idea. I also suggested that we use MVP(Model View Presenter), and take all the logic out of forms. He agreed, and asked me to do it on a couple of forms. I started refactoring, and adding tests.

Initially, I was the only one running the tests. Sometimes I found compile errors in the test project which surprised me! I realized that the project has not been added as part of the solution!. Initially, many of the tests were integration tests and so the database was involved. We created a script to create the database and, separate data files(sql) for default data. Then, wrote a script which created the database, build the projects and ran the tests. We used NDBUnit for input data to be used for integration tests. This required creation of xml files. Slowly the test coverage increased, and it started catching some bugs. Then, I started writing tests for bugs too. I realized some things were common on all forms. This, was a eureka! moment, seeing patterns among the mass of duplicate code or, the representation of similar ideas. This led to creation of base view and base presenter. This eliminated a lot of duplication. Soon, we had 2 new members in the team. They were eager to learn and write tests. This helped in speeding up of writing tests. Today, we have about 500+ tests. Also, we started a QA page which listed points to be checked for each module. This page helped everyone, including the QA team.

The state of the software today is –

1) The software is in better stable condition. Most of the business logic is now in good condition, with very few bugs.
2) The user interface has still some issues.

3) We have many tests, but some of them are unreadable, look very ugly. We have have used BDD style of language for some of the tests in given\when\then style.

4) Linq-to-Sql Entities – They had only set\get properties. We had committed
violation of “Law of Demeter” throughout the codebase. Instead of asking Customer.IsYourName(x), we had code (if customer.Name == x). So, we did some refactoring, and added more stuff to the entities like validation rules, moved functions which acted upon “entity data” to entity.

5) A lot of duplication still exists, which can be removed.

6) We have an acceptable performance metrics page for different scenarios. We have tested a lot, and improved the linq-sql queries and the stored procedures. But a lot of work still needs to be done.

7) The software, is currently in testing stage. The users are testing the software with live data for some part of the system.

Some concluding observations –

1) The architecture of a system can evolve. And, an evolving architecture solves the problems faced, so everyone in the team is able to understand the reasoning behind the changes.

2) Some of the decisions related to architecture could have been made early. For example, the application is for multiple users, and these users are located in different locations(countries). So, it seems obvious that some thought should/could have been given – Where will the database be located? Will we need replication to handle some scenarios? Should we develop a desktop or a web application? Also, it seems there is lack of literature for such scenarios. What are the best practices which have succeeded? Or, the way we have approached, taking decisions much later like for replication. In fact, once replication was implemented, we had to change all primary keys to guid from int.

3) A remote set of developers can work well. But, I miss pair-programming. I tried it a couple of times, but due to slowness of broadband, it did not work out.

4) The unit\integration tests gave confidence to the developers as well as the stakeholders. The stakeholders had become jittery, and were reluctant to request changes, since after every change old problems cropped up. But, having regression tests helped to track such bugs and prevented from re-appearing.

5) The documentation of various aspects of the project on the wiki has helped new developers and the QA process. But, the issue is of keeping it in sync with the changes being made to the software. And, I think we are not always in sync.

6) The tests have really helped us. But, I wonder if we are writing too many tests. The test coverage is around 60 %. I feel, since we have remote developers, and also turnover in the team, these tests serve as a good safety net.

7) We need a continuous integration server. The developers are not disciplined enough, and don’t run tests before every commit. This means, if tests are failing then sometimes it goes unnoticed. We deliver software to client and QA every few days. But, building a setup is a manual process, and done by a developer on his local machine. So, sometimes local changes creep into the build.

Categories
Learning

History..boring,Think Again

During my school days, BBC World Service(English as well as Hindi channel) was my favorite source for news.One of the great things on BBC was that you always got insight into an important news-story, with in-depth coverage of historical background.So,if they were covering Israel-Palestine conflict,you will get to know about various people involved,their history etc.But, when it came to history taught in school, it was quite bland.Though, I think, my history teacher made the subject quite interesting.

Recently, I have become fascinated with maths.My current interest was sparked by this article 2 years back.

“The first thing to understand is that mathematics is an art. The difference between math and the other arts, such as music and painting, is that our culture does not recognize it as such.”

So, true. I have never thought about maths as an art.

“A mathematician, like a painter or poet, is a maker of patterns. If his patterns are more permanent than theirs, it is because they are made with ideas.”

The main problem with school mathematics is that there are no problems.But a problem, a genuine honest-to-goodness natural human question— that’s another thing.
How long is the diagonal of a cube? Do prime numbers keep going on forever?

And my favorite line

“Mathematics is not a language, it’s an adventure.

It made me realize that maths I learnt at school and the way maths was taught, was so boring. Since then, I have picked up a few maths book which focussed on the history.My first book was Journey Through Genius.The most fascinating character I came across was Euclid.He wrote a book called Elements way back in 300 B.C.This book had 465 propositions from plane and solid geometry and the number theory. And, I realized that most of the geometry I did in school was written in this book!!.You can find the book here. Then, I read a novel, a certain ambiguity. This book touches on various topics related to maths like infinite,euclidean\non-euclidean geometry and philosophy.Brilliant book!!
These days, I am reading, The Equation That Could Not Be solved. A book about symmetry ,theory of equations and the creation of group theory.The 2 main protagonists Abel and Galois, both died young, aged 26 and 20 respectively.Their story is both fascinating and tragic.

So, what I have learned in this journey so far? I have learned about how maths and the mathematical ideas have evolved, the great mathematicians who have influenced the evolution of maths, the idea about patterns(sum), the difficulty of getting recognition for one’s work(maybe not these days), great partnerships (Hardy-Ramanujan).
So, my journey continues in rediscovering maths through characters who influenced maths in such a profound way.

What about you? Have you found any subject fascinating through the lens of history?

Categories
Learning

Lesson of the week – seek->sense->share

It’s amazing, when you come across something which strongly resonates with you.I came across this idea about learning and sharing, Active sense making.

This week I had this experience with a fellow developer.He has joined recently our team, and had little experience in writing unit tests.I had directed him to various online resources, and some books.But, the best way to learn is to start writing tests.He was struggling to write test for a behavior.So, using my own knowledge and experience, and my sense making – I suggested him to think in this way –

“given” there are 2 orders having “Chocolate” as items,”when” the user searches by typing “Chocolate”, “then” the user should see the 2 orders

And, he immediately grasped as to what approach was needed to write tests.

Categories
Maths

Beauty – Proof by Contradiction

What is Proof By Contradiction –

To prove something by contradiction, we assume that what we want to prove is not true, and then show that the consequences of this are not possible. That is, the consequences contradict either what we have just assumed, or something we already know to be true (or, indeed, both) – we call this a contradiction.

Axioms

An Axiom is a proposition that is not proved or demonstrated but considered to be either self-evident, or subject to necessary decision. Therefore, its truth is taken for granted, and serves as a starting point for deducing and inferring other (theory dependent) truths.

1. Additive Identity
[ a + 0 = a ]

2. Multiplicative Identity
[ a . 1 = 1 ]

3. [ 1 != 0 ]

4. Additive Inverse
[ a + (-a) = 0 ]
or, it could be written as a – a =0

5. Multiplicative Inverse
[ a. 1/a = 1 ]

6. [ a .0 = 0 ] (this axiom has a proof)

We all know that we cannot divide by 0. Can this truth(which we simply accept) be proved?

We will start by assuming we can divide 1 by 0.

From Axiom 5, the multiplicative inverse, for any n

n. 1/n = 1.
So, when n = 0 , then
0 . 1/0 = 1

Lets choose 2 numbers, x and y, such that x != y.
From axiom 6, we can say

x . 0 = 0
y . 0 = 0
x . 0 = y . 0

Lets, multiply each side by inverse of 0 i.e. 1/0.

(x.0) 1/0 = (y.0) 1/0
We can rewrite it,
x(0 . 1/0) = y (0 . 1/0)

Now, 0. 1/0 is 1(multiplicative inverse), which means
x = y , but this contradicts our assumption that x!=y.
So, this means it was wrong to assume that 1/0 exists.

There are some famous proofs using this method –
1. There are infinite prime numbers ( Euclid proved this in Elements)
2. √2 is irrational

Sources:
1. Proof by Contradiction
2. The Art Of The Infinite ( our lost language of numbers)

Categories
Life work

Pessimism

Do you think pessimism is bad? I don’t think so. I have found in many situations that being pessimistic helps out. I am a programmer, and a pessimistic one at most times. In many programming situations, I tend to be pessimistic which helps to figure out loopholes.
The problem with pessimistic attitude is, when one allows it to overwhelm one’s mind to such an extent that it prevents one from taking an action due to fear of negative result.

Categories
Programming

Notes from a TDD session

My friend wanted to do a TDD session with me.I have experience of using TDD on couple of projects in my previous company.But, since one year I have been doing freelance work,and have not yet got chance to do TDD on a live project.I have been working on a legacy project,to which we have added unit and integration tests.So, which example to do for the session? I decided to go for bowling kata.We used C# with MBUnit framework.

It took just 5 minutes to go through the rules,as my pair was already familiar with the Bowling game.So, how to go about writing the first test?.My friend,wanted to know how to go about writing tests – I told to him to think himself as the user of the API.How would he like to use the class library?.Write the test for the simplest behavior you can think of.

From Mike Bria,

Keep yourself focused on writing tests for the desired behavior of your objects, rather than for the methods they contain.

Our first test – ScoreShouldBeZeroWhenGameBegins.We did not had any design discussion before we started.Then,when we reached the point where we had to take a design decision for passing the test –ScoreShouldBe24_WhenSpareIsFollowedByRegularThrow.How do we implement the “determination and calculation of spare”? My pair suggested,having a Frame object.But,I felt we can achieve the desired behavior using the BowlingKata class.We implemented,and the test passed.But,the code looked a bit ugly.Then, the next testcase was ScoreShouldBe39_When2SparesAreFollowedByARegularThrow.This led to a long design discussion,and we ended up with a Frame class.

A good advice from James Shore,

Don’t let design discussions turn into long, drawn-out disagreements. Follow the ten-minute rule: if you disagree on a design direction for ten minutes, try one and see how it works in practice. If you have a particularly strong disagreement, split up and try both as spike solutions. Nothing clarifies a design issue like working code.

My friend wanted to know if, when we ended up creating Frame class,we have to write test for this class.I did not feel we needed to.When we are writing tests,usually a class does not exist in isolation.A class achieves its purpose by collaborating with other classes.And,here our tests were good enough.

We ended our session in about 1.30 hours(the kata was not completed).I committed the code to github.Then,I spent some time looking at design,and did some refactoring.

Using the idea of Michael Feathers’ Class Splitting,below is the diagram of 2 classes –

image of Frame class with methods and variables

image of bowlingkata class with methods and variables

Interesting notes from the 2 diagram(and some additional information)

1) In the Frame class, all the methods just use the instance variables,whereas in BowlingKata class,some methods use each other
2) Good Command Query Separation – all the methods of Frame Class are query based,except PinsFallen.All methods of BowlingKata are Command based.
3) All methods in the Frame class are public\internal.The BowlingKata has some private methods too.

Incremental Design

Our session was very much incremental design,as mentioned here by James Shore,

This takes place in three parts:

  • start by creating the simplest design that could possibly work,
  • incrementally add to it as the needs of the software evolve,
  • and continuously improve the design by reflecting on its strengths and weaknesses.
  • We followed the rhythm of TDD – fail the test,write just enough code to pass the test, and refactor. The code is here – http://github.com/vishalsodani/LearningTDD

    Note:A friend of mine told me that only tests don’t lead to good design.You can have a class with many small methods and tested, but maybe taking on many responsibilities.The SOLID principles are good guide during the implementation.I agree with him.As soon as you feel that a class is doing too much,apply SRP.

    Categories
    work

    Freelance Sites

    Upwork
    HasJob
    HackerNews – Freelancer, Who is Hiring threads
    For Hire on reddit
    Paid service for remote jobs
    Guru
    FreelanceSwitch
    VWorker
    GetAFreelancer
    Scriptlance
    Collection of Jobs
    Programmer Meet Designer
    People

    Work from home – found on hacker news