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
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

    Categories
    Programming

    99 Problems(3)

    Find out whether a list is a palindrome.

    (defn ispalindrome? [xs]
    	(= xs (reverse xs)))
    Categories
    Programming

    99 Problems(2)

    Find the last but one element of a list

    (def testlist [1 2 3])
    (nth testlist (- (count testlist) 2))
    
    Categories
    Programming

    99 Problems (1)

    Find the last element of a list.

    (def testlist [1 2 3])
    (last testlist)
    
    Categories
    Life

    Go Giver

    Go-Giver is a nice little book which revolves around these 5 principles

    1) The Law of Value: Your true worth is determined by how much more you give in value than you take in payment.
    2) The Law of Compensation: Your income is determined by how many people you serve and how well you serve them.
    3) The Law of Influence: Your influence is determined by how abundantly you place other people’s interests first.
    4) The Law of Authenticity: The most valuable gift you have to offer is yourself.
    5) The Law of Receptivity: The key to effective giving is to stay open to receiving.