Thursday, September 22, 2005
Cyclomatic Code Complexity Analysis ( Microsoft.NET Applications )
There are two key areas that we focus on when choosing code for review:
Functionality that is important to the proper operation of the system (e.g. core frameworks, unique algorithms, performance-critical code, etc.).
Code that has a high complexity
As an example, most of our data types inherit from a base type that provides a lot of common functionality. Because of its placement in the hierarchy, it is important that our base type functions in a consistent, reliable, and expected manner. Example of core functionality that is required for correct system operation. For other code, we need to rely on code complexity measurements.
Having said that how do we analyse code complexity and how its going to be one of the objective of the code review process?
If this is the question on your mind, here is one of the way you can opt for.
Cyclomatic Code Complexity Analysis ( Microsoft.NET Applications )
There are several ways to measuring complexity (data complexity, module coupling, algorithmic complexity, calls-to and called-by, etc.. ). Although these other methods are effective in the right context, it seems to be generally accepted that control flow is one of the most useful measurements of complexity, and high complexity scores have been shown to be a strong indicator of low reliability and frequent errors.
Cyclomatic Code Complexity is based on the Tom McCabe's work and is defined by the codes control flow.
Start with 1 for the straight path through the routine
Add 1 for each of the following keywords or their equivalents: if, while, repeat, for, and, or
Add 1 for each case in a case statement
So, if we have this C# example:
while (nextPage != true)
{
if ((lineCount <= linesPerPage) && (status != Status.Cancelled) && (morePages == true))
{
// ...
}
}
In the code above, we start with 1 for the routine, add 1 for the while, add 1 for the if, and add 1 for each && for a total calculated complexity of 5. Anything with a greater complexity than 10 or so is an excellent candidate for simplification and refactoring. Minimizing complexity is a great goal for writing high-quality, maintainable code.
Some advantages of McCabe's Cyclomatic Complexity include:
It is very easy to compute, as illustrated in the example
Can be computed immediately in the development lifecycle (which makes it friendly)
It provides a good indicator of the ease of code maintenance
It can help focus testing efforts
It makes it easy to find complex code for formal review
It is important to note that a high complexity score does not automatically mean that code is bad. However, it does highlight areas of the code that have the potential for error. The more complex a method is, the more likely it is to contain errors, and the more difficult it is to completely test. Now check the Project/SEI risk assessment matrix for value of code , and decide which code needs refactoring.
Good luck and hope this works for you and your team.
Source: Fowler, Martin. 1999. Refactoring: Improving the Design of the Existing Code Boston: Addison-Wesley. (refer this book for more details)
Friday, September 16, 2005
Microsoft in AOL Talks
Thursday, September 15, 2005
Google now has search for blogs
Friday, September 09, 2005
Something to ponder
-Calvin and Hobbes
Life is a sexually transmitted disease, and it's 100% fatal.
I either want less corruption, or more chance to participate in it.
-Ashleigh Brilliant
In the beginning the Universe was created.
This has made a lot of people very angry and been widely regarded as a bad move."
-Douglas Adams, "The Hitchhiker's Guide to the Galaxy"
"Love is like an hourglass, with the heart filling up as the brain empties."
Jules Renard
"Everything that exists in your life, does so because of two things: something you did or something you didn't do."
-Albert Einstien
I am an old man and have known many troubles, but most of them never happened. -Mark Twain
"The object of war is not to die for your country but to make the other bastard die for his."
- General George Patton
Pray, n:. To ask that the laws of the universe be annulled in behalf of a single petitioner confessedly unworthy."
- Ambrose Bierce
A great many people think they are thinking when they are merely rearranging their prejudices. -William James
Paranoia is just a higher form of awareness. -Charles Manson
Good people will do good things. Evil people will do evil things. But for good people to do evil things, that takes religion. -Steven Weinberg
Thursday, September 08, 2005
Steve Jobs Speaks at Stanford Commencement
Both Text and audio available here
Key lines
* Don't let the noise of other's opinions drown out your own inner voice
* Have the courage to follow your heart and intuition. They somehow already know what you truly want to become
Speech Transcript:
I am honored to be with you today at your commencement from one of the finest universities in the world. I never graduated from college. Truth be told, this is the closest I've ever gotten to a college graduation. Today I want to tell you three stories from my life. That's it. No big deal. Just three stories.
The first story is about connecting the dots.
I dropped out of Reed College after the first 6 months, but then stayed around as a drop-in for another 18 months or so before I really quit. So why did I drop out?
It started before I was born. My biological mother was a young, unwed college graduate student, and she decided to put me up for adoption. She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife. Except that when I popped out they decided at the last minute that they really wanted a girl. So my parents, who were on a waiting list, got a call in the middle of the night asking: "We have an unexpected baby boy; do you want him?" They said: "Of course." My biological mother later found out that my mother had never graduated from college and that my father had never graduated from high school. She refused to sign the final adoption papers. She only relented a few months later when my parents promised that I would someday go to college.
And 17 years later I did go to college. But I naively chose a college that was almost as expensive as Stanford, and all of my working-class parents' savings were being spent on my college tuition. After six months, I couldn't see the value in it. I had no idea what I wanted to do with my life and no idea how college was going to help me figure it out. And here I was spending all of the money my parents had saved their entire life. So I decided to drop out and trust that it would all work out OK. It was pretty scary at the time, but looking back it was one of the best decisions I ever made. The minute I dropped out I could stop taking the required classes that didn't interest me, and begin dropping in on the ones that looked interesting.
It wasn't all romantic. I didn't have a dorm room, so I slept on the floor in friends' rooms, I returned coke bottles for the 5¢ deposits to buy food with, and I would walk the 7 miles across town every Sunday night to get one good meal a week at the Hare Krishna temple. I loved it. And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. Let me give you one example:
Reed College at that time offered perhaps the best calligraphy instruction in the country. Throughout the campus every poster, every label on every drawer, was beautifully hand calligraphed. Because I had dropped out and didn't have to take the normal classes, I decided to take a calligraphy class to learn how to do this. I learned about serif and san serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great. It was beautiful, historical, artistically subtle in a way that science can't capture, and I found it fascinating.
None of this had even a hope of any practical application in my life. But ten years later, when we were designing the first Macintosh computer, it all came back to me. And we designed it all into the Mac. It was the first computer with beautiful typography. If I had never dropped in on that single course in college, the Mac would have never had multiple typefaces or proportionally spaced fonts. And since Windows just copied the Mac, its likely that no personal computer would have them. If I had never dropped out, I would have never dropped in on this calligraphy class, and personal computers might not have the wonderful typography that they do. Of course it was impossible to connect the dots looking forward when I was in college. But it was very, very clear looking backwards ten years later.
Again, you can't connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future. You have to trust in something - your gut, destiny, life, karma, whatever. This approach has never let me down, and it has made all the difference in my life.
My second story is about love and loss.
I was lucky Ð I found what I loved to do early in life. Woz and I started Apple in my parents garage when I was 20. We worked hard, and in 10 years Apple had grown from just the two of us in a garage into a $2 billion company with over 4000 employees. We had just released our finest creation - the Macintosh - a year earlier, and I had just turned 30. And then I got fired. How can you get fired from a company you started? Well, as Apple grew we hired someone who I thought was very talented to run the company with me, and for the first year or so things went well. But then our visions of the future began to diverge and eventually we had a falling out. When we did, our Board of Directors sided with him. So at 30 I was out. And very publicly out. What had been the focus of my entire adult life was gone, and it was devastating.
I really didn't know what to do for a few months. I felt that I had let the previous generation of entrepreneurs down - that I had dropped the baton as it was being passed to me. I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly. I was a very public failure, and I even thought about running away from the valley. But something slowly began to dawn on me Ð I still loved what I did. The turn of events at Apple had not changed that one bit. I had been rejected, but I was still in love. And so I decided to start over.
I didn't see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me. The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything. It freed me to enter one of the most creative periods of my life.
During the next five years, I started a company named NeXT, another company named Pixar, and fell in love with an amazing woman who would become my wife. Pixar went on to create the worlds first computer animated feature film, Toy Story, and is now the most successful animation studio in the world. In a remarkable turn of events, Apple bought NeXT, I retuned to Apple, and the technology we developed at NeXT is at the heart of Apple's current renaissance. And Laurene and I have a wonderful family together.
I'm pretty sure none of this would have happened if I hadn't been fired from Apple. It was awful tasting medicine, but I guess the patient needed it. Sometimes life hits you in the head with a brick. Don't lose faith. I'm convinced that the only thing that kept me going was that I loved what I did. You've got to find what you love. And that is as true for your work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.
My third story is about death.
When I was 17, I read a quote that went something like: "If you live each day as if it was your last, someday you'll most certainly be right." It made an impression on me, and since then, for the past 33 years, I have looked in the mirror every morning and asked myself: "If today were the last day of my life, would I want to do what I am about to do today?" And whenever the answer has been "No" for too many days in a row, I know I need to change something.
Remembering that I'll be dead soon is the most important tool I've ever encountered to help me make the big choices in life. Because almost everything Ð all external expectations, all pride, all fear of embarrassment or failure - these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart.
About a year ago I was diagnosed with cancer. I had a scan at 7:30 in the morning, and it clearly showed a tumor on my pancreas. I didn't even know what a pancreas was. The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months. My doctor advised me to go home and get my affairs in order, which is doctor's code for prepare to die. It means to try to tell your kids everything you thought you'd have the next 10 years to tell them in just a few months. It means to make sure everything is buttoned up so that it will be as easy as possible for your family. It means to say your goodbyes.
I lived with that diagnosis all day. Later that evening I had a biopsy, where they stuck an endoscope down my throat, through my stomach and into my intestines, put a needle into my pancreas and got a few cells from the tumor. I was sedated, but my wife, who was there, told me that when they viewed the cells under a microscope the doctors started crying because it turned out to be a very rare form of pancreatic cancer that is curable with surgery. I had the surgery and I'm fine now.
This was the closest I've been to facing death, and I hope its the closest I get for a few more decades. Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept:
No one wants to die. Even people who want to go to heaven don't want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Life's change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true.
Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma - which is living with the results of other people's thinking. Don't let the noise of other's opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.
When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the bibles of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 1960's, before personal computers and desktop publishing, so it was all made with typewriters, scissors, and polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along: it was idealistic, and overflowing with neat tools and great notions.
Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: "Stay Hungry. Stay Foolish." It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you.
Stay Hungry. Stay Foolish.
Thank you all very much.
Wednesday, September 07, 2005
Something to ponder
When i went to open the door, there was no one there.
We should act in spite of fear and not because of fear.
Friday, September 02, 2005
Something to keep in mind
Tuesday, August 09, 2005
Email in the Enterprise
Friday, August 05, 2005
First Windows Vista Virus Appears
Wednesday, July 06, 2005
Saturday, June 25, 2005
Stored Procedure Invocation Code Generator for VB, C# and JScript.NET:
A great tool that can cut development time multifold, by creating the a sample xml document and defining the name of the stored procedure and its parameters, then assiciate the XML to the custom tool (as part of the install), it will automatically generate the code to call the stored procedure as though it was a class. Download the software and code here
The only disadvantage i have found(dont claim that ive read the entire document /source code to check for bypass) is that we have to specify the DB server name in the XML document. So once we move to a staging server or deployment server then we will have to modify the server name again. I guess you can overcome the limitation by modifying the source code.
All in all *great tool*, will post additional details once i try out the software, can save your project loads of time.
Sunday, June 19, 2005
Friday, June 17, 2005
BILL GATES :
Why do you think, in this time of great technological advancement, people are still working harder and not smarter?
One of the greatest opportunities today is for software to more closely mirror the way people want to work, so they can focus on getting things done rather than managing all the technology in their lives, searching for the information they need, or adapting how they work to how their computer works. I believe the productivity breakthroughs we’ll see in the next decade will be as significant as those we’ve achieved in the past quarter-century.
How do you feel about competing open source platforms such as Unix and Linux?
The software ecosystem can accommodate many different development models, and healthy competition is what produces new innovations and drives technology forward. We focus our efforts on developing products based on the commercial model, which we believe produces the best possible software for our customers.
Thursday, June 16, 2005
What is XP:
eXtreme Programming is a lightweight methodology (see other lightweigh methodologies here), XP is a methodology that is used to delivery software to your customers needs when its needed. XP empowers your developers to confidently respond to changing customer requirements, even late in the life cycle.XP implements a simple, yet effective way to enable groupware style development. XP is a disciplined approach to developing software. XP is successful because it stresses on customer satisfaction.
The methodology emphasizes on team work, from the developers , managers and the client. XP was intended for small project groups but there are examples of projects of 100 members that have used XP eg Though Works. The methodology is a collection of rules, each rule supporting the other rules.
The tenets of XP:
1. Simplicity
2. Communication
3. Feedback
4. Courage
Role of a developer:
One of the key tasks of a developer is refactoring ie thats a task that the client and the managers cannot enforce , only the developer/designer can do so. The programmer is also reasponsible for creating high quality code by
a) pair programming approach
b) refactoring
c) creating test cases before creating code.
XP has 4 phases :
1) Planning
2) Designing
3) Coding
4) Testing
Planning Phase:
User stories: It serves multiple purposes, it can be used instead of a requirement document , the IT integrator can use the document as an estimator and use it for release planning, the document is written by the client in non -technology terms, the client can use the document to derive the user acceptance tests. Once the big picture is created the individual developers go to the client and then get the details of the sub stories and document the same as user requirements, if a user story takes more than 3 weeks then a new story is created
XP uses iterative development process so that the project can get the agility of a change process.
A caterpillar is perfectly designed to eat vast amounts of foliage but he can't find a mate, he must refactor himself into a butterfly before he is designed to search the sky for others of his own kind. Let go of your notions of what the system should or should not be and try to see the the new design as it emerges before you
- Kent Beck
Sunday, June 12, 2005
A chain is only as strong as its weakest link, lets face it in a fast moving economy and dog -eat -dog world .. the weakest link to any enterprise is its workforce. Humans are good decission makes, only if they have the will and interest to make an optimal decission and considering that they cannot make decessions 24x7, wouldnt it be better for an Enterprise to hand that job to a machine ? Evolution ! in the way that the enterprise works, the enterprise now can be a 24x7 money making, decession conscious entity that can work optimally. The system doesnt require sleep, it doesnt have to be out of the office .. doenst have to do the laundry ;) and it doesnt require a raise in the pay cheque :D.
Business could really be "business at the speed of thought" well this time that of a machine, and for thought that can be a simple programmed decission well and machine can defanitely beat any carbon based lifeform.
In the present times when IT system have evolved from basic Mainframe technologies sitting in an isolated room to Grid networks ... IT has defanitely come a long way in a short time (no pun intended there ) but then we have islands of data .. islands every where .. there is no single version of the truth , different systems different data - a different view of the truth, its a bird ... no its a plane... not its DataWarehousing to the rescue !!! well even data level integration doesnt seem to work these days ... we need another means to look at an enterprise level in a holistic view and the answer to that is Business process integration, using Integration techologies. BPI .. the wave of the future.
