Probable Bug in Visual Studio

August 25, 2006

My friend Mohsin Saleem (no he doesn’t have a blog, so cannot link here) pointed out that he has seen a strange behavior on Visual Studio 6 for the following code.

  1. union u {
  2.     union u {
  3.         int i;
  4.         int j;
  5.     } a[20]; //Edit: Its not a[10]. Faisal, thanks for pointing it out.
  6.     int b[20]; 
  7. }u;
  8. int main()
  9. {
  10.     printf(“%d\n”, sizeof(u) );
  11.     printf(“%d\n”, sizeof(u.a));
  12.     return 0;
  13. }

Visual Studio returned

80
1600

Now that was amazing. I opened it in VS7. When made a .cpp file, it flagged a compile time error. When shifted to .c file, the same results 80, 1600.

Tried it on Dev-C++ and it worked according to what theory suggests. It returned

80
80

 

When change line 5 to “} a[10]”, Visual studio returned

40
400

Dev C++ Returned
40
40

With some other examples, I concluded that Visual Studio does this. sizeof(u) * (number of elements in a).

Don’t know whether this bug is reported or not. If it is, good. If not, the credit goes to Mohsin who first pointed this to me :).

 Edit2: Faisal also told me that he tried it on VS 2005 and its still a bug. Thanks to him in pointing out some blunders in my explanation as well.


MSDN Library is a free Download now

August 15, 2006

Wow! Microsoft has done a great job making MSDN library free for downloading. Previously, Online version were free but offline versions came with MSDN subscription. This will help a lot of students and professionals who don’t have Internet access or have slow Internet connections. Currently May 2006 version is available while all the future releases will be free as well. Great move.

By the way, you can download it from here.


Asking Clarifying Questions in Job Interviews

August 7, 2006

Asking Clarifying Questions in Job interviews has always been a recommended practice. Some of my friends were discussing their not-so-successful interview experiences and many times they mentioned that they solved the problem only to realize that

  1. Interviewer had asked some other question OR
  2. They had forgotten to clarify each and every case with the interviewer before attempting the solution etc.

I am not a guru in doing this but let us try this out.

When in an interview, before you jump to the solution, you should be absolutely sure that you and your interviewer are both thinking in the same direction. Interviewer asks you to solve a problem. If you dont’t ask clarifying questions, your interviewer will assume that you have fully understood the problem. So its always good to speak out what you are thinking and your interviewer will correct you thoughts are not aligned with his thoughts.

For example, Let us consider a simple (and famous question). I may not be able to identify all the cases (but who cares 🙂 .. after all its just another blog :)).

“You are getting a char* that represents a string. If this string represents a Palindrome, return TRUE, otherwise return FALSE”.

Now, lets us see how can we start solving it.

You don’t have TRUE and FALSE defined. Tell you interviewer that for simplicity, you are defining them as

#define TRUE 1
#define FALSE 0

Tell your interviewer that you could have considered using ENUM BOOL but you are focusing on the problem right now.

Define a prototype as

unsingned int IsPalindrome(char* str);

Also clarify that you are supposing that you will receive an 8 bit char string.

Discuss with your interviewer that you would do the following

if (NULL == str) return FALSE;

if (!(*str)) return FALSE; // Zero Length Strings

if (‘ ‘ != str[0] && !(str[1])) return TRUE; // 1 Character strings (See next point for spaces. They might be considered palindrome or not. If they are considered palindromes, then you can omit ‘ ‘ != str[0] )

Discuss with your interviewer the issue of SPACES.

If your interviewer says that you have to ignore spaces, then

Any string of length >=1 containing SPACES only will return FALSE
Strings like “bbaaa bb” will be considered palindrome and will return TRUE

If your interviewer says that you have to consider spaces, then

Any string of length >=1 containing SPACES only will return TRUE
Strings like “bbaaa bb” will not be considered palindrome and will return FALSE

Suggest your interviewer to change the prototype to

unsingned int IsPalindrome(char* str, size_t length);

So that you can avoid Buffer overruns. Your interviewer will either GUARANTEE that you will always get a NULL TERMINATED string (in order to simplify things) or your interviewer will allow to change the prototype. In latter case, you must change your logic accordingly.

Well, these were some questions that you can ask before solving a problem. After this, things are pretty much clear between you and your interviewer. You can carry on solving the problem after this.

Clarifying questions vary from problem to problem but there are always certain issues that you should clarify before you jump to the solution.

P.S. If someone reading this blog wants to add more questions regarding this problem, kindly do so in the comments section.


What do we sometimes forget while Testing Web Applications?

July 21, 2006

I was visiting website of Pearl Continental Hotels in Pakistan (probably they bought this chain of hotels from Intercontinental).I went to their Online Room Reservation. Tried a few dates. All those checks were in place e.g. Your check-in date cannot be less than your check-out date etc.

But one thing was amazing for me.

Now let me be specific. Today is July 21, 2006. I tried to reserve a room from July 21, 2005 – July 22, 2005 (I have said 2005 and not 2006).

When I tried dates of a year earlier while using INTERNET EXPLORER 6, it stopped me and showed appropriate error. Here is the screen shot (Click to enlarge).

PC reservation with IE6

But when I tried doing the same with Firefox 1.5, it said that room is available and I can proceed with the reservation. Obviously, there is no obvious advantage. However you can happily imagine that you are tweaking your PAST :P.

Here is the screen-shot of what surprised me 🙂 (Click to enlarge)

PC Reservation with Firefox 1.5

This blog entry doesn’t say that Firefox is not as good as IE6. It merely says that when you are deploying a web application, you should consider testing it on several browsers. Moreover, you should avoid any Browser specific tags/checks that might fail when same website is opened with another browser.

It is very likely that you tested your website against IE7 while your someone uses text based browser in Linux.

Now what is causing this should be the topic of another blog entry. I haven’t searched on it as yet.


C# and Java in “Introduction to Programming”

June 26, 2006

Sometime back, a post appeared on my university group regarding Introduction to Programming in C#. I replied to that post and I feel that the same can be said for Java as well. I wanted to share it here as well. REMEMBER this is not an anti-C# or anti-Java post.

This is what I wrote

"The more important question that comes to my mind is that why are these students being taught C# in their Introduction to Programming Courses.

C# is a complete development solution but it will never allow a student to learn the basics of programming. You never teach English using Shakespeare's plays in Nursery classes. You begin with A-B-C. When you tell someone in the first class that Hello World program would look like this

Console.Writeline("Hello World");

  1. What will you tell a student about Console . How will you explain the concept of Classes.
  2. How would make him understand that Writeline is a static method.
  3. What will you have to say about Namespaces and assemblies etc.

And this line is itself written in a class – in a Main Method that happens to be a static method itself … and it goes on. Believe me, its difficult to produce good programmers like this.

What will these students learn in OOP courses? How will they be able to appreciate the benefits of OOP over structured programming? How will they decide when to use OOP and when to go for structured programming.

What will they learn in Data Structure courses when they already have ArrayList and Stack classes? What will these students do in Operating Systems and System Programming courses. They will only make SIMULATIONS in OS courses. How would they be able to write operating systems and compilers. In short, when will they learn to do some serious programming?

I'm sure that many students would be keep themsleves busy in aligning the Buttons on left side of the form, connecting with databases, opening a file using File Open Dialog etc.

Students in starting semesters should also realize this that being able to Develop "COOL INTERFACES" in the starting semesters is not going to take them anywhere. They should also ask their Instructors to teach them the basics. Finally, if possible, students in first/second/third semesters should request the concerned authorities to teach C/C++ instead of C# or Java."


Visual Studio 2005 Beta 2

May 31, 2005

Got the DVDs for Visual Studio 2005. However it isn't working yet. It always ask for a team server and I am on WinXP. So Team Foundation Server couldn't be installed on my pc. Will try again. The good thing that comes with the Beta DVDs is the WEFLY247.net DVD. It contains more than 7 GB of data (Did I ever say that I read all that:P). But its looks cool. There are a lot step by step tutorials that realy gonna help.

I hope that I can get the beta running soon.


50th Episode of .NET Show

May 12, 2005

Just downloaded and watched the 50th episode of .NET show. Was amazed at a lot of things. Discussion was good but I dont want to discuss it here.

I was more amazed when I saw Brad Abrams as he looked so young. I wasn't expecting that he would be so young (Used to consider him of the age of Anderes Hejlsberg or Jim Gray). I was inclined to find out his age. His resume shows that he graduated in 1997 and he would probably be 24 at that time. So it makes him 31 or 32.

Well the last 6 or 8 minutes of the episode included an interview with Bill Gates. Came to know a few interesting things about him. Like he has done most of his coding in machine code and he still writes a few applications in C#. And moreover, once he used to understand all the code of the windows and used to modify it as his will … Wow.

I think .NET show people have realized that everyone cannot download the movies due to slow internet. Hence they've provided with the Transcripts of the shows. These are available for episode 31 and onward. Here is the link

http://msdn.microsoft.com/theshow/transcripts/default.aspx

Have a look if you want to get a quick overview of the show before downloading it.

Cheers