43
The Poetics of Code LCC 2700: Intro to Computational Media

The Poetics of Code LCC 2700: Intro to Computational Media

Embed Size (px)

Citation preview

Page 1: The Poetics of Code LCC 2700: Intro to Computational Media

The Poetics of Code

LCC 2700: Intro to Computational Media

Page 2: The Poetics of Code LCC 2700: Intro to Computational Media

Aesthetics

The philosophy of art

Immanuel Kant (18th c) - the philosophy of perception

The criticism of taste

Literary, Visual, Gastronomic, Musical…

Page 3: The Poetics of Code LCC 2700: Intro to Computational Media

Poetics

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, endUnity of action: plotStruggle: agôn

Comedy: imitation of “low” behaviors (presumably to encourage avoiding them)

Page 4: The Poetics of Code LCC 2700: Intro to Computational Media

Programming

• We’ve been talking about procedurality as it produces expression

• But is programming itself art?

• Is there an inter-relation between programs themselves and procedural expression?

Page 5: The Poetics of Code LCC 2700: Intro to Computational Media

Paradigms of Programming

Imperative Languagesprogram state + statements: walk through the code line by line as instructions, with some branchingC, Java, Etc.

Declarative LangaugesConditions that describe a solution space rather than executing a set of instructions.Prolog, SQL

Functional LangaugesThe evaluation of functions rather than the execution of instructionsLisp, Logo, Scheme

Machine LanguagesDirect manipulation of registers at the processor-levelAssembly

Page 6: The Poetics of Code LCC 2700: Intro to Computational Media

Programming Style

• Standards for composing code• Readability

– Variable names– Consistency– Comments

• Typography– Indentations– Line breaks– Searchability

• Naming– Evocative variable names

Page 7: The Poetics of Code LCC 2700: Intro to Computational Media

Hungarian 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

Page 8: The Poetics of Code LCC 2700: Intro to Computational Media

Programming 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

Page 9: The Poetics of Code LCC 2700: Intro to Computational Media

Coding Standards or Conventions

get a b c

if a < 12 and b < 60 and c < 60

return true

else

return false

if(hours<12&&minutes<60&&seconds<60){return true;}else{return false;}

get hours minutes seconds

if hours < 12 and minutes < 60 and seconds < 60

return true

else

return false

if (hours < 12 && minutes < 60 && seconds < 60)

{

return true;

}

else

{

return false;

}

Page 10: The Poetics of Code LCC 2700: Intro to Computational Media

Programming 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

Page 11: The Poetics of Code LCC 2700: Intro to Computational Media

Programming Languages

• Themselves designed for maximum productivity

• Object-oriented programming as a kind of Fordist manufacturing process

• “Automatic Factory”?

• Produce “poetic output”

• Facilitate “poetic productivity”

Page 12: The Poetics of Code LCC 2700: Intro to Computational Media

Code and the Program

• HTML as a possible example

• The markup and the layout are both viewable to the end user

• The markup’s “quality” is part of the experience

• “How did they do that” (e.g., the single pixel)

Page 13: The Poetics of Code LCC 2700: Intro to Computational Media

Upsetting 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 Apollinaire’s

Calligrammes)• Typing• Christmas Tree

Page 14: The Poetics of Code LCC 2700: Intro to Computational Media

New 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

Page 15: The Poetics of Code LCC 2700: Intro to Computational Media

Hello World in Brainfuck

• ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.

Page 16: The Poetics of Code LCC 2700: Intro to Computational Media

Hello World in Brainfuck

++++++++++

[

>+++++++>++++++++++>+++>+<<<<-

] The initial loop to set up useful values in the array

>++. print 'H’

>+. print 'e’

+++++++. 'l'

. 'l’

+++. 'o’

>++. space

<<+++++++++++++++. 'W’

>. 'o’

+++. 'r’

------. 'l’

--------. 'd’

>+. '!’

>. newline

Page 17: The Poetics of Code LCC 2700: Intro to Computational Media

Hello World in Malebolge

(=<`:9876Z4321UT.Q+*)M'&%$H"!~}|Bzy?=|{z]KwZY44Eq0/{mlk** hKs_dG5[m_BA{?-Y;;Vb'rR5431M}/.zHGwEDCBA@98¥6543W10/.R,+O<

Page 18: The Poetics of Code LCC 2700: Intro to Computational Media

Project 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.

Page 19: The Poetics of Code LCC 2700: Intro to Computational Media

Hello 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 beans101 eggs108 g lard111 cups oil32 zucchinis119 ml water114 g red salmon100 g dijon mustard33 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.

Page 20: The Poetics of Code LCC 2700: Intro to Computational Media

My Sample Chef Program

Danger Flu.

Creates a very dangerous danger flu. Beware!

Ingredients.1 cup yogurt5 g sneeze particulates3 capers4 chives1 level teaspoon chopped parsley1 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.

Page 21: The Poetics of Code LCC 2700: Intro to Computational Media

Sample from last termMasterful Factorial Mashed Potatoes.

Makes some dank mashed potatoes AND computes any factorials that might needcomputing! Upon executing the program it will wait for you to enter in aninteger whose factorial you would like to compute. After doing so, thefactorial will be computed and output to the standard output. Pre-heattemperature is roughly 350 degrees farenheight, although this has not beentested and the program will not seem to accept this mark, even in Celsius.Roughly speaking, cook until the top of the potatoes is generally goldenbrown with dark brown peaks at the highest points.

Ingredients.1 cup melted butter5 g salt1 kg baked potatoes100 g chives100 g pre-cooked bacon100 g shredded sharp cheddar cheese1 cup sour cream

Cooking time: 10 minutes.

Method.Take baked potatoes from refrigerator. Put melted butter into the mixing bowl.Put pre-cooked bacon into the mixing bowl. Fold chives into the mixing bowl.Put salt into the mixing bowl. Fold shredded sharp cheddar cheese into themixing bowl. Blend the baked potatoes. Combine baked potatoes into the mixingbowl. Combine sour cream into the mixing bowl. Whip the baked potatoes untilblended. Pour contents of the mixing bowl into the baking dish.

Serves 4.

Page 22: The Poetics of Code LCC 2700: Intro to Computational Media

Danger Flu.

Creates a very dangerous danger flu. Beware!

Ingredients.1 cup yogurt5 g sneeze particulates3 capers4 chives1 level teaspoon chopped parsley1 rosemary sprig

Method.Put yogurt into the mixing bowl. Stack = 1 Combine chives. Stack = 4Put capers into the mixing bowl. Stack = 3 4 Add chopped parsley into the mixing bowl. Stack = 4 4 Pound the chives.

Combine sneeze particulates into the mixing bowl. Stack = 20 4Stir the mixing bowl for 5 minutes. Stack = 4 20

Beat chives until pounded. Decrement chives, loop until 0 (Stack = 100 100)Remove capers. Stack = 97 100Liquify contents of the mixing bowl. Stack = a dPour contents of the mixing bowl into the baking dish. Stack = a d, Baking Dish = a dAdd capers. Stack = 100 100Add rosemary sprig. Stack = 101 100Stir for 2 minutes. Stack = 100 101Liquify contents of the mixing bowl. Stack = d ePour contents of the mixing bowl into the baking dish. Baking Disk = d e a d

Serves 1. Writes dead to stdout

Page 23: The Poetics of Code LCC 2700: Intro to Computational Media

Code 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

Page 24: The Poetics of Code LCC 2700: Intro to Computational Media

Code Aesthetics

“…plodding and excruciating to read, because it just didn’t 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

Page 25: The Poetics of Code LCC 2700: Intro to Computational Media

Code Aesthetics

• Elegance

• Beauty

• Craftsmanship

• … terms that are scarcely found in literary, artistic, and cultural criticism…

Page 26: The Poetics of Code LCC 2700: Intro to Computational Media

Code Aesthetics

• A more sophisticated notion of code aesthetics

Page 27: The Poetics of Code LCC 2700: Intro to Computational Media

Types of Alternative Code Aesthetics

• Obfuscation• Parody• Minimalism• Structured Play (Double-Coding, Multiple-Coding)• Puzzle

Page 28: The Poetics of Code LCC 2700: Intro to Computational Media

Obfuscation

• Invert the clarity and beauty goals of programming

• Examples– IOCCC– JAPH

Page 29: The Poetics of Code LCC 2700: Intro to Computational Media

Obfuscation

int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-' ,i+++"hello,world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}

Page 30: The Poetics of Code LCC 2700: Intro to Computational Media

Obfuscation

int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-' ,i+++"hello,world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}

• Character arithmetic• Redefining function names• Omitting syntax (C flexibility)

Page 31: The Poetics of Code LCC 2700: Intro to Computational Media

Just 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”)

Page 32: The Poetics of Code LCC 2700: Intro to Computational Media

Just Another Perl Hacker (JAPH)

$_="krJhruaesrltre c a cnP,ohet";$_.=$1,print$2while s/(..)(.)//;

Page 33: The Poetics of Code LCC 2700: Intro to Computational Media

Parody

• INTERCAL• 1972, Don Woods, James Lyon (Princeton)• Satirizes FORTRAN and COBOL, popular langauges of

the time

Page 34: The Poetics of Code LCC 2700: Intro to Computational Media

INTERCAL

DO ,1 <- #13PLEASE DO ,1 SUB #1 <- #234DO ,1 SUB #2 <- #112DO ,1 SUB #3 <- #112DO ,1 SUB #4 <- #0DO ,1 SUB #5 <- #64DO ,1 SUB #6 <- #194DO ,1 SUB #7 <- #48PLEASE DO ,1 SUB #8 <- #22DO ,1 SUB #9 <- #248DO ,1 SUB #10 <- #168DO ,1 SUB #11 <- #24DO ,1 SUB #12 <- #16DO ,1 SUB #13 <- #214PLEASE READ OUT ,1PLEASE GIVE UP

Page 35: The Poetics of Code LCC 2700: Intro to Computational Media

Minimalism

• Comment on the small amount of structure needed for universal computation

• Small number of language constructs• Isomorphism among language constructs• Brainfuck

Page 36: The Poetics of Code LCC 2700: Intro to Computational Media

Structured 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

Page 37: The Poetics of Code LCC 2700: Intro to Computational Media

Multicoding

• 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

Page 38: The Poetics of Code LCC 2700: Intro to Computational Media

Puzzle

• 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

Page 39: The Poetics of Code LCC 2700: Intro to Computational Media

Malbolge

• 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

Page 40: The Poetics of Code LCC 2700: Intro to Computational Media

Features

• 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?

Page 41: The Poetics of Code LCC 2700: Intro to Computational Media

Expressive Spaces vs. Designed Tasks

• Compare Norman’s approach– “knowing what to do”– “designing for error”– “user-centered design”

• Efficiency • Intention• Practicality

Page 42: The Poetics of Code LCC 2700: Intro to Computational Media

Some Design Problems May Not Open Possibility Spaces

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 43: The Poetics of Code LCC 2700: Intro to Computational Media

Others do

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

ExplorationError