- Beautiful is better than ugly.
- Explicit is better than implicit.
- Simple is better than complex.
- Complex is better than complicated.
- Flat is better than nested.
- Sparse is better than dense.
- Readability counts.
- Special cases aren't special enough to break the rules.
- ...
Write once, run everywhere
Syntax and semantics
Data types
Primitives:
- byte, short, int, long, float, double, boolean, char
Java collections framework
- Immutable types?
- lists? tuples? dicts? sets? in PHP these are Array!
- In PHP we have: boolean, int, float, string, array, object, resource, null
P.S. Standart PHP Library (SPL)
OOP
- Multiple inheritance
- No interfaces
- No abstract classes and methods
- No access specifiers
- Even class is an object
- __metaclass__
- Multiple inheritance: huh?
- No interfaces: WTF?
- No abstract classes and methods: WTF?
- No access specifiers: WTF?
- Even class is an object: ?
- __metaclass__: WTF?
- Multiple inheritance: huh?
- No interfaces: WTF?
- No abstract classes and methods: WTF?
- No access specifiers: WTF?
- Even class is an object: ah?
- __metaclass__: WTF?
Threading
Performance
Conclusion
Python for switch-heads
1991
1995
PEP #20: Zen of Python
- whitespace intendation
- frequently using English keywords where other languages use punctuation: x if true else y
- list comprehensions
- index and slice expressions [start:stop:step]
- statements and expressions distinction:
if a=1: ... #error
- whitespace intendation: WTF?
- statements and expressions distinction: ok
- whitespace intendation: WTF?
- statements and expressions distinction: ok, mostly just prevents errors
Immutable
- str, bytes, tuple, frozenset, int, float, complex, bool
Mutable
- bytearray, list, set, dict
P.S. Everything is an object, and we have collections package
- No threading in PHP, so I don't care
P.S. ...yes, I know about PECL threads
- Global Interpreter Lock (GIL)
- but there's threading API
- async framorks try to "pack" work in CPU using threading API
interpreted, compiles to bytecode, JIT compiler
- interpreted, compiles to bytecode (*.pyc), resuses compiled *.pyc's
- there are several runtimes available: CPython, Jython, PyPy, IronPython...
- there are tricks: sorting, string concatenation, dot dereferencing, etc
P.S. see CPython sources for details
interpreted, number of opcode cachers available
Python is OK, but I'll miss Java*
*P.S. Java4ever =)
Python is great! I'm switching!*
*denotes most common reaction =)