Tuesday, August 28, 2007

Last words for RTL colleagues !

Following is a mail I sent out to my RTL colleagues when I left for Sweden to do my masters in Software Engineering and Distributed Systems ..

Hello All,

As you might have heard (or perhaps not) today is my last day at Relisource. Unfortunately today is a curfew and none of you are here at this moment to say goodbye. I think its all good as the goodbye part would have been very tough for me. Many things have happened and so many people have come and gone, and in this last day, I am not sure what to write for all of you, since there are so many things and each deserve a special thank you in their own way. It's been an exciting and eventful one year and eight months. I will cherish this memories and moments I have lived with you guys for the rest of my life.

In short, I would like to say no matter which part of the map I am in I will always keep in touch and flood your email boxes with my mails no matter what Vaskar Da has to say.

I would also like to take this opportunity and thank all the people in RTL, each and every one of you have, in some way influenced my life in a big way. I have learned a lot during my stay here, not only coding but how to lead and enjoy each moment of life. I have better understood the meanings of fun, commitment and professionalism.

Please do pray for me so that I can stick to path of goodness and follow my own religion with faith and believe.

This is the end of a memorable chapter of my life and beginning of a new one.

Regards
/Reza - End of a wonderful Chapter !

Monday, August 13, 2007

How to justify that your code is stable !

Have you ever wondered how much tested your code is ? We often write Unit Tests to ensure proper functionality of a product. But how do you ensure that the Unit Tests actually covers most of the functionality. Well the solution to this problem is a open source tool named Cobertura. This is for Java freaks only. Cobertura is a tool which calculates the code coverage of your project.

A sample report generated by the tool :



Detailed report on the lines covered by the unit tests written for the project:



Feature List :
[This feature list is quoted from official cobertura page : http://cobertura.sourceforge.net/index.html ]

  1. Can be executed from ant or from the command line.
  2. Instruments Java bytecode after it has been compiled.
  3. Can generate reports in HTML or XML.
  4. Shows the percentage of lines and branches covered for each class, each package, and for the overall project.
  5. Shows the McCabe cyclomatic code complexity of each class, and the average cyclomatic code complexity for each package, and for the overall product.
  6. Can sort HTML results by class name, percent of lines covered, percent of branches covered, etc. And can sort in ascending or decending order.
The integration of this tool is very straight forward. They have given the ant script which when added to your projects ant will automatically have this integrated with your project. So simply go to the following link and digg more on how to integrate : http://cobertura.sourceforge.net/


I am sure Java lovers will find it great and indeed a nice tool through which you can justify that your code is stable and it RoCks. :) Enjoy !.

- Reza

Friday, August 10, 2007

Porting legacy codes to Visual Studio 2005

Lately we were given a code base from EA. It was a mixture of C and C++ codes. They continously added code to it on demand in an adhoc basis for the last 14 years. Our task is to develope the same tool from scratch if need be we can use some of their codes as well. And the requirement is the tool needs to be developed in Microsoft Visual Studio 2005. So our first task was to build the existing legacy code they dumped us with in 2005. While trying to do so I faced a few issues which I want to share in this post :

Commmon Problem 1:
error C2220: warning treated as error - no 'object' file generated
warning C4996: 'wcstombs' was declared deprecated
c:\program files\microsoft visual studio 8\vc\include\stdlib.h(562) : see declaration of 'wcstombs'
Message: 'This function or variable may be unsafe. Consider using wcstombs_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

Solution -
#pragma warning ( disable : 4996 )
Commmon Problem 2:
error C2440: 'initializing' : cannot convert from 'const char *' to 'char *'

The code was :
char *pTxdGroupXml = strstr(name, "_resources.xml");

Solution -
Change the code to :
char *pTxdGroupXml = (char*) strstr(name, "_resources.xml");
Common Problem 3
error C3861: '_assert': identifier not found

Solution
#define _assert(exp, fileName, lineNumber) assert(exp)
Common Problem 4
error LNK2005: __configthreadlocale already defined in MSVCRTD.lib(MSVCR80D.dll) LIBCMTD.lib
Solution
ProjectSettings - > Linker - > Input -> Ignore specific Library : LIBCMTD.lib


Hope this post helps when you are down and fighting to build a mamoth Legacy Code.

- Reza

Monday, August 06, 2007

Playing with linker options [C++]

Changing the entry point of your Application:

Did you know that the entry point of a C++ program can be changed. It can be set from the linker option.
ProjectProperties -> Linker -> Advanced -> Entry Point

In the entry point we can set any function name and that will be the starting point of the program. Try it and have fun :).


How to have a console running behind your MFC or Win32 Application:

Well at times this things come in handy. Suppose you have made a MFC project and have initialized OpenGL in one of the windows. Now while drawing on the window you need to watch some values of animation. In such a case as the values of animation are being update continiously, to see those values via a message box will be very pathetic. The other way to see the values might be to dump them in a file and then see the files. Wouldn't it be better if you could have a console window running behind the MFC windows you have created. Well having a console running at the same time would be easy to debug things on run time as we can have printf statements dumping values in the console, while at the same time the MFC windows are working as usual.

This can be acheived very easily.

SubSytem can be set via :
ProjectProperties -> Linker -> System -> SubSystem

Entry Point can be set via :
ProjectProperties -> Linker -> Advanced -> Entry Point

A bit of playing around with the linker options. When you open a MFC project you have the following set as default :

The subsystem value is set as : Windows(/SUBSYSTEM:WINDOWS)

And for Entry point the value will be wWinMainCRTStartup if you are using MicrosoftVisual Studio 2003 or 2005. For VC6 the value will be winMainCRTStartup.

Changes needed to bring a console :

Set value of the subsytem to be : Console(/SUBSYSTEM:CONSOLE)

When you set the subsytem the Entry Point value will be blank. We need to set it to have the value it initally had that is wWinMainCRTStartup or winMainCRTStartup.

Thats all. Run the program and you will have a console running at the back where you can dump all the information you need.

Hope this helps.

-Reza