Top Banner
PiTechnologies Tudor Prodan March 2009
46
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: Python @ PiTech - March 2009

PiTechnologies

Tudor ProdanMarch 2009

Page 2: Python @ PiTech - March 2009
Page 3: Python @ PiTech - March 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

Page 4: Python @ PiTech - March 2009

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

Page 5: Python @ PiTech - March 2009

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

Page 6: Python @ PiTech - March 2009

Why Python?

Page 7: Python @ PiTech - March 2009
Page 8: Python @ PiTech - March 2009
Page 9: Python @ PiTech - March 2009

Why Python

programming is fun again

Page 10: Python @ PiTech - March 2009

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

Page 11: Python @ PiTech - March 2009

Unfinished game

Java

Page 12: Python @ PiTech - March 2009

Unfinished game

C#

Page 13: Python @ PiTech - March 2009

Unfinished game

Python

Page 14: Python @ PiTech - March 2009

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

Page 15: Python @ PiTech - March 2009

Why Python

programming is fun again agility elegance you don't have to fight the language

Page 16: Python @ PiTech - March 2009

Why Python

Java is the COBOL of the 21st century.

-Sean Kelly, JPL, NASA

Page 17: Python @ PiTech - March 2009

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)

Page 18: Python @ PiTech - March 2009

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

Page 19: Python @ PiTech - March 2009

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:

Page 20: Python @ PiTech - March 2009

Python vs. C(++,#)/Java/..

)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

Page 21: Python @ PiTech - March 2009

Why Python

Example #2:

Create a Coordinate class which holds a latitude and longitude, to be used by a TelemetryTracker object.

Page 22: Python @ PiTech - March 2009

Why Python

this example will show Python vs. Java

but is actually Python vs. Java / C# / PHP / (most others)

Page 23: Python @ PiTech - March 2009

Why Python

Java:

Page 24: Python @ PiTech - March 2009

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

Page 25: Python @ PiTech - March 2009

Why Python

Java: Python:

Page 26: Python @ PiTech - March 2009

Why Python

The Java guys will say:

my IDE can generate most of that - code is read a lot more than written

Page 27: Python @ PiTech - March 2009

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

Page 28: Python @ PiTech - March 2009

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?

Page 29: Python @ PiTech - March 2009

Why Python

Java: Python:

Page 30: Python @ PiTech - March 2009

Why Python

Eventually, the code will end up in production..

Java: Python:

Page 31: Python @ PiTech - March 2009

Why Python

.. time passes ..

Page 32: Python @ PiTech - March 2009

Why Python

.. time passes ..

Eventually,decodeLat receives bad data

This is a bug!

What do we do?

- add a check

Page 33: Python @ PiTech - March 2009

Why Python

Add a setter and a getter:

Page 34: Python @ PiTech - March 2009

Why Python

Add a setter and a getter:

Let's try it out:

Page 35: Python @ PiTech - March 2009

Why Python

and the TelemetryTracker code:

Python:- still works

Java:- needs modification

Page 36: Python @ PiTech - March 2009

Why Python

in the end:

Python:- gives you a choice- you can even change your mind

Java/C#/PHP/..:- no choice

Page 37: Python @ PiTech - March 2009

Why Python

programming is fun again agility elegance you don't have to fight the language the language trusts you .. it accommodates you

Page 38: Python @ PiTech - March 2009

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

Page 39: Python @ PiTech - March 2009

Why Python

Python haslots & LOTSof good books:

Page 40: Python @ PiTech - March 2009

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

Page 41: Python @ PiTech - March 2009
Page 42: Python @ PiTech - March 2009

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

Page 43: Python @ PiTech - March 2009

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

Page 44: Python @ PiTech - March 2009

Why Python

But most interesting to us,lots of great web frameworks:

Page 45: Python @ PiTech - March 2009

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

Page 46: Python @ PiTech - March 2009