Writing pseudocode is a good thing.
Just as it is not recommended that you dive into writing code before your analysis and design are done, so should you not dive into code before you have some sort of pseudocode in place. Unless of course you are writing trivial code.
Even if your design is all laid out before you, then there are many cases where pseudocode is a huge advantage.
Simply listing out the steps gives me a lot of clarity about the way forward. I will most likely find that I've discovered areas that were not thought of during design e.g. if X event takes place, or the application state changes to Y, then how do I handle it?
When I'm coding I am in a different mindset- purely focused on code. Side issues like these are unlikely to pop into my head. And worse, if I haven't worked out the steps, then I will most likely miss something.
Getting stuck on a code issue is very common- at that point, all you can think about is how to solve it/work around it. By the time you've achieved this, your train of thought is lost.
I still use paper and a pencil. Whether you prefer electronic pseudocode or hand written, is up to you but in my opinion, it is an invaluable practice.
I am amazed at the number of people who jump into code and flounder along the way and just refuse to write pseudocode like it's some demeaning activity. What is more amazing is the number of tech leads who prohibit it of their juniors-- saying things like "the client wants to see code". It is well worth the time investment- the bugs will definitely be less. And the amount of patching needed on that code will decrease.
So, it's not a "waste of time" or "an activity that only freshers do". Some of the best engineers I know write pseudocode. It would be worth getting into this habit to help you understand your problem, eliminate ambiguities, reduce bugs and above all, write cleaner code.
4 comments:
I usually write out the "plan" or "logic" in plain english in the src file.
Then go abt coding it.
The pseudocode - then turns out into meaningful comments.
I will definitely implement this method from now
Once upon a time, long ago, when I started learning programming in college, I had access to a PC for only one hour a week! (it's true). And I used to work out all my code on sheets of paper right down to the semi-colons(it was Pascal then, that we used to think in). Not only that, I would painstakingly hand trace through the code many times. Finally, when I would get that one hour access I would cram as much as possible in that time. Couldn't afford to waste too much time compiling and debugging. Circumstances forced me to work this way, but some of my better programs were written in college. No need to get so radical these days, but it really does help to switch off the computer and work your logic out on paper.
I remember from my college days, how our C & C++ professor, Ms. Rekha Rau, forced us to write pseudocode before we write the actual program. I think it makes programming more interesting as we apply our own mind for all those dry-run things.
Thankfully the habit has stayed with me and in fact with most of the Somaiya-ites :)
Post a Comment