DRY Principles through Python Decorators

Date Tags python

Python decorators are a powerful tool to remove redundancy. Along with modularizing functionality into appropriate bite-sized methods, it makes even the most complex workflows into concise functionality.

For example, let's look at the Django web framework, which handles requests by methods which receive a method object and return a ...

more ...

The inevitable cons of overloading methods

Date Tags theory

Day 1

You see a simple method that draws a triangle. Currently, it takes in a specific size:

drawTriangle(float size);

You've been told that in the past, we only needed one kind of triangle. Now we need to be able to choose the color. No biggie, we have ...

more ...

Increment-Decrement for Emacs

Here's a small increment/decrement function I wrote, because I like how vim has one:

;; check if string is an integer
(defun string-integer-p (string)
  (if (string-match "\\`[-+]?[0-9]+\\'" string)

;; Decrement Int
(defun decrement ()
  "Decrement the integer that the cursor is on."
  (let ((x (thing-at-point 'symbol)))
    (when (string-integer-p ...
more ...

Adding JSONP to turbogears


from tg import json_encode, responsefrom tg.render import _get_tg_varsdef render_jsonp(template_name, template_vars, **kwargs):callback = template_name or kwargs.pop('callback', None) or 'callback'for key in _get_tg_vars():del template_vars[key]response.headers['Content-Type'] = 'text/javascript'return '%s(%s)' % (template_name, json_encode(template_vars))from myapp.config.app_cfg import base_configbase_config.render_functions['jsonp'] = render_jsonpbase_config.mimetype_lookup ...

more ...

Move over bash: Python is my language for setup scripts now.

I know when people discuss using programming languages, there's two main schools of thought:

  • Use the same language for as much of your stack as possible
  • Use the language that's most appropriate for each part of the stack as much of possible.

Clearly, there's very strong advantages ...

more ...

About Yusuke Tsutsumi
I work at Zillow. I focus on tools and services for developer productivity, including build and testing.

My other interests include programming language design, game development, and learning languages (the non-programming ones).