Metaprogramming

As everything in Python is an object, classes are created by instanciating a super class called a metaclass. Metaprogramming is about overriding some behavior of that metaclass. This is often used to follow the DRY principle (Don’t Repeat Yourself) in order to avoid repeating the same or similar code inside a program. Metaprogramming is thus often used by frameworks such as Django as it helps to make their API much easier to use.
Continue reading

Dynamic typing (part 1)

Python is a dynamically-typed language, just like PHP, JavaScript or Ruby, and contrary to statically-typed languages such as C/C++, Java or Scala.

In a dynamically-typed language, the code can never know in advance what will be the type of any variable. You can define a function to perform a particular operation on, say, a collection, but unless you explicitly filter out an argument that is not a collection, the code is never certain that it is indeed one – and the bytecode compiler sure cannot be certain either.

Using dynamic types has consequences for the language – both from a conceptual standpoint and from an implementation standpoint.
Continue reading