Title: The Poetics of Code
1The Poetics of Code
- LCC 2700 Intro to Computational Media
2Aesthetics
- The philosophy of art
- Immanuel Kant (18th c) - the philosophy of
perception - The criticism of taste
- Literary, Visual, Gastronomic, Musical
3Poetics
- Aristotle, a subset of aesthetics (with rhetoric)
- The first literary theory
- On poetry a form that carries out imitation
- Principally advice on writing tragedy
- Completeness beginning, middle, end
- Unity of action plot
- Struggle agôn
- Comedy imitation of low behaviors (presumably
to encourage avoiding them)
4Programming
- Weve been talking about procedurality as it
produces expression - But is programming itself art?
- Is there an inter-relation between programs
themselves and procedural expression?
5Programming Style
- Standards for composing code
- Readability
- Variable names
- Consistency
- Comments
- Typography
- Indentations
- Line breaks
- Searchability
- Naming
- Evocative variable names
6Hungarian Notation
- A naming convention in which the name of a
variable indicates its type - Prefixes for variable names
- strName, sName
- intAge, iAge
- lngUserId, lUid
- datHireDate, datHire
7Programming Efficiency
- Class structure
- Careful use of inheritence
- Final and other special directives
- Methods should do one thing
- When to class based on the environment (J2SE v.
J2ME) - Use error control for exceptions, not for flow
control - Python forces indentation for control flow
8Coding Standards or Conventions
- get a b c
- if a lt 12 and b lt 60 and c lt 60
- return true
- else
- return false
- if(hourslt12minuteslt60secondslt60)return
trueelsereturn false
get hours minutes seconds if hours lt 12 and
minutes lt 60 and seconds lt 60 return true else
return false if (hours lt 12 minutes lt 60
seconds lt 60) return true else
return false
9Programming Style
- Focused on productivity
- Collaboration and complexity
- Taken for granted (consider auto-formatting IDEs)
- Code as seen only by technical workers, and only
used to produce programmatic output
10Programming Languages
- Themselves designed for maximum productivity
- Object-oriented programming as a kind of Fordist
manufacturing process - Automatic Factory?
- Produce poetic output
- Facilitate poetic productivity
11Code and the Program
- HTML as a possible example
- The markup and the layout are both viewable to
the end user - The markups quality is part of the experience
- How did they do that (e.g., the single pixel)
12Upsetting the constraints of languages
- International Obfuscated C Code Contest
- Hello World One , Two
- Palindrome
- She Loves Me
- Poot
- Factorial (compare this and the last to
Apollinaires Calligrammes) - Typing
- Christmas Tree
13New Languages
- Entire programming languages devoted to
constrained code-level and execution-level
expression! - Alternate flow control Whenever
- Compresion Brainfuck
- Programming from Hell Malebolge
- Statement redundancy Ook
- Code as visual aesthetics Piet
- Code as literature Shakespeare
- Code as cooking Chef
14Hello World in Brainfuck
- gtgtgtgtltltltlt-gt.gt.
...gt.ltlt.gt..------.---
-----.gt.gt.
15Hello World in Brainfuck
-
-
- gtgtgtgtltltltlt-
- The initial loop to set up useful values in the
array - gt. print 'H
- gt. print 'e
- . 'l'
- . 'l
- . 'o
- gt. space
- ltlt. 'W
- gt. 'o
- . 'r
- ------. 'l
- --------. 'd
- gt. '!
- gt. newline
16Hello World in Malebolge
- (lt9876Z4321UT.Q)M'H"!Bzy?zKwZY44Eq
0/mlk hKs_dG5m_BA?-YVb'rR5431M/.zHGwEDCBA_at_
986543W10/.R,Olt
17Project 7 - Write a program in Chef
- It must compile and run. It need not be the most
meaningful program, but it must execute and do
something coherent - It must read like a coherent recipe. That is, the
source code should be as readable as the
executable code, and it should make sense as a
recipe. - If you want an 'A', your recipe must also be
coherent enough to be prepared in the real world.
This is harder than it sounds. - Extra credit (5 points) for anyone who brings in
a version of their Chef code for us to eat in
class.
18Hello World in Chef
- Hello World Souffle.
- This recipe prints the immortal words "Hello
world!", in a basically brute force way. It also
makes a lot of food for one person. - Ingredients.
- 72 g haricot beans
- 101 eggs
- 108 g lard
- 111 cups oil
- 32 zucchinis
- 119 ml water
- 114 g red salmon
- 100 g dijon mustard
- 33 potatoes
- Method.
- Put potatoes into the mixing bowl. Put dijon
mustard into the mixing bowl. Put lard into the
mixing bowl. Put red salmon into the mixing bowl.
Put oil into the mixing bowl. Put water into the
mixing bowl. Put zucchinis into the mixing bowl.
Put oil into the mixing bowl. Put lard into the
mixing bowl. Put lard into the mixing bowl. Put
eggs into the mixing bowl. Put haricot beans into
the mixing bowl. Liquefy contents of the mixing
bowl. Pour contents of the mixing bowl into the
baking dish. - Serves 1.
19My Sample Chef Program
- Danger Flu.
- Creates a very dangerous danger flu. Beware!
- Ingredients.
- 1 cup yogurt
- 5 g sneeze particulates
- 3 capers
- 4 chives
- 1 level teaspoon chopped parsley
- 1 rosemary sprig
- Method.
- Put yogurt into the mixing bowl. Combine chives.
Put capers into the mixing bowl. Add chopped
parsley into the mixing bowl. Pound the chives.
Combine sneeze particulates into the mixing bowl.
Stir the mixing bowl for 5 minutes. Beat chives
until pounded. Remove capers. Liquify contents of
the mixing bowl. Pour contents of the mixing bowl
into the baking dish. Add capers. Add rosemary
sprig. Stir for 2 minutes. Liquify contents of
the mixing bowl. Pour contents of the mixing bowl
into the baking dish. - Serves 1.
20Sample from last term
- Masterful Factorial Mashed Potatoes.
- Makes some dank mashed potatoes AND computes any
factorials that might need - computing! Upon executing the program it will
wait for you to enter in an - integer whose factorial you would like to
compute. After doing so, the - factorial will be computed and output to the
standard output. Pre-heat - temperature is roughly 350 degrees farenheight,
although this has not been - tested and the program will not seem to accept
this mark, even in Celsius. - Roughly speaking, cook until the top of the
potatoes is generally golden - brown with dark brown peaks at the highest
points. - Ingredients.
- 1 cup melted butter
- 5 g salt
- 1 kg baked potatoes
- 100 g chives
- 100 g pre-cooked bacon
- 100 g shredded sharp cheddar cheese
- 1 cup sour cream
21- Danger Flu.
- Creates a very dangerous danger flu. Beware!
- Ingredients.
- 1 cup yogurt
- 5 g sneeze particulates
- 3 capers
- 4 chives
- 1 level teaspoon chopped parsley
- 1 rosemary sprig
- Method.
- Put yogurt into the mixing bowl. Stack 1
- Combine chives. Stack 4
- Put capers into the mixing bowl. Stack 3 4
- Add chopped parsley into the mixing bowl. Stack
4 4 - Pound the chives.
22Code Aesthetics
- Absolutely beautiful. Reading it was just like
hearing a symphony, because every instruction was
sort of doing two things and everything came
together gracefully - Donald Knuth, The Art of Computer Programming
23Code Aesthetics
- plodding and excruciating to read, because it
just didnt possess any wit whatsoever. It got
the job done, but its use of the computer was
very disappointing. - Donald Knuth, The Art of Computer Programming
24Code Aesthetics
- Elegance
- Beauty
- Craftsmanship
- terms that are scarcely found in literary,
artistic, and cultural criticism
25Code Aesthetics
- A more sophisticated notion of code aesthetics
26Types of Alternative Code Aesthetics
- Obfuscation
- Parody
- Minimalism
- Structured Play (Double-Coding, Multiple-Coding)
- Puzzle
27Obfuscation
- Invert the clarity and beauty goals of
programming - Examples
- IOCCC
- JAPH
28Obfuscation
- int imain()for(i"ltii)--i"read('-'-'-'
,i"hello,world!\n",'/'/'/'))read(j,i,p)writ
e(j/pp,i---j,i/i)
29Obfuscation
- int imain()for(i"ltii)--i"read('-'-'-'
,i"hello,world!\n",'/'/'/'))read(j,i,p)writ
e(j/pp,i---j,i/i) - Character arithmetic
- Redefining function names
- Omitting syntax (C flexibility)
30Just Another Perl Hacker (JAPH)
- print "Just another Perl hacker,\n"
- Just Another Perl Hacker
- Code that prints Just another Perl hacker
- Leverage the flexibility of Perl (there are many
ways to do it)
31Just Another Perl Hacker (JAPH)
- _"krJhruaesrltre c a cnP,ohet"_.1,print2whi
le s/(..)(.)//
32Parody
- INTERCAL
- 1972, Don Woods, James Lyon (Princeton)
- Satirizes FORTRAN and COBOL, popular langauges of
the time
33INTERCAL
- DO ,1 lt- 13
- PLEASE DO ,1 SUB 1 lt- 234
- DO ,1 SUB 2 lt- 112
- DO ,1 SUB 3 lt- 112
- DO ,1 SUB 4 lt- 0
- DO ,1 SUB 5 lt- 64
- DO ,1 SUB 6 lt- 194
- DO ,1 SUB 7 lt- 48
- PLEASE DO ,1 SUB 8 lt- 22
- DO ,1 SUB 9 lt- 248
- DO ,1 SUB 10 lt- 168
- DO ,1 SUB 11 lt- 24
- DO ,1 SUB 12 lt- 16
- DO ,1 SUB 13 lt- 214
- PLEASE READ OUT ,1
- PLEASE GIVE UP
34Minimalism
- Comment on the small amount of structure needed
for universal computation - Small number of language constructs
- Isomorphism among language constructs
- Brainfuck
35Structured Play
- Using the free play in programming to create
meaning at the level of code - Characterized by a translation of statements into
symbolic structures - Variables as Shakespeare characters in
Shakespeare - Nouns as constants in Shakespeare with integer
values - Positive lord, angel, joy
- Negative bastard, beggar, Microsoft
- Neutral brother, cow, hair
- Program flow managed by commensurate symbolic
constructs - Open your heart, Speak your mind
36Multicoding
- Double Coding expression at the level of code
execution - Multicoding expression on even more registers
- Chef
- Code
- Execution
- Preparation
- Consumption
- Ook
- Code
- Execution
- Parody
- Performance
37Puzzle
- Provide counter-intuitive flow control,
operators, syntax, etc. to make programming
difficult - Related to, but different from obfuscation
- Obfuscation comments on a particular language and
its affordances - Puzzle languages comment more generally on the
process of programming - Related to the history of puzzles and riddles
- Malbolge
- Designed for difficulty of use
38Malbolge
- Trinary machine model
- Three-level digital logic (-1, 0, 1 o, 1, 2)
- Minimalism
- Counterintuitive flow
- Indirect instructions
- Malbolge performs transformations on instructions
- Three registers C, which points to the current
instruction - When the interpreter tries to execute a program,
it first checks to see if the current instruction
is a graphical ASCII character (33 - 126). If so,
it subtracts 33, adds C, mods by 94, then uses
the result as an index into the following table
of 94 characters (omitted) - After each instruction, the instruction set is
modified - Cryptography rather than programming
39Features
- Reflexivity
- commentary about the languages themselves
- commentary about programming in general
- response to the efficiency goals of professional
programming? - Simplicity
- The large expressive possibility space derived
from only a few affordances - Cognitive challenge
- The inherent puzzle process in programming
- Other statements yet to be explored?
40Expressive Spaces vs. Designed Tasks
- Compare Normans approach
- knowing what to do
- designing for error
- user-centered design
- Efficiency
- Intention
- Practicality
41Some Design Problems May Not Open Possibility
Spaces
42Others do
Exploration Error