Replacing Developers with Perl Scripts
It’s important that as a new developer you do not succumb to a mind numbing repetitive task.
One, you’ll look like an idiot when someone else does the same thing with a script or a tool but in 1/100th the time.
Two, you could have tons of time to slack off if you’d only used the tools at hand!
Things that are very handy that you should know:
Regular Expressions – Find and replace complex patterns of text. Many IDE’s, such as Visual Studio have an implementation you can use.
A scripting language, such as Perl – Take some kind of input, process it (using regular expressions), spit something out.
Excel – Generate number sequences from formulas and sorting data.
These things have saved me countless hours. I had to generate a templated class with a bunch of repeated typenames from T1 through T120. I wrote a quick Perl script to do my bidding for me:
$i = 120
printf( " template< " );
for( $j = 1; $j <= $i; $j++ )
{
printf( "typename T%d", $j);
if( $j != $i )
{
printf( ", " );
}
}
printf( ">\n");
What’s great about regular expressions and scripts is that if it turns out you have to change the formatting or the number of values you want to write out, it’s a simple change.
Plus it’s fun to write throw away code that only has to work once.
An Intern Story
When I worked as an intern for a nameless blue company, another intern was given the [fun] task of porting a database to a newer version. The work came down to taking this huge definition text file and making it work with the new system.
The changes were mainly comments now used slashes instead of apostrophes and some keyword differences.
For two days he chugged along hitting backspace and / repeatedly.
When I had finished my project, I was asked to help him. I copied the entire file into Word, did a couple of find/replaces and was done.
“Chris, the savior of the database!” they cheered [in my head].
Of course, now neither of us had anything to do for the rest of the week.
A Microsoft Story
We have some code which gets auto-generated based on some input data files. If you add new data, but don’t update certain helper headers, you’ll get a list of linker errors like the following:
Unresolved external GenClass1::s_id in gen.obj
Unresolved external GenClass24::s_id in gen.obj
Unresolved external TempClass1::s_id in gen.obj
Unresolved external GenClass8::s_id in gen.obj
Unresolved external GenStruct4::s_id in gen.obj
... (600 more lines)
So we have a handy dandy macro which will define the IDs for these classes:
DEFINE_ID( GenClass );
I could have spent all day copying and pasting the class names in. Or I could load the error output into Visual Studio and use its great find and replace tool which allows for regular expressions:
Find .*external and replace with DEFINED\_ID\(
Find \:\:s_id.* and replace with \)\;
The result:
DEFINE_ID( GenClass1 );
DEFINE_ID( GenClass24 );
DEFINE_ID( TempClass1 );
DEFINE_ID( GenClass8 );
DEFINE_ID( GenStruct4 );
... (600 more lines of code
I didn't have to write)
Tada! [........It’s the final countdown…]