Upload
tudorprodan
View
218
Download
0
Tags:
Embed Size (px)
Citation preview
PiTechnologies
Tudor ProdanMarch 2009
What is Python
- a “very high-level language”- developed by Guido van Rossum - main features:
simple, yet powerful semantics object-oriented, but multi-paradigm clean syntax and coherent design focus on productivity rich standard library lots of high quality 3rd-party several good implementations:
CPython, Pypy, IronPython (2.0.1), PyS60, Jython
Jython
Jython, lest you do not know of it, is the most compelling weapon the Java platform has for its survival into the 21st century :-)
—Sean McGrath, CTO, PropylonJuly 31, 2003
CPython
Version history:1.0 – Jan 19942.0 – Oct 20003.0 – Dec 2008
Latest stable versions:2.6.1 and 3.0.1
Usable versions:2.5.x2.6.x = 2.5 + improvements + 3.0 features
(__future__)| | |__ maintenance version| |____ minor version|______ major version
Why Python?
Why Python
programming is fun again
Unfinished game
The problem of the unfinished game:
Let's say, hypothetically speaking, you met someone who told you they had two children, and one of them is a girl.
What are the odds that person has a boy and a girl?
-Jeff Atwood, December 30, 2008http://www.codinghorror.com/blog
Unfinished game
Java
Unfinished game
C#
Unfinished game
Python
Unfinished game
LoC readable? fun?
Java 53 barely nope
C# 49 kind of not really
Python 10 clean, much more fun concise than the above
Why Python
programming is fun again agility elegance you don't have to fight the language
Why Python
Java is the COBOL of the 21st century.
-Sean Kelly, JPL, NASA
Spirit of C
Python is close to the “Spirit of C” (more than C++/ Java/...), as per ISO C Standard's “rationale”:
trust the programmer don't prevent the programmer from doing what needs to be done keep the language small and simple provide only one way to do an operation make it fast, even if it's not guaranteed to be portable (the only bit not @100% in Python)
Python vs. C(++,#)/Java/..
everything is a first-class object - functions, methods, modules, ..
typing: strong, but dynamic - names have no type, objects have types
no “declarations”, just statements - implicit compilation, .pyc files - everything is run-time (compile-time too)
spare syntax, minimal ornamentation - no { } for blocks - no ( ) for conditions - a lot less punctuation
Python vs. C(++,#)/Java/..
In the 1960's the KGB was very interested in learning everything possible about the American space program, sending all sorts of spies to find every possible piece of information.
One afternoon, a breathless spy returned to headquarters with a piece of paper in his hand, excitedly shouting to his superior, "Comrade! Comrade! The Americans are using Lisp to write their rocket launching software!“
The commander was skeptical. "How do you know?"
"I broke into their research lab and stole a page from the teletype machine! It's not the whole program, but it's the final page and contains the concluding logic of the program! See for yourself!"
The commander looked at the page and smiled:
Python vs. C(++,#)/Java/..
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Why Python
Example #2:
Create a Coordinate class which holds a latitude and longitude, to be used by a TelemetryTracker object.
Why Python
this example will show Python vs. Java
but is actually Python vs. Java / C# / PHP / (most others)
Why Python
Java:
Philosophy
You know you've reached perfection in design, not when you have nothing more to add, but when you have nothing more to take away.
-Antoine de Saint Exupery
Why Python
Java: Python:
Why Python
The Java guys will say:
my IDE can generate most of that - code is read a lot more than written
Why Python
The Java guys will say:
my IDE can generate most of that - code is read a lot more than written
but, your fields are public - Python philosophy
Why Python
The Java guys will say:
my IDE can generate most of that - code is read a lot more than written
but, your fields are public - Python philosophy
can't we apply this to other languages?
Why Python
Java: Python:
Why Python
Eventually, the code will end up in production..
Java: Python:
Why Python
.. time passes ..
Why Python
.. time passes ..
Eventually,decodeLat receives bad data
This is a bug!
What do we do?
- add a check
Why Python
Add a setter and a getter:
Why Python
Add a setter and a getter:
Let's try it out:
Why Python
and the TelemetryTracker code:
Python:- still works
Java:- needs modification
Why Python
in the end:
Python:- gives you a choice- you can even change your mind
Java/C#/PHP/..:- no choice
Why Python
programming is fun again agility elegance you don't have to fight the language the language trusts you .. it accommodates you
Why Python
programming is fun again agility elegance you don't have to fight the language the language trusts you .. it accommodates you .. and will not go out of it's way to stop you
Why Python
Python haslots & LOTSof good books:
Why Python
programming is fun again agility elegance you don't have to fight the language the language trusts you .. it accommodates you .. and will not go out of it's way to stop you good documentation (lots of books) good support: lots of forums, mailing lists, IRC
Why Python
Large number of high quality 3rd-party libraries and frameworks:
- networking: twisted, cogen, concurrence- scientific: NumPy, ScyPy, PyEvolve (genetic algorithms)- testing: PyUnit, Google Mox- fuzzing: Fuzz- database: SQLAlchemy, Elixir, Django ORM- web crawling: BeautifulSoup, lxml, Scrappy- game development: PyGame- GUI: PyGTK, wxPython, PyQt, GTK#-templating: Genshi, Mako, Kid, Jinja2- cryptography: M2Crypto, PyCrypto, Keyczar,
.. many, many others
Why Python
programming is fun again agility elegance you don't have to fight the language the language trusts you .. it accommodates you .. and will not go out of it's way to stop you good documentation (lots of books) good support: lots of forums, IRC, mailing lists lots of high quality 3rd-party libraries
Why Python
But most interesting to us,lots of great web frameworks:
Why Python
programming is fun again agility elegance you don't have to fight the language the language trusts you .. it accommodates you .. and will not go out of it's way to stop you good documentation (lots of books) good support: lots of forums, IRC, mailing lists lots of high quality 3rd-party libraries many great web frameworks