tags:

views:

907

answers:

6

I don't want to invite an argument over whether Pseudocode is useful or not here,..there are plenty of questions relating to that. I DO find writing pseudocode useful at times but one thing that crops up all the time is how best do i express it?

Sometimes i end up with a numbered approach, other times I'll use a C style syntax but most of the time it's a mix of what i think is best at the time. That's fine but in 6 months when i come to look over it again it's not always so clear what the intention was! To combat that i've recently started dividing the page into two and down the right half i'll write pidgin [Insert Language Here] and down the left i'll write in really obvious and verbose English.

I don't think there aren't any 'Standards' for writing pseudocode but I'm interested to see how other people do it and maybe that'll help me decide on a unified approach.

Thanks in advance.

Oh, i know this question is subjective and I'm sorry if that's not the intended purpose of SO but it's still a valid question. In fact, are there really that many questions in computing that have a single correct answer? I'll be marking the most helpful answer as correct.

+1  A: 

I start by writing in english or mixed with programming language expressions. Then I, step-by-step, replace english with programming language expressions and sometimes leave english words as comments, and then - voila - I have a test function - so it's like pseudo code + TDD all in one approach. I have to mention though, that I don't use this approach always, just when I have to solve a difficult task or design a new not a trivial class.

nightcoder
+2  A: 

I like Steve McConnell's chapter on writing pseudocode in his book Code Complete. I know this answer may not be satisfactory if you don't own it but still, if you don't, the book itself is a must have anyway.

Razzie
Never got around to reading it so it's on order, along with Pragmatic Programmer. It's about time i read them!
Stimul8d
Yes, you really should, you'll be glad you have! :) It's how I learned about pseudocode anyway, and I haven't really found some other tutorial that goes into it in detail.
Razzie
You can get the book from amazon [http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670].
Jon Cage
+1  A: 

I generally avoid any sort of code language altogether and write comments about what I want to happen at any given point in the program. Once the comments are all done, it's a matter of filling in the blanks.

spbots
I went down this route a few times but the trouble is when your in an OO language you don't end up with a sequential flow of the whole process unless EVERYTHING you need is available to the object you're writing for,... if that makes sense?!
Stimul8d
+1  A: 

I also find pseudocode useful. Your two-page approach sounds good. You might also look into Literate Programming; I often use an LP style laying out my thoughts as I program, although I don't generally use an LP tool.

Charlie Martin
Hmmm, never come across this before. Worth a look though for sure. Thanks.
Stimul8d
+2  A: 

I tend to find myself writing small use cases in notepad using indentation... and after half a dozen lines or so I suddenly realise I'm writing in a style which is essentially Python but with a little less syntax! So I've come to the conclusion that Python is actually pseudo code and a fantastic way to prototype your thoughts in whatever language you're really trying to write in. The best thing about this technique is that you already have a reference you can compare your finished result to in the case of nasty bugs.

There are times when a UML sequence diagram is faster than writing as a mental exercise to map out what needs to happen and when, but those two techniques are what I come back to time and time again.

Jon Cage
Good call on the sequence diagrams,.. i use them for formal docs or when i have to get a particularly techie or algorithmically heavy concept across. Python makes me sick to my stomach though. It's a perfectly valid language of course and maybe especially for prototyping,.. i've just never liked the syntax.
Stimul8d
Out of curiosity, what do you prefer to Python?
Jon Cage
I like this "good pseudocode is Python" mantra.
ilya n.
+1  A: 

I've never used pseudocode and never felt the need of doing it, I believe that your code can be clean enough if you dedicate some time refactoring it, no matter what language are you using.

I thought I was too lazy, or just against it for some reason but then I found others think the same

Pablo Fernandez
I can understand your point but I'm not writing pseudocode to be 'clean', I'm writing it to make certain i have the concept/algorithm right in my head before i begin. Also, no matter how much time you budget for refactoring, unless you have some kind of design up front you have no knowledge of how much refactoring you might need.You COULD end up getting 90% through a project only to realise that you've missed something early on and you''re potentially back to square one! Horses for courses though. I've written a lot of software with no pseudocode at all.It depends how complex things get.
Stimul8d