Tuesday, 3. June 2008, 17:17:03

How many of You work in a big corporation, dashing out code in a programming language which You don't like? Wouldn't it be great to code a little bit of python or [insert Your favorite programming language here] from time to time?
If You really happen to work in a big company then You already know that this isn't as simple as it sounds. You probably have coding standards and company approved technologies. How can You possibly sneak some code in, avoiding all off those obstacles? Most importantly how to get Your manager to assign time for coding in languages that *You* not the company wants?
First of all, don't charge the revision control with every snippet of code that You happen to have at hand. Try looking around first. Is there a place where Your favorite language could help in the development of Your companies flag product? Every language has it's benefits and is better then the rest at specific tasks.
In my case it all started with a simple script to do some search&replace and file splitting operations on the current code base. Note that this wasn't a task that I made up for myself. I had to ask around and talk to different people to know that this was planned. The need was there, and 150 lines (without comments and blank lines) of Python satisfied it.
The first script You write in the language You were able to choose is really important. You can't mess up at this point. Make the code readable! Even if fitting it all in 70 lines of code less is tempting. Document it. Even if skipping the docs would cut the implementation time in two. Write some simple unit tests for the code if Your company happens to use unit tests in their own products, or do them if You have some spare time. Create a simple usage instruction so people will be able to use the script without consulting every step with You.
Now, You probably think that this is overkill for a throwaway script, but keep in mind that the company paid You money for the time You spent working on it. They certainly don't want to throw it away. And no, making it bigger this way isn't cheating. Remember that someday You or someone else may have to extend the scripts capabilities, the docs and unit tests will come in handy then.
The first script payed off in my case. I was given a second task. Another script to traverse the current source, analyze it and generate some SQL for the database. This again took around 100 lines of Python.
It all went down hill from there. I was asked to code a script that would search hard coded messages in the current code base, judge if the text is intended for a human operator and if so include it in the results. I decided to store the results as XML and present it in the users browser using XSLT. The total for this script was 300 lines of Python.
At this point I started to built a toolkit that I could reuse in future projects. I looked back at the code I wrote before and extracted the parts that seemed to appear more often. I also started to write some classes on my free time, based on the observations I made so far.
I looked at our code base and found a way to automate some tasks by writing scripts that would be hooked into our source code management system. I wrote a document describing the project. Included the estimated time that I would need to implement it and most of all wrote a working prototype on my free time. My project got accepted and is now in queue for implementation.
The reason that it is in queue now is that I got two other Python programming tasks. One to implement a parser for our code base that understands it's structure and can do further analysis of the code, gathering data and presenting it to a human for refactoring purposes. Implementing this script took ~3000 lines of Python (including a GUI in Tk), 18 pages of user documentation, 2 XSLT files for nice output of the results and over 60 unit tests (I realize that it's a small number of tests). A nice side effect was having technical documentation generated by
Epydoc. The second task was a simple search script that took ~100 lines of Python and reused an old XSLT file.
I didn't even start writing the project that I suggested and a new one is on the horizon. There is one script used almost daily by every programmer in the company. The script wasn't written by me but it's in Python. I was asked to extend it's functionality which I gladly accepted, as the code is written in a clean, logical and readable way.
To summarize all of the tips I wanted to share:
- Start small, by writing scripts that ease daily tasks
- Keep Your code base clean and readable.
- Document Your code
- Use Your favorite language where it works best. Don't use a hammer when a screwdriver is better.
In the beginning You will be the one asking to code some stuff in [insert Your favorite language]. When someone notices that the time invested on Your ideas paid off, then They will ask You to implement their own ideas. The chances are that They will be less strict about the language choice They allow You to make.
I managed to sneak in ~3650 lines of Python code. How many lines did You? And in what programming language?