[Python-ideas] Proposal for function expressions

David Stanek dstanek at dstanek.com
Mon Jul 13 17:19:35 CEST 2009


On Mon, Jul 13, 2009 at 6:51 AM, Chris Perkins<chrisperkins99 at gmail.com> wrote:
>
>  var callback = function(result) {
>    // 10 lines of code...
>  };
>  make_ajax_call(url, callback);
>
> vs.
>
>  make_ajax_call(url, function(){
>    // 10 lines of code...
>  });
>

This is common in Javascript, but still makes me cry. I would rather
see something like this:

  function main() {
      make_ajax_call(url, ajax_call);
  }

  function ajax_call() {
    // 10 lines of code
  }

This way ajax_call can be in a different file and can be used in other
code without duplication.

> I have come to hate the former style, and find myself frequently
> refactoring it into the latter, because the main thrust of what this
> code does is summed up by "make_ajax_call(url, ..)", so that is what I
> want to see first - not way down at the end, like an afterthought.

I think you are refactoring in reverse.

-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek



More information about the Python-ideas mailing list