Archive for November, 2007

Trekking at the Sayhadri range

Friday, November 30th, 2007

STA_7767-STO_7781
Just came back from a trek in the Sayhadri range in Maharashtra, India. Took a 10 day break from the routine. This is after a two year break from trekking. I almost forgot what it was like to be out in the wilderness. It was a mind blowing experience, sleeping under the stars, breathing unpolluted air and visiting caves and forts built in 200BC. I thought that such stuff existed only in video games. All in all, it was an easy trek. It's one that I have wanted to do for some time now and one that I’d like to do again in the monsoons. The grass is greener (literally) and the landscape is ten times more beautiful. As you might guess there is a photo album where you can check out the pics.

For those of you interested, the trek was organized by YHAI Malad unit. The trek schedule was something like the one below, but we deviated from plan here and there, but below is what happened during the trek.

1st Day (17th Nov 2007) Base Camp Karjat
Arrival at Karjat.

2nd Day – Rajmachi Camp.
The journey started with a half an hour auto ride. The actual adventure began from Kondivade with with a walk with awe-inspiring views of Ulhas Valley. Along the way to Rajmachi we visited Kondhana Caves. In the evening there was a sight seeing program of lake and temple. We even took a dip in the lake.

3rd Day – Rajmachi Darshan.
In the morning there was a sightseeing program of twin forts of Rajmachi. In the evening we were kept busy with a treasure hunt.

4th Day – Ekvira Camp.
There was a rather flat walk through the Valvan village on the bank of Shirota Lake. Even though it was flat I would say it was the toughest route in the trek as we had very limited water and it was blazing hot. Then after a gradual climb we reached the top of Ekvira mountain. From there we were able to see the Valvan dam and Lonavala city. After that we climbed down to the famous Karle caves. After seeing the Ekvira caves and Ekvira temple we reached Ekvira camp.

5th Day – Lohagad
The trek started towards Village Bhaje via a tempo ride. After visiting beautiful Bhaje caves group we climbed Fort Visapur and then reached Lohagad wadi camp.

6th Day – Back To Civilization.
In the morning we visited Fort Lohgad. After this we had a certificate distribution program after which everyone split up and went their way

After the trek, I spent a few days in Bombay. Bombay reiterated it's coolness. That is where things happen and where you live your life to the fullest. I will be uploading a few pics from that trip as well.

In the mean while I uploaded an old album of an office party to the site. It’s one of those never ending jobs where I need to sync up all the albums from my HDD to my site.

Coding best practices: Minimizing the use of macros

Friday, November 30th, 2007

This coding ‘best practice’ is the first in the series of many posts that I will be making. Many of them have been introduced to me only recently, so it’s unlikely you will see this in my old code. I am making these posts as I think they are essential to every C++ programmer.

Lets get started on the first one…
Some may call this an opinion, but I call this a good programming practice.
Don’t declare a macro unless you cannot do without them. Below I have presented some problems plaguing macros and some workarounds.

1. Macros modify the code before the compiler sees it. This makes it harder for you to debug your program, step into code and find bugs.

2. Macros don't obey scoping rules. So the following example

// The macro below could very well be in another header file
// that you never seen or totally forgot about
#define width 20

// And then you name a variable the same name,
// forgetting there was a macro with the same name
// It’s than you think to forget, especially if the macro is
// hidden in one of those header files
void RenderRect(int height, int width) // …

Workarounds
Below are some workarounds for some common uses you might have for macros

// 1 //// Global strings
// macro:
#define SZ_HELLO "Hello world"
// workaround:
char const szHello[] = "Hello world";

// 2 //// Global setting
// macro:
#define NMAX 5
// workaround:
const int nMax = 5;

// 3 //// Generic functions
// macro:
#define SQUARE( x ) ((x)*(x))
// workaround:
template<typename T>
T inline square(T &x)
{
  return x * x ;
}

End note

Of course there are some places where only a macro can get the job done. In these cases go ahead and use a macro, but follow a strict naming convention for your macros so you will not confuse them with a standard variable later on.