Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Python internals: how callables work

[The Python version described in this article is 3.x, more specifically - the 3.3 alpha release of CPython.]The concept of a callable is fundamental in Python. When thinking about what can be "called", the immediately obvious answer is functions. Whether it’s user defined functions (written by you), or builtin functions (most probably implemented in C inside the CPython interpreter), functions were meant to be called, right?Well, there are also methods, but they’re not very interesting because they’re just special functions that are bound to objects. What else can be call...

1,906 0       PYTHON RATIONALE CALLABLE WORK


  In-memory key-value store in C, Go and Python

Subtitle: Wow Go’s net library is fastOn paternity leave for my second child, I found myself writing an in-memory hashmap (a poor-man’s memcached), in Go, Python and C. I was wondering how hard it would be to replace memcached, if we wanted to do something unusual with our key-value store. I also wanted to compare the languages, and, well, I get bored easily!The code is on github as Key-Value-Polyglot.Each version implements enough of the get and set commands from the memcached protocol that we can test them with a memcached client.If you write a version in a different language (...

4,419 0       KEY-VALUE MEMORY C PYTHON GO


  Currying in Python

What is Currying?Currying is like a kind of incremental binding of function arguments. Let’s define a simple function which takes 5 arguments:1def f(a, b, c, d, e):2    print(a, b, c, d, e)In a language where currying is supported, f is a function which takes one argument (a) and returns a function which takes 4 arguments. This means that f(5) is the following function:1def g(b, c, d, e):2    f(5, b, c, d, e)We could emulate this behavior the following way:1def f(a):2    def g(b, c, d, e):3      &n...

4,283 0       PYTHON CURRING BINDING IMPLEMENT


  Python internals: adding a new statement to Python

This article is an attempt to better understand how the front-end of Python works. Just reading documentation and source code may be a bit boring, so I’m taking a hands-on approach here: I’m going to add an until statement to Python.All the coding for this article was done against the cutting-edge Py3k branch in the Python Mercurial repository mirror.The until statementSome languages, like Ruby, have an until statement, which is the complement to while (until num == 0 is equivalent to while num != 0). In Ruby, I can write:num = 3until num == 0 do puts num num -= 1endAnd it will...

2,308 0       PYTHON NEW STATEMENT RESEARCH ADDITION


  Advice From An Old Programmer

You've finished this book and have decided to continue with programming.Maybe it will be a career for you, or maybe it will be a hobby. You'll needsome advice to make sure you continue on the right path, and get the mostenjoyment out of your newly chosen activity.I've been programming for a very long time. So long that it's incrediblyboring to me. At the time that I wrote this book, I knew about 20 programminglanguages and could learn new ones in about a day to a week depending on howweird they were. Eventually though this just became boring and couldn't holdmy interest anymore. This does...

4,052 0       PROGRAMMING PYTHON ADVICE OLD PROGRAMMER


  Overlap Detection

How does one detect when two strings overlap? In the case below, the four-letter suffix of string 1 matches the four-letter prefix of string 2.1: "Fire at Will"2: "William Riker is number one"Sometimes there are several matches; finding the longest is not always straight forward.1: "Have some CoCo and CoCo"2: "CoCo and CoCo is here."2: "CoCo and CoCo is here."2: "CoCo and CoCo is here."The naïve solution is to take ever smaller substrings of each string, compare them, then bail out when the first match is found. This is quick ...

7,040 0       PYTHON IMPLEMENTATION STRING OVERLAP DETECTION


  Programming Language Readability

Lets compare some Python to Haskell for solving the same problem.  The problem we’ll pick is Trie data-structure for auto-completions.  We are interested not so much in the nitty gritty of the algorithm, but in the language style itself.  Auto-complete has been in the programming news a lot recently; both a Python and a Haskell solver have turned up.(I suspect this post got flagged on Hacker News :(  It never got on the front-page despite the rapid upvoting on a no-news night)Here’s the Python:"""A fast data structure for searching strings with autocomplete su...

2,738 0       PROGRAMMING READABILITY PYTHON HASKELL


  Python Performance Tips, Part 1

To read the Zen of Python, type import this in your Python interpreter. A sharp reader new to Python will notice the word “interpreter”, and realize that Python is another scripting language. “It must be slow!”No question about it: Python program does not run as fast or efficiently as compiled languages. Even Python advocates will tell you performance is the area that Python is not good for. However, YouTube has proven Python is capable of serving 40 million videos per hour. All you have to do is writing efficient code and seek external (C/C++) implementation for speed ...

3,125 1       TIPS PERFORMANCE PYTHON EFFICIENCY