• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is pseudo/prep code?  RSS feed

 
Bennett Nelson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys. Well, I have been reading the book "Head First Java" because I am new to programming in general and I heard that java (and this book) are pretty easy. In chapter 5, where you build a battleship type game, it tells me to use prep code (apparently a form of pseudocode, whatever that is XD) and even gives me some examples. Then later in an exercise, it wants me to write my own. I can't seem to do it at all. This probably seems like a dumb question, but what is prep/pseudo code even used for? Also, is there an easier way for me to write it or at least get started writing it? Thanks for any help you can give me!
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pseudo code is essentially writing your logic in the vernacular without any actual code.

e.g.
 
Bennett Nelson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LOL! Ok that clears things up. So basically it is to make it easier to visualize what your code needs to be? Do you have any tips for writing this when it is on a larger scale?
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Split this into small parts that represents some concept. Like a method or procedure.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. Like Pawel suggested, split the functionality into chunks. Similar chunks should go into one class.
e.g. You might have a scenario where you need to manipulate user names. Extract the first and last name, extract only the first, only the last, extract salutation etc. All these should be individual isolated blocks, which are also called methods. Since all these methods perform a similar function (extract relevant information from the given user name), all of them should belong to a class e.g. UserNameInfoExtractor.
One of the good things about Java is that you are not restricted to your class/method name length. Use this to your advantage to give proper names, reading which it should be immediately clear what the method/class does.
 
Bennett Nelson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! That makes a lot of sense. It's pretty much a way to simplify things in an organized way. I can see how this makes the actual coding process easier. Thanks a lot guys! Sorry for a nooby question.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't apologize. This forum is meant to ask nooby questions ;).
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bennett Nelson wrote:Oh! That makes a lot of sense. It's pretty much a way to simplify things in an organized way. I can see how this makes the actual coding process easier.

The only other thing I'd add to the excellent advice already given - and it's probably the hardest part about pseudo-code for "noobs" - is to concentrate on WhatNotHow (←click).

Maneesh's tongue-in-cheek "code" is actually a great example of this. His first line is:
Notice a girl
and it's simply one of the things that has to be done. There's no attempt to explain HOW he's going to do it because you can usually fill in that detail at coding time. And if you can't, get another sheet of paper and break that down.

In my case the first step would be:
Put on glasses

HIH

Winston
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for an off-top.
Winston, one more post to go ;).
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:Winston, one more post to go ;).

Blimey. Hadn't even noticed. 5,000th was at 10:37:36 Belgian time.

Winston
 
Bennett Nelson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! Thanks everybody! And congrats on 5000 posts
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!