Do you know the most common programming mistake? Try to recollect the times when you used to compile your baby size programs and print Hello World.
Didn't get it? Its omittance of semicolon at the end;
The Solution:
What I am about to share is solution to just another big common mistake, staking programmers scared sleeps.
The scenario:
After hapless efforts, tonnes of Page Dn and Page Up, when your eyes swell of digging screen and at last you encounter the villain: "if(x=0)". You take a deep breath and after adding the required '=' the program finally complies.
The Solution:
In order to avoid this just use a simple rule: always put conditions with constants on left: "if(0==x)". It might look bit odd but has the 'miracle' thing. It will always generate error if you put single '='. Here's how,
Lets assume you forget to put the second '=' (No way if you have read this post) and you try to compile, it would throw an error because "if(0=x)" is illegal in language - you cannot assign variable to constant.
Hence always keep these practices:
- Use (0==x) in conditions
- Read this blog everyday before brushing
That said will save you real time.
No comments:
Post a Comment