Jump to content

  • Log In with Google      Sign In   
  • Create Account


pseudocode!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Benderwiz   Members   -  Reputation: 162

Like
0Likes
Like

Posted 24 February 2013 - 07:06 PM

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.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 27925

Like
7Likes
Like

Posted 24 February 2013 - 07:19 PM

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).


Edited by Hodgman, 24 February 2013 - 07:21 PM.


#3 BGB   Crossbones+   -  Reputation: 1545

Like
6Likes
Like

Posted 24 February 2013 - 07:42 PM

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.

#4 epicpunnum   Members   -  Reputation: 454

Like
4Likes
Like

Posted 24 February 2013 - 08:09 PM

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.



#5 alnite   Crossbones+   -  Reputation: 2056

Like
3Likes
Like

Posted 25 February 2013 - 02:45 AM

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


Edited by alnite, 25 February 2013 - 03:08 AM.


#6 CC Ricers   Members   -  Reputation: 623

Like
0Likes
Like

Posted 25 February 2013 - 08:44 AM

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.


My development blog: Electronic Meteor

#7 swiftcoder   Senior Moderators   -  Reputation: 9669

Like
0Likes
Like

Posted 25 February 2013 - 10:55 AM

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 - Software Engineer @Amazon - [swiftcoding]


#8 spiralseven   Members   -  Reputation: 132

Like
0Likes
Like

Posted 25 February 2013 - 02:00 PM

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



#9 spiralseven   Members   -  Reputation: 132

Like
0Likes
Like

Posted 25 February 2013 - 02:02 PM

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



#10 Benderwiz   Members   -  Reputation: 162

Like
0Likes
Like

Posted 25 February 2013 - 07:57 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS