a new look at exception handling

I was taught that good exception handing means:

  • Don’t catch all exceptions -> only catch exceptions you know how to handle
  • If your application needs to raise an exception, create a unique exception and raise it.
  • Never silently ignore exceptions (it’s even part of the zen of python)

I strongly believe in these rules. they, in my opinion, make your code more readable, testable and easier to debug. Anyway, I just read a nice article with nice tips about exception handling.

By the way, I also add the locals (it’s really easy in python) of the exception I just raised. It helped a few times!

Internals of python string interning

String interning is an implementation of the Flyweight design pattern:

In computer programming, flyweight is a software design pattern. A flyweight is an object that minimizes memory usage by sharing as much data as possible with other similar objects; it is a way to use objects in large numbers when a simple repeated representation would use an unacceptable amount of memory. Often some parts of the object state can be shared, and it is common practice to hold them in external data structures and pass them to the flyweight objects temporarily when they are used.

Almost every language has an implementation of string interning and python is no exception.

I just read a The internals of Python string interning and found it very interesting!

Boost productivity with virtualenv

“A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.” - The Hitchhiker’s Guide to Python

In this blog post I’ll explain about virtualenv, venv, and how I use both.

Read More

*args and **kwargs

*args and **kwargs are a big deal in the python world, and to me, a bit magical:
On one hand, they allow one to inject arbitrary arguments to functions, which is extremely powerful.

On the other hand, if abused, can make your code extremely complex and unreadable.

I suggest reading args and kwargs to understand how they work in depth.

the march towards go

Have you heard about the go programming language?
I just read The March Towards Go and got extremely interested.

Here’s what go’s creators, Rob Pike & Ken Thomson, said about it:

Go attempts to combine the development speed of working in a dynamic language like Python with the performance and safety of a compiled language like C or C++. In our experiments with Go to date, typical builds feel instantaneous; even large binaries compile in just a few seconds. And the compiled code runs close to the speed of C. Go is designed to let you move fast.

We’re hoping Go turns out to be a great language for systems programming with support for multi-processing and a fresh and lightweight take on object-oriented design, with some cool features like true closures and reflection.

python & the global interpreter lock

I’m an internals guy. I read CLR via C# to understand the inner workings of C# (and I highly recommend it!)

After learning python’s syntax, I started digging into the fun stuff.
I just found out the python has a global interpreter lock (GIL) that basically makes python a single threaded language (not really).

In upcoming posts I’ll share links that explain how to bypass/handle this limitation (hint: multiprocessing). But for now, take a look at these articles:

Hello, World!

Dear diary, I decided to ditch you and open up a blog!

Why?

Mainly because my memory is horrible and I need a place to put my thoughts.
I hope somebody will find it useful!

what now?

Now I’ll start writing things :)