19
Object Oriented Programming Paradigms in by Chandrashekar Babu http://www.chandrashekar.info/ <[email protected]>>

Python OOP Paradigms and Pythonisms

Embed Size (px)

Citation preview

Object����������� ������������������  Oriented����������� ������������������  Programming����������� ������������������  ����������� ������������������  Paradigms����������� ������������������  in����������� ������������������  ����������� ������������������  

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  

by Chandrashekar Babu

http://www.chandrashekar.info/<[email protected]>>

Why ?1. Most of us have learnt

OOP paradigms using

Java/C++/C#

Due to academic syllabus in most colleges and universities

Why ?2. Most of us have thought that

the best way to write a OO program is to start with creating

a Class!

And hope that JAVA/.NET vm’s figure out how to run our program

Ouch!

Shouldn’t this suffice ?

#PythonZen_9: Although practicality beats purity.

Pythonisms!

Pythonisms #1.Everything is an Object!

This includes classes, modules, functions, types

“If I can touch it - I can surely destroy it!”

Functions are first class objects!

Classes are first class objects!

Modules are first class objects too!

Pythonisms #2.All identifiers are

references to Objects!

This includes variables, object’s attributes,

indices of a sequence, keys of a mapping

Pythonisms #3.All assignments are

assigned-by-references!

All objects are passed-by-references!

“Why copy when you can just refer ?”

Pythonisms #4.All definitions

happen in runtime!

Thus var = Noneis simply unnecessary!

“What’s the point in holding a label when don’t know where you’d stick them to ?”

Pythonisms #5.Variables on their own are

typeless!

Instead, they act as labels to Objects - thus deriving Object’s type.

Note: Objects however are strongly typed!

Pythonisms #6.There is no

“type-casting”!

Instead you do “type conversion”

or “type construction”

“A number is a number! A string is a string!”

Pythonisms #7.Duck-Typing

over Type-checking!

“When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.”

- James Whitcomb Riley

- Alex Martelli

Pythonisms #8.

Introspection over

Inheritance!

“Ask what the object can do - not where they come from!”

- Me :-)

Pythonisms #9.Generalized functions

over interface methods!

“Sure - I can throw a camera, a pen or a brick - though these objects might have no idea about what to do if thrown around!”

- Me :-)

Pythonisms #10.Succinct-ness

over verbosity!

int(“10”) over

Integer.parseInt(“10”)

Questions ?

‣ Contact: Name: Chandrashekar Babu. Website: http://www.chandrashekar.info/ Email: [email protected] LinkedIn: http://in.linkedin.com/in/chandrashekarbabu/