Hacker 101/102 - Introduction to Programming w/Processing
-
Upload
dan-chudnov -
Category
Documents
-
view
4.727 -
download
0
description
Transcript of Hacker 101/102 - Introduction to Programming w/Processing
hacker101/102
code4lib 2010 preconferenceAsheville, NC, USA 2010-02-21
i. intro
why are we here?
learn to hack?
...not exactly
we work in librariesso we can
help people
we hack to help ourselves
help others
what’s a good hacker?
languages?standards?
jargon?math?logic?
frameworks?
nope!
a good hackerknows
when to ask for help
a good hackerknows
how to ask for help
a good hackerknows how
to help other hackers
a good hackerknows other hackers
to ask for help
when to askhow to ask
how to answerwhom to ask
i’m herebecause i want
to be able to ask you
when to ask?
thirty minute rule
for today:three minute rule
how to ask?see “How to ask
questions the smart way”
we’ll get startedtogether
basics in Processingregexes in JavaScript
glue it together in Python
explore on your own
get comfortableasking for help
ii. the basics
Processing
canvas, grid, points
200
400
300200
lines, rects, ellipses
start
end
syntax, functions, errors
don’t be afraidto break stuff
variables, loops
test
initial value
type “integer”
increment
repeatingactions
every lang has loops
• for (a=blah, a<foo, a=a+bar) {...}
• for each (foo in blah) {...}
• for i in range(20): ...
• while (foo != bar) do {...}
• next, continue, break
more variables, loops
even more variables, loops
explore on your own
iii. functions, objects,the main loop
why functions?
setup, draw, void
function structure
RETURN_TYPE FUNCTION_NAME ([var a, ...]) {...statements...}
setup, draw
•void: returns nothing (into the void!)
•setup: prep stuff
•draw: the “animation loop” or “main”
different kinds of “main”
• Processing: draw() is like an animation “cell”
• in a GUI: the user feedback loop
• command-line app: parse args, then main()
• web app: the user feedback loop
setup, draw, void
we canwrite this better
setup, draw, void
see the problem?
setup, draw, void
DRYDon’t Repeat Yourself
a littlebetter
moretask
specific
adddelay(10);
nowtry this
initialization
no loop!
if/elsei.e.
“conditional”
•draw() is already a loop; why another?
•“i” becomes state
•tightens up draw()
what about objects?
objecti
fied
• it says what it is
• it removes a lot of repeated noise
• it’s kinda overkill here
•we don’t use rp1 and rp2 again
• design a matter of taste
• sometimes things should be called what they mean
• sometimes an “int i” is just an “int i”
• think about what you’ll understand later
no single answer
explore on your own