NMD 105 Creative Coding I

P5js Pitfalls

"Green Brain99099" by Luis Ruiz

Where to write code?

When to put code in setup, draw, or outside.

Horizontal whitespace usually doesn't matter, but consistent indenting helps debugging.

Vertical whitespace is always optional.

p5js reads from top to bottom. Don't refer to something now that isn't defined until later.

Punctuation and syntax

Double quotes "" versus single quotes '' versus backticks ``.

Every ( has a ), every { has a }, every [ has a ], but they are not always on the same line.

= versus == versus ===

let versus var versus nothing

Naming stuff

Capitalization matters: mouseX works, mousex doesn't

Use nouns for most variables: puppy, numberOfCats

Use verbs for functions: addBird(), detectCollision()

Use phrases for true/false (Boolean) variables: isFalling, hasParent

Don't abbreviate unless you have to: makeCloud is better than mkCld

Use "camelCase" to combine words: addBird is better than add_bird or addbird

Can't use the same name for a different variable or function.

Some names are already taken: width, mouseIsPressed

⚠ī¸ Beware of Googling code

You won't understand it

I'm customizing each assignment to each student

New Media Meme 10

🍀 Stack Overflow when you're lucky

☚ī¸ Stack Overflow when you're not so lucky

Meme Cats Stack Overflow

Asking for help

Give enough info

Post to #troubleshooting!

To post privately

/