Python considered harmful?

October 17th, 2008

Yesterday morning I started writing a simple tool which should compile all C++ files in a given directory tree. Ok, simple enough, it’s just a matter of a simple os.walk and some subprocess.call.

After that, I thought that it would be nice if the tool did something more. For example, I could write down a function that was able to “make clean” the executables I built. This is simple as well. You just have to be smart since on *nix executables do not have extensions. And I could make the system Windows friendly. It was a matter of a couple of functions more.

However, at that point I needed some kind of interface. A simple command line tool was nice. But… well, I remembered using a Prolog tool which did some heuristic to get wrong commands right (zsh does this as well)… so, why not? A levenshtein distance + some more checks could do. And it did. Nice.

But… what if I just want to compile one single file? Well, I had already most of the infrastructure. And why not letting me specify a single file to clean? As easy as breathing. Done. By the way, the system at that point supported building and cleaning object files as well.

And I was already wondering that I left out C files. After all I needed to process C++ files, but the tool would be surely more useful if I could use it with C files too. And why not Pascal? Ok, I have the right design which could support kind of configuration to map file types to compilers… and I could parametrize compiler options as well. Somewhere in my mind an automated compiler detection system was already lurking.

I refactored the tool. It became a package, with a lot of useful functions… But well… why rebuilding all the sources? I need only to rebuild executables which are older than their source file. This is easy, a couple of stat…

At that point I realized that if only I added some kind of file dependency discovery I would have basically reinvented make. That is to say I was reinventing a square wheel. One of these days I’ll get the very first script and modify so that instead of compiling files generates a CMakeLists.txt, calls cmake and then Make.

The end of the story is developing in Python is too fast. :P

BTW: the author is not suggesting Python should not be used, just the opposite!

Open Source and Free Software, Programming, Python | Comments | Trackback

9 Responses to “Python considered harmful?”

  1. 1JafraldoNo Gravatar
    October 17th, 2008 @ 18:14

    Thanks for that bit of clarification at the end there. A lot of us internetters can’t understand humor and would have missed the point of this blog post without that final sentence.

  2. 2asdfNo Gravatar
    October 17th, 2008 @ 23:03

    I think python sucks because of significant white-space. That’s why no one uses it.

  3. 3Enrico FranchiNo Gravatar
    October 18th, 2008 @ 03:31

    @Jafraldo: Well, the point was more that I should think more about reusing pieces of software rather than rewriting them, even though in this case language productivity was somewhat responsible of late understanding of my mistake. And I stress that it was my mistake.

    Moreover, the point of the post was not entirely clear. It was easy to read only a couple of paragraphs and jump to conclusions. More over I’ve got my reputation to defend, I only flame pro-python. :P

  4. 4Enrico FranchiNo Gravatar
    October 18th, 2008 @ 03:38

    @asdf: This is an example of hard to understand humor.

  5. 5ilyaNo Gravatar
    October 18th, 2008 @ 13:02

    As a matter of fact, creating a square wheel would be an improvement in this case ;-).

    Simply b/c make is more of a triangular wheel and square wheels roll way better.

    And, yes, in my experience a custom build scripts often beats handwritten makefiles both in terms of maintainability and code size.

    Btw, if you want a python based alternative to make: take a look at scons.

  6. 6Enrico FranchiNo Gravatar
    October 18th, 2008 @ 13:43

    Well, I see your point! I had a look at scons, but I chose to use cmake.
    Having Python to script the builds is great, though I found cmake syntax more readable and clean. This is, of course, just a matter of taste.

    About my square wheel, the point is that I could just generate CMakeLists.txt and let cmake && make do the job. Cmake is quite good at it! :P

    Of course, I could have used scons as well. What they missed (or maybe I just did not find it in the documentation) is build every file of a certain kind in a given subdirectory without specifying it anywhere. I have to teach C++ and I need to write a lot of short examples and I find it boring to add them to the build system. A prefer a build system which discovers the files and builds them automatically.

  7. 7StuNo Gravatar
    October 19th, 2008 @ 11:19

    Python syntax would be so much nicer than make files (or bowing to the pointy bracketed overlords of ant)… bring it on!

  8. 8Jeethu RaoNo Gravatar
    October 26th, 2008 @ 23:58

    And I thought I was the only one who’d tried to do this with Python. Automatic compiler detection, smart rebuilding with stat() calls, your whole post felt like a deja vu, except for the part where you used levenshtein distance to get wrong commands right (I just used optparse).

  9. 9Enrico FranchiNo Gravatar
    October 30th, 2008 @ 07:03

    I think this could be listed among the things “any python programmer does sooner or later” among with the creation of a home brewed web framework. :P

Leave a Reply

  1.  
  2.  
  3.  
  4. XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
You can keep track of new comments to this post with the comments feed.

Recent Posts

Blogroll

Siti amici

Misc

Recent Comments

Categories

Enrico Franchi graduated in Maths and Computer Science and is now studying for a Computet Science MSc (though because of italian bureaucracy that very course is to be cancelled).

RiK0's Tech Temple is using WP-Gravatar