GithubHelp home page GithubHelp logo

pseudocode's Introduction

Pseudocode

Learning Objectives

  • Describe the role of pseudocode in development
  • List the steps for problem solving
  • Create pseudocode to describe a basic problem

What Is Pseudocode? (5 minutes / 0:05)

Pseudocode is a way to describe the solution to a problem without writing code in full.

  • Writing pseudocode forces you to think critically about the problem and break it down into smaller steps.
  • It is usually written using a combination of English and logic. As a result, it is easy to read.
  • It might display some features of the final product, such as indentation and code blocks.

Pseudocode should describe the entire logic of a problem so that programming becomes a task of translating pseudocode line by line into actual code.

How to Make a PB&J Sandwich (10 minutes / 0:15)

Source: Get Creative Today

We're going to make a PB&J sandwich โ€” for real.

In today's demo, the supporting instructor will act like a computer. You'll be tasked with guiding the instructor through the process of making the sandwich. Keep in mind that your instructions will need to be explicit otherwise things could get messy!

**Here's one approach to solving our problem**
PROGRAM MakePB&JSandwich:
Grab a paper plate;
Open bread container;
Grab bread package;
Untwist bread package;
Open bread bag and remove two slices;
Place slices on paper plate;
Grab a plastic knife;
Open peanut butter jar;
Use knife to scoop out peanut butter;
Apply peanut butter to one slice of bread;
Spread peanut butter on slice;
Place knife on plate;
Close peanut butter jar;
Open jelly bottle;
Squeeze jelly onto second bread slice;
Close jelly bottle;
Place down jelly;
Pick up knife;
Spread jelly on slice;
Bring two slices of bread together;
Cut slices in half down the middle;
Throw knife in the trash;
Pick up one half of sandwich;
Enjoy;
END.  

A. This example's sequence is very thorough! However, we are still assuming certain conditions that our utensils or ingredients already exist. What if we are out of plates? Will we grab a napkin instead to place our sandwich on? What if we are out of jelly? Will you throw the sandwich away or eat it with just peanut butter?

Approaching a Coding Problem (15 minutes / 0:35)

Computers are not smart. We need to give them step by step instructions to account for conditions. They can not adapt to make changes without being explicitly told. Programing is a series of tasks, which can be completed only if a certain number of conditions are met.

Computers can not adapt, but we can. Your first pass at pseudocode will probably not cover everything. Once you know more, you may come back to update and refactor your pseudocode.

Pseudocode isn't just about writing down the steps that you already know. It's a tool to help you work through the problem. Before we can write pseudocode to solve the problem, we need to know the problem.

Identify the Problem

  • What exactly are we trying to solve?
  • What are we delivering?

Conceptualize

  • Look at the big picture
  • Avoid details
  • Whiteboards and pen-and-paper can be useful tools here

Break It Down

  • Break the conceptual models down into concrete steps / actionable items
  • Identify risks (e.g., gaps in knowledge and technology)

Start Small, Stay Small

Write code using those concrete steps

  • Verify that each step achieves what we want before continuing on
  • If we do too much at once and things break, which they always do, we won't know what is causing the problem
  • Humans thrive on easy wins and forward progress. Use this to your advantage.

Where Does Pseudocode Fit In?

"Break It Down"

This process is iterative. We keep circling around and repeating the earlier steps, just at a different level.

When we first approach a problem, we see the big picture. "Break it down" first into big steps. Then we take one of those steps and "Break it down" again into smaller steps. We write pseudocode to help illustrate the problem.

Pseudocoding proves that we have identified the problem, understand it conceptually, and have broken it down into small steps that we can follow.

Example 1.1

PROGRAM IsEvenOrOdd:
  var num = number;
  IF (num % 2 === 0)
    THEN Print "even";
    ELSE Print "odd";
  ENDIF;
END.
What do we think?

This is not a great example. Here we are using "var" in our pseudocode when it should read plain english! Also, we should not be using the javascript syntax "===" in our conditional. Would a non-programmer know that num % 2 === 0 indicates an even number?

Example 1.2

PROGRAM IsEvenOrOdd:
  Read number;
  IF (number divided by two has no remainder)
      THEN Print the number is even;
      ELSE Print the number is odd;
  ENDIF;
END.
What do we think?

This is better. It's closer to English. It clearly states what we are trying to achieve and how, without getting bogged down in the minutia of code. Even someone that doesn't code can help us check our logic. Is any number that can be divided by two, cleanly -- without leaving a remainder -- even? Is anything else odd?

You Do: Pseudocode Concentration (15 minutes / 0:50)

Take 10 minutes to pseudocode the game Concentration with a partner.

The user should see a grid of cards. Clicking a card reveals it and allows them to click another card. If they match, the cards stay up and if not they flip back over. Users get a point for every pair they flip. The game ends after 1 minute or all cards have been matched.

Afterwards, we'll spend 5 minutes sharing approaches as a class.

Conclusion

  1. What are some helpful steps for solving problems?
  2. What does pseudocode help us do?
  3. Do we only pseudocode at the start of a project?

Resources

Screencasts

pseudocode's People

Contributors

adambray avatar amaseda avatar beckybeauchamp1 avatar jshawl avatar mattscilipoti avatar nayana487 avatar robertakarobin avatar superbuggy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pseudocode's Issues

Clarify role of assignment

Many student struggled with assignment of the result of a command: Number CurrentIndex = Add(CurrentIndex, 1). I wonder if we could make this clearer.

Tic-Tac-to(Diona/patrick)

Features to be added

  • Board
    players
    x and o
    rules
    refresh button
    greeting and score messages

Design
each square is a div
only able to enter once and the field entered will be disabled

Pseudocode:
createBoard()
prompt player for teams
message explaining game rules
rules() - game loops- for each , it will check if there is three pieces in a row

Christian Spenser Pseudo

on-click, if box empty and if player 1 place X
on-click, if box empty and if player 2 place O

check to see if 3 X's or 3 O's in a row, horizontal, vertical, or diagonal
display winner if 3 combo

add +1 to winner's win counter
add +1 to loser's loss counter

display, Play Again?

Suggest: providing command names for fizz buzz

Many students struggled with how to use the provided command descriptions. I think it would be clearer for them (and fun) if we provided the commands.

e.g. Add(addend1, addend2): Add two numbers together. Outputs the sum.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.