Visualizing Code l Does the SapirWhorf hypothesis have

  • Slides: 15
Download presentation
Visualizing Code l Does the Sapir-Whorf hypothesis have relevance to programming languages and code?

Visualizing Code l Does the Sapir-Whorf hypothesis have relevance to programming languages and code? Ø Ø Ø l What factors (should) influence language choice? Ø Ø Ø l What is a language? Should we look at programming language grammars? What languages should we investigate? How do we measure efficiency? What problem are we solving? What do we know, what itch are we scratching? How do we think about code? Visualizing Code 1

Why do we know about this? Visualizing Code 2

Why do we know about this? Visualizing Code 2

http: //chir. ag/phernalia/preztags/ l Similarities to Minard’s graphic? Ø Ø Ø Timeline Size matters

http: //chir. ag/phernalia/preztags/ l Similarities to Minard’s graphic? Ø Ø Ø Timeline Size matters Shading/color matter Ø l What state-of-the-art technologies enable this? Ø Ø Ø Done in CSS and HTML, no flash, no Javascript, no … How does this work? Is there something here for us to use in our courses? Visualizing Code 3

Tagcloud of ? http: //www. tagcloud. com Visualizing Code 4

Tagcloud of ? http: //www. tagcloud. com Visualizing Code 4

Tastes Great! aka Emacs v. vi [two years ago] we lamented the state of

Tastes Great! aka Emacs v. vi [two years ago] we lamented the state of our educational discipline. There were remnants of the language wars, extensive focus on the best way - or tool - to teach language X, and ambivalence toward the state of our discipline. I think languages matter since languages determine how easy or hard it is to work with the base language constructs. To do anything, we and our students must express abstract ideas in one or more concrete languages. Visualizing Code 5

Fundamental parts of Tagcloud l Determining word frequencies Ø Ø Ø l Differentiate among

Fundamental parts of Tagcloud l Determining word frequencies Ø Ø Ø l Differentiate among frequencies Ø Ø Ø l What is a word? Issues in stemming? Other issues? Smooth curve? Step function? Other issues? Output Ø Straightforward? CSS? … Visualizing Code 6

Language and Social Experiment l l l Post to SIGCSE and Dulug Submit code

Language and Social Experiment l l l Post to SIGCSE and Dulug Submit code 70 out of 565? Visualizing Code 7

Eight solutions in C++ Visualizing Code 8

Eight solutions in C++ Visualizing Code 8

Twenty-one Java solutions Visualizing Code 9

Twenty-one Java solutions Visualizing Code 9

Seventeen Python Solutions Visualizing Code 10

Seventeen Python Solutions Visualizing Code 10

Eleven Perl Solutions Visualizing Code 11

Eleven Perl Solutions Visualizing Code 11

What about Performance? l Kjv 10. txt, time in seconds, read only, read as

What about Performance? l Kjv 10. txt, time in seconds, read only, read as percentage Perl 1. 766 0. 84 47. 5% Python 2. 373 0. 71 29. 8% C 0. 352 0. 187 53. 1% C++ 1. 29 0. 254 19. 7% Java 3. 592 2. 361 65. 7% Visualizing Code 12

What about understanding? l Shade in yellow the code that updates counts Ø l

What about understanding? l Shade in yellow the code that updates counts Ø l Shade in another color the code that “sorts” the data appropriately Ø l C++, Java, Python, Perl Where should you add this line or its equivalent? Ø word = remove. Punctutation(word); Ø What is the equivalente in the different languages? Stemming (reduce to canonical form) location? Ø Visualizing Code 13

Alternatives (that don’t work: -) cat $1 | tr A-Z a-z | tr 't'

Alternatives (that don’t work: -) cat $1 | tr A-Z a-z | tr 't' ' ' | tr ' ' 'n' | grep -v '^$' | sort | uniq -c | sed -e 's/^ *//' | sort -k 1, 1 nr -k 2, 2 | tr ' ' 't' awk '{for (i=1; i<=NF; i++) print tolower($i)}' $1 -key=1 rn, 2 d | sort | uniq -c | sort - cat ${1} | tr A-Z a-z | tr -sc A-Za-z '12' | sort | uniq -c | sort -r -n awk '{for (i=1; i<=NF; i++) print tolower($i)}' $1 | sort | uniq -c | LC_COLLATE=C sort --key=1 rn, 2 | awk '{print $1"t"$2}' tr "[: upper: ]" "[: lower: ]" < $1 | tr -s "[: space: ]" "[n*]" | sort | uniq -c | sort -n -r -b -s -k 1, 1 | sed 's/^ *//' | tr "[: blank: ]" "[t*]" Visualizing Code 14

What about fun? l Making the code work with PHP Ø Ø Ø l

What about fun? l Making the code work with PHP Ø Ø Ø l Documentation for sorting was a headache Finally made it work, but spent 2 hours Not fun Making the code work with Ruby Ø Ø Ø Documentation online was superb Took 20 minutes to get canonical solution Was very fun Visualizing Code 15