Sunday, December 18, 2011
Sunday, November 13, 2011
Wednesday, October 12, 2011
On the shoot-out
So here’s what I think (knowing that nobody cares what I think).
In 2009 Mahinda really wanted to win the western provincial council election big, specifically he wanted to win Colombo district big. This was at the very late stages of the war, a strong election win was needed for him to show the world that people approve the war. A big win in UNP stronghold Colombo would have created good news, and also made good grounds for the upcoming parliamentary elections (Presidential elections were probably not planned then).
The previous election results for Colombo wasn’t that good. The win was marginal; and that too at a weak period of UNP with people starting to reject the cease fire agreement. worst of all, there weren’t any strong candidates for UPFA in Colombo.
2004 Provincial Council Elections, Colombo District | Votes
2004 Provincial Council Elections, Colombo District | Top candidates of UPFA
So, Mahinda did what he does the best, bought a couple of candidates from the UNP, not with money, but with power! Duminda Silva and Thilanga Sumathipala. These two had enough money of their own for them to be bought with money, what they lacked while in opposition is power, and that’s what Mahinda had to offer them. The deal probably was win me Colombo and I’ll give you parliamentary tickets and organizer posts.
Results were quite clear, win they did. They literally bought votes for themselves spending insane amounts of money.
2009 Provincial Council Elections, Colombo District | Votes
2009 Provincial Council Elections, Colombo District | Top candidates of UPFA
So, Duminda and Thilanga got their parliamentary election tickets and organizer posts as promised. But, unfortunately, that meant someone else lost their organizer post and possibly election tickets. To compensate for this, Mahinda offered Bharatha some other posts including the presidential advisor post.
For Duminda, the electoral seat doesn’t matter. He buys votes – literally. So he could go in to any area, throw some cash around, muscle out any resistance and get voted. But for someone like Bharatha, getting voted depends a lot on relationship building and small scale spending's over a lifetime. And giving his electoral seat to Duminda meant the end of his active political career; presidential advisor post didn’t really compensated for that. Thus started the battle between Duminda and Bharatha.
Where did Duminda get his money from? I don’t know. His brother owns few radio stations and they probably have other businesses. Some say it’s drugs. Can’t rule that out, but it’s highly unlikely that Rajapaksha’s would get a drug dealer in to the defense secretariat. Most claim drugs because they don’t know people could actually make an insane amount of money with legit businesses. And all they could think of is drugs.
There are no black or white characters, they are all shades of grey. Duminda had lot of thugs surrounding him, and I wouldn’t believe if someone said Bharatha didn’t. And most of all, I don’t think either of these two had got into a fight of this nature where the other party responded in the same way. They are probably so used to going in with brute force and shooting away the opponents.
So, when the first to get out of the vehicles – be it Duminda or Bharatha – started waving the guns around, probably didn’t expect the other party to do the same. And they didn’t know what to do next. They either had to pack-up and leave, or shoot. Alcohol probably stopped them from making the wise move and shoot they did. The ones with most guns, made the most kills. But I don’t think Bharatha’s group didn’t shoot back, or Duminda didn’t get shot, as some bloggers claim. With three bullets in the head, I’d be really surprised if he’s not vegetable now.
So, is this Mahinda’s fault for bringing in a thug from UNP to muscle out – and kill in this instance - the old SLFPers who helped him vin the elections? It’s obviously a consequence of a series of incidents, but I don’t think it could be directly attributed to bringing Duminda and Thilanga in to SLFP. Mahinda is just another grey character, with good and bad, making decisions which he thinks is right for him, his family, his friends and after some more items in that list, the country (hopefully).
Related: http://indi.ca/2011/10/hearsay-about-duminda-silva/
In 2009 Mahinda really wanted to win the western provincial council election big, specifically he wanted to win Colombo district big. This was at the very late stages of the war, a strong election win was needed for him to show the world that people approve the war. A big win in UNP stronghold Colombo would have created good news, and also made good grounds for the upcoming parliamentary elections (Presidential elections were probably not planned then).
The previous election results for Colombo wasn’t that good. The win was marginal; and that too at a weak period of UNP with people starting to reject the cease fire agreement. worst of all, there weren’t any strong candidates for UPFA in Colombo.
2004 Provincial Council Elections, Colombo District | Votes
POLITICAL PARTY | VOTES | % | SEATS |
UNITED PEOPLE'S FREEDOM ALLIANCE | 322,653 | 49.11 | 25 |
UNITED NATIONAL PARTY | 276,759 | 42.12 | 15 |
2004 Provincial Council Elections, Colombo District | Top candidates of UPFA
Candidate | Preferential votes |
Aruna Hemapala | 36,029 |
Andarage Don Gamini Thilakasiri | 34,992 |
H. Kanchana Peiris | 34,658 |
So, Mahinda did what he does the best, bought a couple of candidates from the UNP, not with money, but with power! Duminda Silva and Thilanga Sumathipala. These two had enough money of their own for them to be bought with money, what they lacked while in opposition is power, and that’s what Mahinda had to offer them. The deal probably was win me Colombo and I’ll give you parliamentary tickets and organizer posts.
Results were quite clear, win they did. They literally bought votes for themselves spending insane amounts of money.
2009 Provincial Council Elections, Colombo District | Votes
POLITICAL PARTY | VOTES | % | SEATS |
UNITED PEOPLE'S FREEDOM ALLIANCE | 530,370 | 57.78 | 25 |
UNITED NATIONAL PARTY | 327,571 | 35.69 | 15 |
2009 Provincial Council Elections, Colombo District | Top candidates of UPFA
Candidate | Preferential votes |
Arumadura Lorence Romelo Duminda Silva | 165,128 |
Uduwatuwage Janathpriya Thilanga Sumathipala | 159,603 |
Udaya Prabhath Gammanpila | 116,144 |
So, Duminda and Thilanga got their parliamentary election tickets and organizer posts as promised. But, unfortunately, that meant someone else lost their organizer post and possibly election tickets. To compensate for this, Mahinda offered Bharatha some other posts including the presidential advisor post.
For Duminda, the electoral seat doesn’t matter. He buys votes – literally. So he could go in to any area, throw some cash around, muscle out any resistance and get voted. But for someone like Bharatha, getting voted depends a lot on relationship building and small scale spending's over a lifetime. And giving his electoral seat to Duminda meant the end of his active political career; presidential advisor post didn’t really compensated for that. Thus started the battle between Duminda and Bharatha.
Where did Duminda get his money from? I don’t know. His brother owns few radio stations and they probably have other businesses. Some say it’s drugs. Can’t rule that out, but it’s highly unlikely that Rajapaksha’s would get a drug dealer in to the defense secretariat. Most claim drugs because they don’t know people could actually make an insane amount of money with legit businesses. And all they could think of is drugs.
There are no black or white characters, they are all shades of grey. Duminda had lot of thugs surrounding him, and I wouldn’t believe if someone said Bharatha didn’t. And most of all, I don’t think either of these two had got into a fight of this nature where the other party responded in the same way. They are probably so used to going in with brute force and shooting away the opponents.
So, when the first to get out of the vehicles – be it Duminda or Bharatha – started waving the guns around, probably didn’t expect the other party to do the same. And they didn’t know what to do next. They either had to pack-up and leave, or shoot. Alcohol probably stopped them from making the wise move and shoot they did. The ones with most guns, made the most kills. But I don’t think Bharatha’s group didn’t shoot back, or Duminda didn’t get shot, as some bloggers claim. With three bullets in the head, I’d be really surprised if he’s not vegetable now.
So, is this Mahinda’s fault for bringing in a thug from UNP to muscle out – and kill in this instance - the old SLFPers who helped him vin the elections? It’s obviously a consequence of a series of incidents, but I don’t think it could be directly attributed to bringing Duminda and Thilanga in to SLFP. Mahinda is just another grey character, with good and bad, making decisions which he thinks is right for him, his family, his friends and after some more items in that list, the country (hopefully).
Related: http://indi.ca/2011/10/hearsay-about-duminda-silva/
Sunday, September 18, 2011
Friday, August 05, 2011
ඇයට කුමක් වීද?
2007 වසරේ මාව ඇමෙරිකාවට යැව්වා ඒ කාලේ මම වැඩ කරපු ඔපීසියෙන්. මුලින් විස්කොන්සින් ප්රාන්තයේ මිල්වූකී වල මට මාස පහක් විතර ඉන්න උණා. මට නම් මිල්වූකි මෙලෝ රහක් නැති පලාතක්. මම එහෙට ගියේ 2007 දෙසැම්බර් පළමුදා, එදා එහෙට හිම කුණාටුවක්. මම එහෙන් ආවේ 2008 අප්රේල් මැද, එදත් හිම කුණාටුවක්. එහේ හිටිය මාස පහ හමාරම, හිම හිම හිම.
එහේ අපේ කණ්තෝරුවෙම තව අය හිටියත් මම නැවතිලා හිටියේ තනියෙන් අපාර්ට්මන්ට් එකක් අරන්, මම පෞද්ගලිකත්වයටත් නිදහසටත් කැමති නිසා.
කොහොමින් හරි අප්රේල් වල මම ගියා නිව්යෝක් නගරයට. එහේ මම වැඩ කලාට අපාර්ට්මන්ට් එකක් ගත්තේ නිව් ජර්සි වල. එහෙත් ඔෆිස් එකේ අය හිටියාට මම නැවතුනේ තනියෙන්. මම එහේ ඉඳලා නිව්යෝක් වල වැඩට ගියේ ආවේ බස් එකේ.
වසන්තය ඉවර වෙන කාලේ විතර, එක සෙනසුරාදාවක, මම නිව්යෝක් නගරයේ රස්තියාදුවක් යන්න හිතාගෙන ගිහින් බස් හෝල්ට් එකට වෙලා හිටියා. ගෙදර ඉන්න කම්මැලි හිතුනම මම ඒ දවස් වල කරන්නේ ඒක. මම බස් සීසන් ගන්නේ මාසෙටම, ඉතින් ගමනට වැඩිපුර වියදම් වෙන්නේ නෑ. අනික නිව්යෝක් නගරේ බලන්න ජාති හෙන ගොඩයි. ඇවිදලා කෙලවරක් කර ගන්න බැරි උනා මට එහේ අවුරුද්දක් විතර ඉඳලත්.
ඉතින් ඔය බස් හෝල්ට් එකේ තියෙනව බංකු තුනක්. මම යද්දී දෙන්නෙක් ඉඳගෙන හිටියා. ඉතුරු එකේ මම ඉඳ ගත්තා. සෙනසුරාදා ඉරිදා දවස් වලට බස් යන්නේ පැය දෙකෙන් දෙකට විතර. ඉතින් මට කලින් බස් එක මිස් වෙලා තිබ්බ නිසා සෑහෙන වෙලාවක් ඔතන ඉන්න උනා. ඔහොම ඉද්දී ඔතෙන්ට ආව සෑහෙන වයස සුදු නෝනා කෙනෙක්. ඉතින් එයා හිටන් ඉද්දි මට පුලුවනෑ ඉඳන් ඉන්න, ඉතින් මම නැගිටලා දුන්නා පුටුව. එයාට හෙන පුදුමයි. ඉතින් එයා මගේ රට තොට අහලා මාත් එක්ක කතාවට වැටුනා. එයා නැගෙනහිර යුරෝපීය රටක. පොඩි කාලෙම ඇමෙරිකාවට ඇවිත්, එහෙන් කසාද බැඳලා නැවතිලා. දැන් මහත්තයා නෑ, ළමයි රටේ ඈතට ගිහින්. එයා තනියම, මම ඉන්න අපාර්ට්මන්ට් වලම නැවතිලා ඉන්නේ.
එදයින් පස්සේ, ඉඳලා හිටලා අපි බස් හෝල්ට් එකේ දි හම්බුණා. බස් එකේ එක ලඟ ඉඳගෙන අපි අපේ රටවල් ගැන, ළමා කාලේ ගැන, ඇමෙරිකාව ගැන කතා කරා. ඇගේ ගෙදර ඇවිත් යන්න කියලා ඈ මට ආරාධනා කරත්, මම ගියේ නෑ. මම මිනිස්සු එක්ක බොහොම සීමිත සම්භන්ද කම් පවත්වන කෙනෙක්..
කොහොම හරි, මම ලංකාවට එන්න දවස් දෙකකට කලින් මට ඈව හම්බුණා. මම ඈට කිව්වා, මම ලංකාවට යන බව. මම සතුටින්ද දුකෙන්ද යන්නේ කියා ඈ අහුවා. මම කිව්ව මගේ අම්මලා අප්පච්චිලා දකින්න මම ආසාවෙන් ඉන්නවා කියලා. ඈ මට සුභ පතලා, වෙන විස්තර කතා කරා.
අපි වෙන් වෙන මොහොතේ ඈ මගේ අතින් අල්ලගෙන කිව්ව "ඔබ ආයේ ඇමෙරිකාවට ආවත්, ඔබව දකින්න මම ජීවතුන් අතර ඉන්න එකක් නෑ, ඔබ බොහොම හොඳ ළමයෙක්, ඔබට දෙවි පිහිටයි" කියලා. ඇගේ වයසක දෑසින් කඳුලු හෝ ගාලා ගලාගෙන ගියා.
නොදන්න රටක, නොදන්න අම්මා කෙනෙක්, මාව ආයේ දකින්න වෙන්නේ නෑ කියලා ඒ විදිහට දුක් වෙලා අඬයි කියලා මම බලාපොරොත්තු උනේ නෑ. මගේ ඇහෙනුත් ඉබේටම කඳුලක් වැටුණා.
ඇයගේ ඊමේල් ලිපිනයක් වත්, දුරකථන අංකයක් වත් මට ඉල්ල ගන්න බැරි උනා. අඩුම තරමින් ඇගේ නම වත් මට හරියට මතක හිටලා තිබෙබේ නෑ. ඈ නම නම් මුල් දවසේ කිව්ව. හුරු නමක් නෙවෙයි මතක හිටින්න.
දැන් මම ලංකාවට ඇවිත් සෑහෙන කල්. ඒත් ඉඳලා හිටලා මට තාම ඒ වයසක මණුස්සයාව මතක් වෙනවා. ඒ වෙනකොටත් එයාට අසූව පැනලා. දැන් ඉන්නවා ද දන්නෙත් නෑ. පව්..
Thursday, June 16, 2011
Advocating and Opposing Agile for the wrong reasons
Development processes have fundamental problems they address, a philosophy by which they try to solve that problem and methods by which they implement that philosophy.
Problem that Agile solves is ever changing requirements of enterprise applications.
There are those who laugh at Agile for how awfully it would fail in building an air plane (technically speaking, proper agile will not fail, but it’s not at all the correct process to use there) and then go try to make an information system to a galactic government using a formal process and fail even more miserably. (I wanted to say kite, but wanted to emphasize size is not the problem). And this goes vice versa.
Smart project teams chose the right process for the right project. They don’t brand themselves as agile or formal. They are simply good engineers who are good at applying proper solution for the problem at hand right from the process itself.
Problem that Agile solves is ever changing requirements of enterprise applications.
There are those who laugh at Agile for how awfully it would fail in building an air plane (technically speaking, proper agile will not fail, but it’s not at all the correct process to use there) and then go try to make an information system to a galactic government using a formal process and fail even more miserably. (I wanted to say kite, but wanted to emphasize size is not the problem). And this goes vice versa.
Smart project teams chose the right process for the right project. They don’t brand themselves as agile or formal. They are simply good engineers who are good at applying proper solution for the problem at hand right from the process itself.
Tuesday, June 14, 2011
How’s your agile process working for you?
Are you practicing an agile process in your team? Do you still find your team working through the night? Do you still find your software to be rigid, fragile and immobile? Do you still find changes of requirements to be nightmares to the developers? How do you suppose those situations are possible with an Agile process?
Unfortunately, this is the situation in almost all Agile practicing and Agile preaching companies we have around in Sri Lanka. I’ve crossed my paths with quite a few developers from these companies and they all have the same story to tell; agile for them, is the same old cycle, without the documentation and without a designing phase - which makes their development life worse. Non-technical project managers are still around, being called by other names, and to add to the misery, now the customers bring the pressure directly to the developer - because it’s “Agile”.
Is Agile a bad idea? What’s going wrong? Why can’t we make it work? Have you seen the list of names in the Agile manifesto at http://agilemanifesto.org/? Do you think those are the kind of people who would invest on a failing process? Besides, they’ve been practicing and teaching it for over a decade now. So if there’s anything wrong with Agile, it’s more likely in the way we practice it.
Management elements such as deadlines, budgets and sucking up to customers’ aside, we developers too need to change some fundamental ideologies towards development in order to make Agile, well Agile. It is not to say that the operational model doesn’t matter, indeed, that’s what makes Agile possible. Someone should be available to the team to represent the customer, acceptance tests should be automated and made available to the developers when feature requests / changes are made; team should be responding to changes than follow a plan; team should be able focus on getting a working product out instead of documenting etc. etc. which all agile gurus will tell you; but the part they don’t speak about; the part the folks came up with agile manifesto took for granted; the part that is responsible for more than half the agile failures in Sri Lanka is with the developers.
One misconception most developers in Sri Lanka have about Agile development is, it is coding without design or documentation. The other misconception is to think getting software to “work” means getting the functionality out one way or another. The Agile philosophy has very different interpretations for these and is defined with the implied expectation of strong object oriented concepts and design principles of the developers.
By the term “a working product” what’s meant is a functional, testable and maintainable product. Not just functional. If a piece of code provides the functionality required, but only the developer himself could read and understand how it does that, it is not a working product by Agile definitions. Developers are to get the code to work and then refactor till it’s readable, not duplicating code and as simple as it could be but not simpler.
Refactoring to make code readable, non-duplicative, simple and free of unused design complexities and code is a constant practice that developers are expected to follow whenever they code something.
The design focus of Agile is much more implied than explicit. In each iteration, Agile focus on getting a working product to the customer. The team narrows their focus only on the features that are planned for that iteration making it as simple and expressive as possible; yet not losing the overall picture - or at least what exist of it at the time. This practice makes sure that the design never gets complicated than necessary and serves to the problem at hand than expected (but volatile) problems of the future. One of the problems in designing the whole application at once is that the architect is force to foresee requirements of the future; with requirements ever changing and little understanding of them to begin with; this is not a task someone could get 100% right. That’s why Agile promotes this simplistic approach which could accommodate changes more easily.
Unit Tests for agile developers are a design practice than a verification step. Writing the non-compiling unit test is defining the contract for a component. Developer should do due diligence and consider who are the consumers and think how the consumers would want to use a class. Note that the tests are written for the public interface of the class, the tests care only about the functionality exposed through that. Once the developer get the unit tests to pass, he can then go on refactoring his code to be simple, readable and non-duplicative - one step at a time - without worrying about breaking the functionality unknowingly; because the tests are there to guard against that.
The next aspect of design developers ignore in Agile is how exactly the changes are accommodated. Remember that agile designs are as simple as possible meaning that when code is first written, it is not accommodating flexibility for “potential” change. But when the first change comes, the developers should follow the object oriented design principles and separate the changing elements of code from the non-changing elements of code, evolving the design in that part, so that a second change in the same area would be easier and simpler than the first. This practice prevents the code becoming stale over repeated changes, still keeping the code as simple as possible.
As always, developers should keep themselves up to date not only with the new technologies but of the time proven concepts; and the organizations who wish to harness the benefits of any methodology should invest on getting their developers in par with that methodology.
References
Agile Principles, Patterns, and Practices in C# By Robert C. Martin, Micah Martin
Agile Software Development: The Cooperative Game, Second Edition By Alistair Cockburn
Test-Driven Development By Example By Kent Beck
Unfortunately, this is the situation in almost all Agile practicing and Agile preaching companies we have around in Sri Lanka. I’ve crossed my paths with quite a few developers from these companies and they all have the same story to tell; agile for them, is the same old cycle, without the documentation and without a designing phase - which makes their development life worse. Non-technical project managers are still around, being called by other names, and to add to the misery, now the customers bring the pressure directly to the developer - because it’s “Agile”.
Is Agile a bad idea? What’s going wrong? Why can’t we make it work? Have you seen the list of names in the Agile manifesto at http://agilemanifesto.org/? Do you think those are the kind of people who would invest on a failing process? Besides, they’ve been practicing and teaching it for over a decade now. So if there’s anything wrong with Agile, it’s more likely in the way we practice it.
Management elements such as deadlines, budgets and sucking up to customers’ aside, we developers too need to change some fundamental ideologies towards development in order to make Agile, well Agile. It is not to say that the operational model doesn’t matter, indeed, that’s what makes Agile possible. Someone should be available to the team to represent the customer, acceptance tests should be automated and made available to the developers when feature requests / changes are made; team should be responding to changes than follow a plan; team should be able focus on getting a working product out instead of documenting etc. etc. which all agile gurus will tell you; but the part they don’t speak about; the part the folks came up with agile manifesto took for granted; the part that is responsible for more than half the agile failures in Sri Lanka is with the developers.
One misconception most developers in Sri Lanka have about Agile development is, it is coding without design or documentation. The other misconception is to think getting software to “work” means getting the functionality out one way or another. The Agile philosophy has very different interpretations for these and is defined with the implied expectation of strong object oriented concepts and design principles of the developers.
By the term “a working product” what’s meant is a functional, testable and maintainable product. Not just functional. If a piece of code provides the functionality required, but only the developer himself could read and understand how it does that, it is not a working product by Agile definitions. Developers are to get the code to work and then refactor till it’s readable, not duplicating code and as simple as it could be but not simpler.
Refactoring to make code readable, non-duplicative, simple and free of unused design complexities and code is a constant practice that developers are expected to follow whenever they code something.
The design focus of Agile is much more implied than explicit. In each iteration, Agile focus on getting a working product to the customer. The team narrows their focus only on the features that are planned for that iteration making it as simple and expressive as possible; yet not losing the overall picture - or at least what exist of it at the time. This practice makes sure that the design never gets complicated than necessary and serves to the problem at hand than expected (but volatile) problems of the future. One of the problems in designing the whole application at once is that the architect is force to foresee requirements of the future; with requirements ever changing and little understanding of them to begin with; this is not a task someone could get 100% right. That’s why Agile promotes this simplistic approach which could accommodate changes more easily.
Unit Tests for agile developers are a design practice than a verification step. Writing the non-compiling unit test is defining the contract for a component. Developer should do due diligence and consider who are the consumers and think how the consumers would want to use a class. Note that the tests are written for the public interface of the class, the tests care only about the functionality exposed through that. Once the developer get the unit tests to pass, he can then go on refactoring his code to be simple, readable and non-duplicative - one step at a time - without worrying about breaking the functionality unknowingly; because the tests are there to guard against that.
The next aspect of design developers ignore in Agile is how exactly the changes are accommodated. Remember that agile designs are as simple as possible meaning that when code is first written, it is not accommodating flexibility for “potential” change. But when the first change comes, the developers should follow the object oriented design principles and separate the changing elements of code from the non-changing elements of code, evolving the design in that part, so that a second change in the same area would be easier and simpler than the first. This practice prevents the code becoming stale over repeated changes, still keeping the code as simple as possible.
As always, developers should keep themselves up to date not only with the new technologies but of the time proven concepts; and the organizations who wish to harness the benefits of any methodology should invest on getting their developers in par with that methodology.
References
Agile Principles, Patterns, and Practices in C# By Robert C. Martin, Micah Martin
Agile Software Development: The Cooperative Game, Second Edition By Alistair Cockburn
Test-Driven Development By Example By Kent Beck
Sunday, June 12, 2011
Sunday, May 29, 2011
Saturday, May 28, 2011
The specification of a method
Sometime back I read Alan Shalloway’s wonderful book “Design Patterns Explained: A New Perspective on Object-Oriented Design” which I think makes a wonderful pre-read for anyone who’s going to read the GoF design patterns book. But even if you’ve already read the GoF, like I had, Alan’s book still is a good read.
In that book, Alan brings the point that any object oriented software component should be looked at in three different perspectives,
At any given level of abstraction - application | component | package | class | method - this stands true and is very important to separate these concerns in designing at each level.
I'd like to give a thought on how this is applicable at the level of a method. Let’s take an example to make things easier to understand. A method that converts a string to a number.
What is the responsibility?
Convert a string to a number of cause, but does that statement describe everything?
What’s the contract?
Defining the contract is the step which is going to make the responsibility of the method more explicit, and define the explicit usage of the method.
What are the parameters the method would take? Just the string to be converted? Should it get control parameters?
What’s the format of the string should be?
What would the method return if the format is incorrect? Would it return a default value? Would it throw an exception (what type of exception) or would it return null?
What type is the number? Integer or float? Could it be both? If so, how would the method return it?
What’s the implementation?
We should only get at this once we have the answers to the above two questions. And our implementation should depend on them, the responsibility or the contract should not change by our implementation - remember the dependency inversion principle!
So why is this post called “The specification of a method”? Because that’s where I’d like to focus for the rest of this post. That’s where I see room for a lot of improvements.
How exactly do we define the contract for a method after we do have the answers to the questions like what we saw above? It should all end up in the method signature. But, most languages only allow us to specify parameters and return types; so how do we communicate exceptions and whether a method would return null or not?
Java is a language that goes one step further and offer checked exceptions that allow us to express in the method signature what type of exceptions are thrown by the method; which I learned to appreciate only very recently. That’s a feature which make sure an application will not ever crash due to an unhandled exception, by making method contracts explicit.
That’s one good example that making the contract explicit contributes directly towards application stability and better coding practice. (But there are debates on whether this is a good thing or a bad thing - I think it is good.)
How do we do this in .NET? We could add the exception details in the XML comment documentation. But that’s not as good as the compiler mandate of java.
The other part of the signature which we miss a lot is conveying the fact whether a method would return null or not. We see quite a few null reference exceptions and quite a few null checks on methods that do not return nulls than we would like to in our day-today life. Some argue that it’s a “good” practice to check null even if a return value cannot be null. But that’s a pretty lame claim isn't it?
There are two ways that I could think of to overcome this. Obviously we can comment if a null value is returned by the method. But there’s no guarantee that someone someday would forget the comment and would not check null. The much thoughtful approach is to implement the Special Case pattern (PoEAA). In which, separate implementations are given to such anomalies as null for the same interface, so that the consumer need not worry about exceptions. But, it’s a design decision that has to be taken much earlier than you start to design method signatures.
Regardless of how we are going to handle these information in the method signatures, if we do define them upfront and communicate to the consumers of the method (and of cause stick to that contract within the implementation) we are bound to improve stability and the quality of code in our applications.
In that book, Alan brings the point that any object oriented software component should be looked at in three different perspectives,
- Concept - which is the responsibility of that particular component (i.e. what it’s supposed to do)
- Specification - which is the contract with the external entities (i.e. how it would be used)
- Implementation - which is how that component is actually going to get the job done.
At any given level of abstraction - application | component | package | class | method - this stands true and is very important to separate these concerns in designing at each level.
I'd like to give a thought on how this is applicable at the level of a method. Let’s take an example to make things easier to understand. A method that converts a string to a number.
What is the responsibility?
Convert a string to a number of cause, but does that statement describe everything?
What’s the contract?
Defining the contract is the step which is going to make the responsibility of the method more explicit, and define the explicit usage of the method.
What are the parameters the method would take? Just the string to be converted? Should it get control parameters?
What’s the format of the string should be?
What would the method return if the format is incorrect? Would it return a default value? Would it throw an exception (what type of exception) or would it return null?
What type is the number? Integer or float? Could it be both? If so, how would the method return it?
What’s the implementation?
We should only get at this once we have the answers to the above two questions. And our implementation should depend on them, the responsibility or the contract should not change by our implementation - remember the dependency inversion principle!
So why is this post called “The specification of a method”? Because that’s where I’d like to focus for the rest of this post. That’s where I see room for a lot of improvements.
How exactly do we define the contract for a method after we do have the answers to the questions like what we saw above? It should all end up in the method signature. But, most languages only allow us to specify parameters and return types; so how do we communicate exceptions and whether a method would return null or not?
Java is a language that goes one step further and offer checked exceptions that allow us to express in the method signature what type of exceptions are thrown by the method; which I learned to appreciate only very recently. That’s a feature which make sure an application will not ever crash due to an unhandled exception, by making method contracts explicit.
That’s one good example that making the contract explicit contributes directly towards application stability and better coding practice. (But there are debates on whether this is a good thing or a bad thing - I think it is good.)
How do we do this in .NET? We could add the exception details in the XML comment documentation. But that’s not as good as the compiler mandate of java.
The other part of the signature which we miss a lot is conveying the fact whether a method would return null or not. We see quite a few null reference exceptions and quite a few null checks on methods that do not return nulls than we would like to in our day-today life. Some argue that it’s a “good” practice to check null even if a return value cannot be null. But that’s a pretty lame claim isn't it?
There are two ways that I could think of to overcome this. Obviously we can comment if a null value is returned by the method. But there’s no guarantee that someone someday would forget the comment and would not check null. The much thoughtful approach is to implement the Special Case pattern (PoEAA). In which, separate implementations are given to such anomalies as null for the same interface, so that the consumer need not worry about exceptions. But, it’s a design decision that has to be taken much earlier than you start to design method signatures.
Regardless of how we are going to handle these information in the method signatures, if we do define them upfront and communicate to the consumers of the method (and of cause stick to that contract within the implementation) we are bound to improve stability and the quality of code in our applications.
Sunday, May 22, 2011
Vesak is a Carnival
Seems it's finally over. There were insane number of people on the streets last week and traffic was horrible.
Apart from the traditional lanterns and lights, there were quite a few drunk men on the streets doing all sorts of drunken stuff and generally being assholes. I saw couple of musical shows, and a Ferris wheel in Dematagoda as well. Good Carnival, I thought - may be we'd compete with Rio someday and attract tourists.
I highly doubt, Buddha, the person who preached of simplicity and being unmoved by eight worldly dhammas would have appreciated this "carnival" and public menace to celebrate his birthday and attaining nibbana.
But who knows, Sinhala Buddhists(TM) have a strange way of practicing Buddhism...
Thursday, April 14, 2011
Black and White Portraits
It's been a while since I made a post in this blog, and I've realized now that separating photo blogging from regular blogging is not going to be practical.. so.. here we go..
Wednesday, April 13, 2011
The $10 extension tube is worth the money
It's worth for $10, compared to Nikon 105mm f/2.8G ED-IF AF-S VR Micro-Nikkor Lens for $1000.. (Heck, it was less than $800 last year.. the price go up as if it's made of gold..)
I attached the 50mm f/1.8D to it's end (It was $107 when I bought it in 2008, now it's $160.. insane!). You'll need a lens with an aperture ring (not a G) or the lens would be stuck at the lowest aperture and you won't be able to get any light in. Also, a zoom would be a bad idea due to reasons I point below. 50mm f/1.4D or the 85mm f/1.4D would be slightly better, but the 50mm f/1.8D is the most cost effective.
It's really really difficult to capture something that moves with this extension tube on, and you almost always need strobes to light the subjects. The thing is, with this thing attached, the effective focal length is probably something like 150~160mm and effective aperture at F/1.8 at the lens is probably around F/6, I don't know.. do your math.. anyhow, the DOF is razor thin at F/1.8, and at F/8 and up when you start to get a decent DOF (by decent I mean something like below, the above shots were at F/16 and up) You virtually can't see the subject through the view finder without holding a flashlight at the subject..
(I shot all these at ISO 100, 1/200s and SB600 at full power from side and on camera flash at full power)
And it only focus to like couple of inches to the front of the lens, you can't do much other than shooting small insects and flowers..
I focus by moving the camera back and forth than moving the focus ring as that shifts the frame dramatically.
So, you get my point right? It's not an alternative for a $1000 solution at $10.. but, within a pretty limited scope, you can achieve some amazing results with it.
I bought it on ebay, but here's the amazon link.
There are much expensive tubes with auto focus. But, all you get for that extra money is auto focus, proper metering and aperture reported on your exif. But the limitations in DOF and focus distance would still be there.. At that point, you might just as well throw some cash on a cheap macro lens.
I attached the 50mm f/1.8D to it's end (It was $107 when I bought it in 2008, now it's $160.. insane!). You'll need a lens with an aperture ring (not a G) or the lens would be stuck at the lowest aperture and you won't be able to get any light in. Also, a zoom would be a bad idea due to reasons I point below. 50mm f/1.4D or the 85mm f/1.4D would be slightly better, but the 50mm f/1.8D is the most cost effective.
It's really really difficult to capture something that moves with this extension tube on, and you almost always need strobes to light the subjects. The thing is, with this thing attached, the effective focal length is probably something like 150~160mm and effective aperture at F/1.8 at the lens is probably around F/6, I don't know.. do your math.. anyhow, the DOF is razor thin at F/1.8, and at F/8 and up when you start to get a decent DOF (by decent I mean something like below, the above shots were at F/16 and up) You virtually can't see the subject through the view finder without holding a flashlight at the subject..
(I shot all these at ISO 100, 1/200s and SB600 at full power from side and on camera flash at full power)
And it only focus to like couple of inches to the front of the lens, you can't do much other than shooting small insects and flowers..
I focus by moving the camera back and forth than moving the focus ring as that shifts the frame dramatically.
So, you get my point right? It's not an alternative for a $1000 solution at $10.. but, within a pretty limited scope, you can achieve some amazing results with it.
I bought it on ebay, but here's the amazon link.
There are much expensive tubes with auto focus. But, all you get for that extra money is auto focus, proper metering and aperture reported on your exif. But the limitations in DOF and focus distance would still be there.. At that point, you might just as well throw some cash on a cheap macro lens.
Sunday, February 20, 2011
Sunday, February 13, 2011
නුඹ මගේ වන්නට...
රන් හුයක් අවැසිද දෑඟිලි බඳින්නට
අත පැන් අවැසිද ප්රේමය හඟින්නට
පෝරුවක් අවැසිද හදවත් බැඳෙන්නට
අත්සනක් අවැසිද නුඹ මගේ වන්නට
Sunday, January 09, 2011
It’s time you stop masturbating and go have the orgy of your life...
Rationalists, secularists, Humanists, Agnostics, Atheists and all the free thinking intellectuals and scholars of our time in Sri Lanka, seem to be hiding behind anonymity of internet and closed doors of “punchi theater” in Borella when they masturbate (alone or as a group) about their intelligence and the ability to comprehend things independent of religion and tribalism. They all seem to be afraid of the confrontations they may face if they speak in public.
They speak of Richard Dawkins, Mark Twain and all the western leaders of such intellectual circles; they speak of intellectuals from last generation of Sri Lanka, like Senaka Bibile and Osmond Jayaratne, but where are the intellectuals of this generation who go out there to speak to the public about this revolution that has to happen?
We need independence from tribalism, we need governance separated from religion, and we need to move forward from cultural dogma; but who’s taking this message to the masses? Does a blog that gets couple of thousand hits per day do that? While those Rationalists and Secularists hide behind blogs and forums, Likes of Kiribathgoda Gnanananda, Champika Ranawaka, T B Ekanayake and Mahinda Rajapaksha are among the masses, brain washing them to make the Sinhala Buddhist Taliban in Sri Lanka.
So I say it’s time you bunch stop masturbating and go out in public to have your orgy.
They speak of Richard Dawkins, Mark Twain and all the western leaders of such intellectual circles; they speak of intellectuals from last generation of Sri Lanka, like Senaka Bibile and Osmond Jayaratne, but where are the intellectuals of this generation who go out there to speak to the public about this revolution that has to happen?
We need independence from tribalism, we need governance separated from religion, and we need to move forward from cultural dogma; but who’s taking this message to the masses? Does a blog that gets couple of thousand hits per day do that? While those Rationalists and Secularists hide behind blogs and forums, Likes of Kiribathgoda Gnanananda, Champika Ranawaka, T B Ekanayake and Mahinda Rajapaksha are among the masses, brain washing them to make the Sinhala Buddhist Taliban in Sri Lanka.
So I say it’s time you bunch stop masturbating and go out in public to have your orgy.
Subscribe to:
Posts (Atom)