Thursday, December 30, 2010

Tuesdays with Morrie

I have heard a lot about this book by Mitch Albom and so when I saw this book in my library, I thought I should give it a try. While there are numerous books with the same theme - life is more than just materialistic pursuits and happiness is beyond your salary and designation, I think what makes this book different from others is that this is a real life, true story.  As any reader of self-help book would readily agree, most of the tips in such books are easier said than done. That the author's teacher actually walked the talk and really believed in the different traits that he shared with the author is what makes this special.  Surely this book is not for someone who is looking for tips to change his life overnight, but is clearly a definite read for those who already have similar thoughts in life and are looking for real life examples of people who live the life the way they want, irrespective of numerous hurdles and distractions. 

Wednesday, December 29, 2010

C++ Common Knowledge

Inspired by my friend Ranjit's web-site, I have also decided to give it a try and make jot down some notes on the books that I read, both technical and non-technical. Here it comes.

My first attempt is C++ Common Knowledge by Stephen C.Dewhurst. The blurb on the back page of this book says that this book is for you "if you've had some experience in C++ programming, but reading intermediate and advanced C++ is slow-going". I will have to agree with this assessment. The book intends to list of out some essential tips and practices for professional C++ programmers and clearly achieves it.  One word of caution -- As there are no exercises at the end of the chapters, we need to resist the temptation to just flip the pages and treat it as a light read, the contents have to be chewed and digested for maximum benefit.

The book has a total of 61 chapters and of these, I felt I have learned something new (or presented something I knew in a new way) from quite a few of these chapters. I skipped the STL related common senses as I thought I need to get some "basic sense" of STL before learning advanced "common sense".

For those who already are familiar with a lot of these, this book presents enormous opportunity for composing C++ interview questions, if not anything else :)

Of the chapters I did read, here are some notes:
  1. Chapter 11. "You do not get what you see". I have never assumed the location of the virtual function table pointer or other data members in a class and I was amused to see that some people try to get into that detail. Nevertheless, the fact that compiler can possibly rearrange the data members, irrespective of the order in which they were declared, was new.
  2. Chapter 14. The name of the function is the same as its address. What happens when you take the address of an overloaded function? Is this allowed? I learned from this chapter that this is indeed allowed and that the compiler uses the type of the pointer is used to select among the various candidates.
  3. Chapters 15 and 16. Pointers to class members and Member functions. Well, to be honest, I had never used these and somehow I have a feeling that I will never need to use them, but the fact that these can be done and that de-referencing the class members actually gives an offset (from the start of an object) rather than an address was something new for me.
  4. Chapter 18. The idea of using the Fibonacci series to illustrate the benefits of using function object instead of a function pointers was nice. It drove home the point pretty well. Just for reference, function objects are like smart pointers where the function call operator () is overloaded.
  5. Chapter 20. Like Chapter 18, the examples of the using function object as comparator was a good idea. Introduction to std::binary_function and std::unary_function was welcome.
  6. Chapter 22. Template Method terminology. Basically this is the idea that the base case establishes the contract with its users and that derived classes need to uphold the contract.
  7. Chapter 23. I am also guilty of the folly listed in this chapter -- putting the using directive (for namespaces) at a global scope. I usually use it for "using namespace std" and I do not think I would ever name a variable from the std library, but I agree with the author wholeheartedly that this is not a good practice.
  8. Chapter 29. The concept of virtual constructor by indirect invocation of class's copy constructor, to clone for example, is worth knowing.
  9. Chapter 33.  Using destructor as pure virtual is a good choice for coercing a class to be abstract. This is interesting.
  10. Chapter 39. Minimize usage of try blocks and use them at module boundaries between your code and third-party libraries and also your code and OS. Something to think about.
  11. Chapter 40. RAII explained with the ResoureHandle example was great.  The idea is that you acquire your resource in your constructor and release it in your destructor and make sure you use local variables so that destructor is automatically called when the function ends.
  12. Chapter 63. You can omit virtual keyword when you have overriding a parents virtual method. No big deal, but new nevertheless.

Monday, November 15, 2010

Ultra run

Last weekend was a big personal milestone. I did my first ever ultra marathon run - 50K at the Bangalore Ultra. By and large, it was a satisfying experience.

The day started with me and my friend Ravikanth driving to Ravi's colleague Sandeep's place at 4AM in the morning. We then hitched a ride in Sandeep's car and traveled to the venue. Sandeep chose the NICE road to get to Tumkur road and then got to Hessaraghatta road from there -- a smart idea, completely avoiding the city traffic and pretty fast.

We reached the venue at around 5:30 and as we were approaching the venue, we could see the 100K and 75K runners already in the trail, running with torches as it was pitch dark. That was one awesome sight. Once we reached the venue, we had just enough time to change to our running gears, deposit the baggage and complete the pre-race formalities. At 6AM we were ready to go.

For the last two years (2008, 2009), the Sun god had been really kind to the Ultra runners, he was always hiding behind the clouds and content to watch the runners from the backdrop. With rain in the previous days, it appeared that this wonderful tradition would continue. At 6AM, we did need to bother about the sun, it was just dawning and it was a wonderful atmosphere to run. And the 100 odd 50K and 37.5K runners hit the trail with great spirit and energy.

As the race progressed, it became apparent that Mr. Sun had other ideas for the day. He came out in full glory to really bring out the best (read test !!) from the runners and started belting out in great style. Add to this the fact that the trail itself is pretty tough (uneven, narrow at times, stones, gravel and what not), it became quickly apparent as why RFL calls this a tough race meant for tough people.

The course itself was made of 12.5 K laps (6.25K to and back) and for completing 50K, we were required to complete 4 laps.  I hit a steady pace (around 10K/hr) speed and was hoping to maintain that speed for atleast 3 laps (37.5K) and then do a walk/run for the last lap depending on how I felt. I was doing fine till about the 32K mark when the heat and tiredness combined hands (or should we say legs) with the knees to bring down the average pace. I had to resort to some walking in that lap itself, though I did finish that lap strong. The first two laps were done in 1:15 each, however, the 3rd lap took 1:30 and so it was 4hrs for 37.5K. In the last lap, the strategy was simple. Walk during all up slopes and run during down slopes. And so when I finally managed to cross the finish line, it was 5:46. Reasonable, but lot of scope for improvement.

The race split information from my Garmin reveals the story very nicely. In the timing graph, you can see the steady running till the 32K mark and then the valleys suddenly start appearing. The frequency of such valleys only keep increasing and even the last k was not spared, I did some walking there as well. Nevertheless, it was  a satisfying experience. I did not cramp or get injured in those trying conditions and even at the end of the race, though the body was tired and knees a little sore,  I was feeling fine otherwise.  This race has certainly increased my resolve to train better and do better the next year.

Monday, October 18, 2010

Broken out of the rut?

About a month (a little more), I wrote this blog on how I was struggling to get out of the well entrenched laziness mode. Now, I think I can say, writing that blog has made me turn a new leaf (at least until I hit the next rut) -- I have woken up before 6AM on all but 3 days from then on and I have missed physical activity (either gym or running) only for 4 days. So far, so good...

Friday, September 10, 2010

Onine Map Directions

I have used Google Maps/Yahoo Maps extensively while in the US and has been really amazed at how detailed they are and how useful they have been. At the same time, I have never felt that this would be effective in India where it is fairly common to have one-ways come up where there were none, other one-ways change directions, roads closed for a variety of reasons and in some cases are just plain un-motorable. However, I had a very pleasant surprise yesterday. I was traveling from Bangalore to Tirupathi and the usual route we take is through NH4. But because of road works here, this road is a little painful and slow. So, we decided to try out alternatives and Google map showed me the alternative through Chithoor - Gudiyatham and NH46. I was really amazed. I never knew the existence of this Chithoor - Guidyatham state highway and even if I did, I would not have thought of this route. This route was about 40Km longer, but much more comfortable and faster. Yet again, the online revolution is making changes to our lives in more ways than we imagine.

Wednesday, September 8, 2010

Breaking out of the rut

I have always felt that total abstinence is much easier than compared to moderation. For example, it is easy to stay off chips completely than to say I will only have a handful. I was hoping that the reverse is also true for things that I want to do. Like going to gym. I thought that after a break, you just need to go to gym for a couple of days to break your laziness and set up your rhythm, but alas it does not appear so. After having finally broken the jinx and waking up with the alarm for a couple of days, I thought I was all set for the good routine. Unfortunately, waking up with alarm every morning seems to be getting more and more difficult. And the first two days that I actually did get up seems more like an aberration. And of all things, running and going to gym are actually things that I always liked to do !! Need to somehow break out of this rut and get to more active and enjoyable routine...

Monday, July 5, 2010

NP hard problem

OK, after being dormant and completely inactive in blogging, I have finally resolved to get back to more active blogging.  It is not that there were any lack of interesting incidents that led to my entering the dormant stage, it was rather a lot of other reasons (read laziness).  Let us see if my mid-year resolution holds for the next half of the year. I will start with a post on one interesting situation I faced a couple of days back.

Last weekend, I visited Chennai to attend a family function. And as my wont, I decided to do a long run on Sunday. Chennai, being renowned for the hot and humid place that it is, is not a conducive place for such runs, especially for those who are not used to its weather. So I decided to do an early morning run and left home at around 4:45 AM on a two wheeler. It was here that I realized, in spite of all my years of riding, there has been one problem that I have never managed to solve.

That is the problem of handling chasing dogs when driving a two wheeler. The pack of dogs seem to reserve all their courage and ferociousness for those hapless two wheeler riders of early morning and can really give them their "fright of their lives".  How do you solve this problem? If you try to drive faster and get away from the place, you are sure to hit the biggest speed breaker ever just a few meters away or worse still, come face to face with another speeding two wheeler trying to escape dogs from the other end of the street. You could try kicking them, but then that is no easy task either. And if you have dogs chasing you on both sides, you have had it. There is an inner urge to drive over them, but then you don't want to do it, even if you are not a Maneka Gandhi fan. This is one hell of a NP-hard problem.