Talk Like a Pirate David Reed Creighton University [email protected] davereed Captain Jack...
-
Upload
deirdre-lloyd -
Category
Documents
-
view
212 -
download
0
Transcript of Talk Like a Pirate David Reed Creighton University [email protected] davereed Captain Jack...
Talk Like a Pirate
David ReedCreighton University
[email protected] www.creighton.edu/~davereed
Captain Jack Sparrow
Captain Blackbeard
Captain Redpen
2
Talk Like a Pirate Day
International Talk Like a Pirate Day – September 19th founded by John Baur and Mark Summers in 1995 popularized by columnist Dave Barry see www.talklikeapirate.com for more details
official Web site had a simple pirate translator poorly done, but inspiring
"nifty" characteristics can be used to introduce/demonstrate a variety of programming concepts
GUIevent-driven programmingmeta-programmingstring methods, regular expressions
can be used in a variety of classes using different languages CS0 with HTML/JavaScriptCS1 or CS2 with C++/JavaWeb Design/Programming
it's fun!
3
Pirate Translator (version 1.0)
used in a Web-based CS0 course
students critiqued the design of the official page
developed a "better" translation page one button per word/phrase when user clicks on button, translation appears in a
text box
<input type="button" value="hello" onClick="document.PForm.Output.value += 'ahoy ';" />
note: this could easily be done in Java using AWT/Swing
advantages: simple & intuitive easy to extend (just add more buttons) minimal "programming" open for creativity (layout, images, extended
vocabulary, …)
4
Pirate Translator (version 2.0)
disadvantage of version 1: button repetition adding a new word/phrase meant adding a new button – danger of inconsistencies
more general solution: metaprogramming store words/phrases in a list structure
to extend the vocabulary, simply add to the list use JavaScript to dynamically generate the buttons
PHRASES = [["Greetings", "hello", "ahoy", "pardon me", "avast", "excuse me", "arrr"], ["People", "sir", "matey", "madam", "proud beauty", "miss", "comely wench"], ["Questions", "where is", "whar be", "can you help me find", "know ye", "is that", "be that", "how far is it to", "how many leagues to"], . . . ];
for (var i = 0; i < PHRASES.length; i++) { document.write("<tr valign='top'><td>" + PHRASES[i][0] + ": <td>"); for (var j = 1; j < PHRASES[i].length; j+=2) { document.write("<input type=\"button\" value=\"" + PHRASES[i][j] + "\" onClick='document.PirateForm.Output.value += \"" + PHRASES[i][j+1] + " \";'>\n"); }}
could use a Java/C++ program to generate the HTML document
5
Pirate Translator (version 3.0)
disadvantage of version 2: translation is limited to provided buttons would like to take entire phrases, translate "piratey" parts, leave rest alone
alternative approach used in upper-level Web Programming course user enters text to be translated string methods used to search for words/phrases to translate
utilize regular expressions to match word boundaries, ignore case replace matched word/phrase with pirate translation
PHRASES = [["hello", "ahoy"], ["hi", "yo-ho-ho"], ["pardon me", "avast"], ["excuse me", "arrr"], ["yes", "aye"], ["my", "me"], ... ];
for (var i = 0; i < PHRASES.length; i++) { var toReplace = new RegExp("\\b"+PHRASES[i][0]+"\\b", "i"); var index = text.search(toReplace); while (index != -1) { if (text.charAt(index) >= "A" && text.charAt(index) <= "Z") { text = text.replace(toReplace, Capitalize(PHRASES[i][1])); } else { text = text.replace(toReplace, PHRASES[i][1]); } index = text.search(toReplace); }}
here in JavaScript, but could be any language with strings (regular expressions a plus)
6
It be fun!
in conclusion: a pirate translator is fun and engaging
can be used in a multiple courses to illustrate multiple concepts
can provide an open-ended challenge to students critique/design a user interface add to the vocabulary of the translator add new features
e.g., insert random Arrrrrrr's explore regular expressions
e.g., translate words ending in ing to in' (but not swing or handspring)
Give it a try in your class, or walk the plank like the lily-livered landlubber you are!