Being greener

For most of my life, I’ve been a “small e” environmentalist. I’m not outspoken on my views, but I really hate to see needless waste. For me, that’s meant keeping cars for a long time rather than replacing them, spending a little more on stuff that will last so I don’t need to throw as much stuff away, and getting books at the library. Stuff like that.

I haven’t, however, put as much effort into applying the same principles to my profession, and over the past few months, I’ve been working to be more reasonable in that area as well.

I’ve come up with a few practices that I thought I’d pass along, as part of what I’m calling “Green Programming – Simple practices to make the world a better place…”

Practice #1:

Consider the following code:

    if (x > 5)

Now, if I need to change it so that 2 is added to the value of i rather than one, I would probably do the following:

First, I’d select the line with the increment:

    if (x > 5)

hit “delete”:

    if (x > 5)

and then type in the new line:

    if (x > 5)
        i = i + 2;

I’ve done that sort of thing millions of times in my career. But not any more. Here’s what I do now:

First, delete the characters that I no longer need. In this case, it’s just the second “+” sign:

    if (x > 5)

 then, insert ” = i “

    if (x > 5)
        i = i +;

 and finally, ” 2″:

    if (x > 5)
        i = i + 2;

In my first version, I deleted 12 characters (plus a carriage return and linefeed), and then added 20 new characters. With my new approach, I deleted 1 character and added 7 characters. That small change reduced my deletion percentage by 91.67%, and my new character percentage by a less impressive but still impactful 65.00%.

Practice #2:

The first practice made some great improvements, but I thought there was more to be had. I found that I could keep open a session of notepad, and rather than deleting the characters from my code, I would copy them to notepad, for possible reuse later. Unfortunately, since I write a lot of new code, I tended to exhaust this resource fairly quickly, and was forced to fall back on typing new characters.

Practice #3:

To give me a better source of recycled characters, I came up with a new approach. Not only do I copy characters to notepad before deleting them, when I need to delete a source file, I copy *all* of it’s contents to my notepad buffer before deleting the file.

I am proud to report that I now am justified in believing that I am “character neutral” in all of my coding. That made me quite happy, until I realized that I still had a problem.

It was my blogging. I tend to write a fair bit on my blogs (3-5 depending on how you count them), but because of my natural eloquence and low quality standards, I rarely delete stuff, and therefore keeping a buffer for my blog writing was problematic. I tried using my programming one – it certainly is sufficiently full that it won’t run out quickly – but I found that I tended to have some problems with expression (“I regret I have but one life to give foreach my country”), not to mention developing having to write lines like this:


to use up some of the excess punctuation.

So, that clearly wasn’t workable, but just yesterday I came up with a great idea. I’m now recycling all the contact spam that is *already generated* by my blog into my blog buffer, and I’m considering re-using the splog links I keep getting, which would be especially convenient as they already have the words that I like to use.

So, that’s my little contribution, because as I like to say, if you’re not part of the solution, you’re part of the problem. Or the precipitate.

Future Ideas:

I haven’t thought all of these through fully, but here’s a list of other ways you might “recycle and reuse”:

  • Don’t throw away that command window you’re using and create a new one. Reuse the existing one.

  • Keep old classes around to use as the starting point for new ones.

  • As some believe in “Peak Oil“, I fear that we’ve already reached “Peak Guid”, and that the days of $4 guids are in sight. I therefore recommend that you save all of the guids that you generate. Sure, it may be 15 years before the software that you used them in is gone and you’re free to reuse them, but if you’re the guy with 500 guids in your pocket during the Guid crisis of 2025, you’re going to be sitting pretty.

What practices can you add?

(composed of 100% post-consumer characters)

Comments (8)

  1. well, on a more serious note, you can actually be a lot greener with things like ViEmu Visual Assist and Resharper 🙂

    amazing how satisfying it is to edit efficiently!

  2. JL says:

    You forgot pressing the -> move cursor keys, which I assume is still faster than moving the mouse.


    would have worked faster too 🙂

  3. Miral says:

    Now just think of the savings if you had used "i += 2;" instead 🙂

  4. allen s says:

    better than copy to notepad

  5. Jeff Parker says:

    I tried the recycling characters thing before. It just didn’t work it. it was far less efficient, I would burn more brain cells making sure I didn’t introduce a typo. Once I did introduce a typo then a lot more resources were waisted debugging trying to find it. I think it has to do with how my brain is wired. as my brain is multicore. One core is thinking about the code I am writing and at the same time the other core is thinking about all the other code it will affect and how it will affect it and thinking about the next 20 lines at the same time.

    However the reuse of the command window I fully support you on, you failed to mention though the importance command that can make your command prompts good as new every time. that command would be CLS.

  6. So you saved all the characters typed, and then typed in this long blog entry =)

    Happy Belated Birthday!

  7. Timothy Fries says:

    >>when I need to delete a source file, I copy *all* of it’s contents to my notepad buffer before deleting the file

    Deleting a file?  How wasteful!  Best to store unneeded files in the Recycle Bin, that way if you find out you need to add any new files to your project, you can just pull one of the files out of there, clean out the contents of the file, then reuse your old file.

  8. L'ours qui code says:

    i think that to "copy *all* of ITS content" may result in expensive quotes.