PHP developers should try Python.
PHP and Python both are dynamic typed language, so there is no point the discuss anything related in this aspect. Exception is first class citizen
1 2 3 4 |
try: a = 1 / 0 except: print 'Caught' |
Prints ‘Caught’ Let’s look at PHP:
1 2 3 4 5 6 |
try{ $a = 1 / 0; }catch (Exception $e){ print "Caught"; } I cannot believe by default this still gives me PHP Warning: Division by zero |
Better functions Imagine you can write functions like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
def marry(man, woman): ... marry('John', 'Julie') marry(woman='Julie', man='John') def party(*args): for person in args: print person party('John') party('John', 'Ben', ...) def save(name, *kwargs): data = {'name': name} data.update(kwargs) write_to_db(data) save('John') save('John', gender='male', birthday='01/01/1970') |
Short-lived vs Long-lived Almost all PHP scripts are short-lived, including most frameworks, which… Read More »