Sign in to follow this  
Robert James Saunders

pseudocode!

Recommended Posts

Pseudocode is writing steps in English? I'm kinda mixed up by some of this. I found an example that confuses me:
 
 
Pseudocode to me would be just write simple steps in English. Like for example:
 
wake up,
get a shower,
get dressed,
have something to eat,
etc, etc.

Share this post


Link to post
Share on other sites

As this is filed under C++, I'd assume for this case a C-like syntax would be ideal. Personally, like cr88192, I prefer such a syntax as well, especially as C-based laguages have a lot of ground in today's world, encompassing C, C++, C# and Java (not to mention that there are a few other languages that have somewhat similar structures and syntax).

Just for a general idea, psuedocode can have any loosely defined structure. If you wish to adhere more to the language you're using, it could show up as

void performMorningRoutine(){
  wakeUp()
  shower()
  getDressed()
  eat(breakfast)
}

 

In many cases of psuedocode, the actual implementation is ignored, and instead just has a loose design, opting for comments in some places

void eat( food ){
  if ( hasFood )
    while (hungy){
      //decide how to eat your food and eat it.

    }
}

 

In most cases, it's just to give you an idea of the structure you need to follow for an algorithm.
Honestly though, as long as your structure follows some sort of structure that programmers can get, you should be fine. If there's one language you're using specifically, using it's syntax loosely is probably preferred as long as it promotes readability.

Share this post


Link to post
Share on other sites

I find it strange that some people would write their pseudocode almost like they are writing actual code.  IMO, if you have to worry about syntax, then might as well write the code. My pseudo-code is usually just plain english mixed with coding symbols, which gets translated into comments, and removed once the code is tested and finalized.

 

For example,

[tt]

if player's hit points > 0

  player runs around

else

  player stays, barks, and twirls

[/tt]

Edited by alnite

Share this post


Link to post
Share on other sites

I find it strange that some people would write their pseudocode almost like they are writing actual code.  IMO, if you have to worry about syntax, then might as well write the code.

 

I sometimes find writing pseudocode helpful that way in that it then becomes the first step of a TDD cycle. I'm not heavy on TDD but it has gotten me to write some of my functions quicker.

Share this post


Link to post
Share on other sites
The first time you try and write 30 curly braces on a whiteboard during an exam/interview, you'll be cured of adding excessive syntax to your pseudocode.
 
I tend to stick with a very minimalist style (somewhat pythonic, I guess): indentation indicates scope, statements are plain english plus various mathematical operators.
 
main:
   for each line in input file
      calculate running average of columns 2,3
   output final averages

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this