MV3D Development Blog

October 6, 2007

That Code Be Stylin’!

Filed under: Uncategorized — SirGolan @ 1:36 pm

Soo.. Been a while, eh? Long time no see. Things have been pretty busy with work, but I’ve gotten a little bit of time to work on MV3D stuff. I’m not going to talk about that now. If you’re lucky (or unlucky if you find me boring), I’ll write more later today about MV3D.

Something that really irks me is ugly code. There’s a lot of MV3D code that I consider fugly. Most of the reason is the formatting (darn me and my C++ habits), so rather than go through 30kloc of manual reformatting, I decided that was a job for a program. I asked around a bit and it doesn’t seem like anyone’s written a Python code reformatter (or at least one that can format to Divmod coding style), so I’ve made Stylin.

Now you can have it, and may your code be stylin’ too!

Here you go. (Sorry for the zip file, but my webserver is configured to try and execute .py files)

What does it do?

Let’s start by saying what it doesn’t (yet) do:

  • Wrap lines at 79 chars
  • Properly add blank lines around import statements at the top of the
  • Properly add blank lines around random code that isn’t indented (and isn’t a class/function)
  • Move your indents to the top of the file (this is probably not a good idea anyway)
  • Make your algorithms cleaner
  • Occasionally it has an issue with mismatched quotes within a docstring
  • Unless you do something with mismatched quotes like above, it does not break your code.

    So with that in mind, what does it do?

  • Put spaces around operators (but not in keyword arguments on function defs)
  • Re-indent everything to use spaces and not tabs (can even handle mixes)
  • Add blank lines between classes, methods, etc
  • Reformat doc strings
  • Add doc strings where there are none (”You need a docstring here!” :) )

    Enjoy!

  • No Comments »

    No comments yet.

    RSS feed for comments on this post. TrackBack URL

    Leave a comment

    You must be logged in to post a comment.

    Powered by WordPress