Top Banner
+ CS1001. Python. November 14 th , 2011
18

CS1001 . Python.

Feb 22, 2016

Download

Documents

CS1001 . Python. November 14 th , 2011. Scripting languages. Scripting languages foster an exploratory , incremental approach to writing code Historically interpreted Favor your time and energy over the CPU’s Include libraries for common tasks Examples - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS1001 .  Python.

+

CS1001. Python.November 14th, 2011

Page 2: CS1001 .  Python.

+Scripting languages

Scripting languages foster an exploratory, incremental approach to writing code

Historically interpreted Favor your time and energy over the CPU’s Include libraries for common tasks Examples

AWK [1977], Perl [1987], Python [1991]

Page 3: CS1001 .  Python.

+Style

Java: public class HelloWorld {public static void main(String[] args) {System.out.println("Hello world");}

}

Python: print “hello world”Perl: print “hello world\n”;AWK: BEGIN { print "Hello, world!" }

Page 4: CS1001 .  Python.

+Philosophy

More timeThinking about the problemExperimenting with solutions

Less timeWriting code

Page 5: CS1001 .  Python.

+Perl

Larry Wall, 1987 (linguist)Report writing (text processing!)“There is more than one way to do it.”What was text processing essential for

in the early 90s?

Page 6: CS1001 .  Python.

+Websites per year (log scale)

Source: http://www.useit.com/alertbox/web-growth.html

Page 7: CS1001 .  Python.

+Which is more important?

Code should be easy to writeCode should be easy to read(This is a false dichotomy)

Page 8: CS1001 .  Python.

+Obfuscated code contest

`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=($!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++; $_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`

Perl

Page 9: CS1001 .  Python.

+Obfuscated code contest

`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=($!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++; $_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`

$ Just another Perl hacker.

Perl

Page 10: CS1001 .  Python.

+Obfuscated code contest

C

Page 11: CS1001 .  Python.

+Obfuscated code contest

C

Page 12: CS1001 .  Python.

+Python

Emphasizes readability“There should be one – and preferably

only one – way to do it.”Large standard library (batteries

included)Cross platform and open source

Page 13: CS1001 .  Python.

+Parsing text files (and reading them back!)

Page 14: CS1001 .  Python.

+Getting the weather

http://weather.yahooapis.com/forecastrss?w=2459115

Page 15: CS1001 .  Python.

+Technically

Dynamic typingGarbage collectedMulti-paradigmCompiles to bytecodeException based error handlingExtensible

Page 16: CS1001 .  Python.

+Dynamic typing

pi = 3.1459

print pi

pi = "I'd love to have " + str(pi) + " pies"

print pi

print "In fact, I'd like one more"

pi = pi + 1 # TypeError: cannot concatenate 'str' and 'int' objects

print pi

Page 17: CS1001 .  Python.

+BooksOrdered by technical complexity - notice anything?

Page 18: CS1001 .  Python.

+Internet humor

Source: http://xkcd.com/534/