Sunday, July 13, 2008

C or Sea?



Few days back, my brother... who wants to learn C programming, asked me to send Turbo C++ compiler by mail. Immediately I said "NO! Do not use Turbo C++ compiler". He asked for the reason and I said I will tell you later. So here are some of the reasons for the same:-

1. Turbo C++ compiler is not ANSI standard compliant. It has many non standard header files:

e.g. conio.h - basically people use it for clrscr() i.e. clearing the screen
graphics.h - Even it is not a standard header file. But in school, colleges still computer graphics programming is taught under Turbo C/C++ compiler…me too a victim.
Now you can ask if graphics.h is not standard then how to do graphics programming? So the answer is go for openGL, DirectX .etc. programming.

2. It has lots of bug one e.g. consider the code

for(;0;)
printf("hello");

This prints hello once in Turbo C++ v3.0 compiler even though the condition is false. The same code in gcc does not give any output. Updated: check this out.

3. You might have noticed that working on Turbo C++ compiler shows 100% CPU usage in task manager. Even the processor gets heated and your system can hang up. This is because it is a 1989 based 16-bit compiler and does not comply with latest processors.

Now, you can ask...which compiler to choose then?

So in my opinion, use GCC...available in Linux and for Windows use the Dev C++ compiler. I found it very lightweight on system performance.

People use Turbo C++ compiler coz it’s easily available...and due to the help it contains regarding syntax .etc. But the biggest problem is the book we read before going for actual programming. Most of us read Yashwant Kanetkar books. Sorry if I am offending anyone but...do not read Yashwant Kanetkar books. Some of the reasons are -

1. Those books have been written keeping in mind Turbo C/C++ compiler only. So, they do not teach us c language properly.

2. You have to unlearn many things. e.g.

Has anyone ever asked you questions like:-

int x=5;
y=x++ + ++x + x++;
What is the value of y?
(Yashwant kanetkar's Exploring C contains lot of these types of questions)

or

Swap two variables without using a third variable in one line?
You might have replied a=a+b-(b=a);
or may be some other way.

For your kind information answer to both of them is "Undefined behavior".

Confused!! ever heard of 'Sequence Points'? For more details visit these:- Wikipedia, c-faq, orkut c/c++ community

Upon thinking the reasons for reading Kanetkar books I found that-

1. These books are easily available even at a second hand book stall. So, definitely cost matters.

2. In schools/colleges, teachers ask to follow these books.

3. Mass following the same path like sheep and getting so called good jobs. Then why not me? Even lot of interviewers ask these types of questions.

Now...which book to follow then? So, in my opinion, no book is best...you have to refer different books for different topics... and yes google, wikipedia etc. can lead to some good resources.

Well...you might be thinking why I am writing about all these things here. So in reply, I would like to repeat the famous quote from movie AntiTRUST - Human knowledge belongs to the world.

0 comments:

Thanks For Visiting The Site | ASIANTOPPER.COM Designed By Siddhartha Gandhi