pseudocode!

Started by
8 comments, last by Robert James Saunders 11 years, 1 month ago
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.
Advertisement

Yep.

Pseudo-code is any kind of informal description, which looks somewhat like code, enough that a programmer could translate it into real code.

That example is a little bit silly, because it seems to be defining a strict/formal syntax for pseudo-code, when the point is that it doesn't have to follow any strict syntax (pseudo == false/fake/pretend, so it's fake-code, pretend-code).

Yep.
Pseudo-code is any kind of informal description, which looks somewhat like code, enough that a programmer could translate it into real code.

That example is a little bit silly, because it seems to be defining a strict/formal syntax for pseudo-code, when the point is that it doesn't have to follow any strict syntax (pseudo == false/fake/pretend, so it's fake-code, pretend-code).

yeah, kind of backwards is that a lot of people get fussy and demand that pseudocode have some specific syntax, generally resembling either a BASIC or Pascal variant, and have ended up complaining because I often tend to write pseudocode which resembles C-family languages (generally ranging from C-like to C++-like to JS-like).

but, as I see it, the point is mostly to express ideas, while being able to hand-wave details (like making the code actually work, or entirely nailing it down to a particular language, ...), and people insisting that it have a particular narrowly-defined syntax kind of misses the point IMO.


then again, some people have also complained because my scripting language uses a vaguely C-like syntax as well, but I personally prefer C-like syntax, and also expect this is what most people are most familiar with.

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.

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,

if player's hit points > 0

player runs around

else

player stays, barks, and twirls

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.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

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

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I use the #typedef function to create psuedo-code prototypes....

youre practically giving a label to a complicated set of instruction that would make it appear as if it were english

Thanks for the feedback. Seems there are many ways to use Pseudocode and I understand it now.

This topic is closed to new replies.

Advertisement