• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is pseudo/prep code?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Split this into small parts that represents some concept. Like a method or procedure.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't apologize. This forum is meant to ask nooby questions ;).
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for an off-top.
Winston, one more post to go ;).
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow! Thanks everybody! And congrats on 5000 posts
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic