Tommy’s Blog

Discovering and learning

March Eastside Weblog Meetup

8th March 2006

Almost everyone else has posted a note about the meetup last night (Anita, Jack, Dennis, and Ram – but not Alex), so I’m a bit behind. We somehow manage to spend little of our time talking about blogging at these meetups but we still enjoy ourselves immensely. I’m disappointed that Anita (and Jack, I presume, though I didn’t get a chance to ask him) hasn’t been following Battlestar Galactica this season. The other folks I usually talk to about the show are still catching up from the first half of the season. I would love to know what they think about the Baltar-Six developments in the past few episodes.

Dennis — a.k.a. Orcmid — dropped by and left a comment this morning. He asked whether I had tried compiled JavaScript in .NET or not.

In the case of my strong typing epiphany, I wasn’t writing a script from scratch. Instead, I was modifying an existing script. Basically, I was changing it from doing a set of things once to doing that set of things multiple times, but with slight variations in the options. There was a bit of new logic in the program, but it was mostly refactoring. And it was the refactoring that got tough without strong typing as I converted repeating blocks of inline code into functions and corrected assumptions the original author had made (but that no longer were true). I had to change the scope of variables, create parameters, and document each new function. There were a lot of opportunities for typos.

One of the cardinal rules of modern programming is never to copy and paste. If you have two or more blocks of code that are identical, or even nearly identical, a subroutine should be made and then that subroutine called in place of the inline blocks of code. The reasoning is this: if the logic is duplicated in the code, if that logic is ever changed, it may not get picked up in all the places.

For example, pretend this pseudocode is a meaningful program:

if something equals "a" then
    doFunctionOne(using "a")
    doFunctionTwo(using "a")
    doFunctionThree(using "a")
if something equals "b" then
    doFunctionOne(using "b")
    doFunctionTwo(using "b")
    doFunctionThree(using "b")

There’s an example of copy-and-pasted code. It could easily be turned into a subroutine:

subroutine doFunctions(parameter)
    doFunctionOne(parameter)
    doFunctionTwo(parameter)
    doFunctionThree(parameter)

And then the main part of the program would look like:

if something equals "a" then
    doFunctions("a")
if something equals "b" then
    doFunctions("b")

Or even simpler, in this trivial example:

doFunctions("a")
doFunctions("b")

Imagine this kind of change, but across several hundred lines of script code.

Getting back to Dennis’s question: I have done some things with JScript.NET, but it wouldn’t have helped here because I was modifying existing code rather than starting from scratch and I needed to work within the already-established parameters.

If I have to touch this bit of code again, for anything more than the most-trivial change, I’ll most likely invest the time to convert it to managed code. It will save me — or whoever comes along after me to maintain it — more time than I’ll spend doing the conversion.

Now, another question that the devil’s advocate in me has been asking: when is copy-and-paste better than factoring code into subroutines? Let’s forget about one-off, throw-away code. For stuff that’s meant to last and be maintained, are there any situations where copy-and-paste is preferable? Perhaps I will address that in the future or, even better, maybe some of you will provide answers in the comments.

Update: I’ve got to do something to remind myself to insert the tags on the posts before posting. I need to figure out how to hook Blogjet to remind me.

Tags: , ,
del.icio.us tags: , ,

4 Responses to “March Eastside Weblog Meetup”

  1. Billie Says:

    hooks on the tags?
    Heck, I’m just trying to figure out how to do tags. LOL Don’t know what you are taking about half the time but I’m facinated.

  2. Tommy Williams Says:

    By “hook” I mean that I would like to insert my own little bit of code into Blogjet so that, if I have forgotten to insert my tags, it won’t post the entry to the server. It has nothing to do with tags themselves.

    The World of Warcraft Wiki defines a hook as: “Hooking a function is the procedure of modifying a function after it has been defined to carry out another set of instructions every time the original function is called.”

    So I would like to modify the post function in Blogjet to check whether I’ve added tags. If not, halt posting and notify me.

  3. Alex Barnett blog : eBay invest in Meetup.com Says:

    [...] eBay invest in Meetup.com I checked my mail just now and got a message from the CEO of Meetup.com, Sott Heiferman, explaining that his company has just closed an investment round with eBay. He doesn’t say how much, and stresses that they’ve not been acquired. Here’s the relevant part of the mail. “Meetups are going so well that, alongside our existing investors, eBay just invested in Meetup.com! I love eBay. They use the internet to empower and connect people and make the world a better place. That’s exactly what Meetup is all about! They did NOT “buy the company”, they simply invested money that we’ll use to run and grow Meetup.com. Our hope is this will make everyone’s Meetups better. This news is something for us all to be proud of!” It wasn’t a personal mail of course, but my congratulations to Meetup.com anyway. Why do I care? I use them whenever I RSVP for the Seattle Webloggers Meetup. I went to another the other night. Good fun again - met up with Anita, Jack, Tommy and was introduced to Dennis and Ram. [...]

  4. Billie Says:

    Tommy, I got the idea of what a hook and a tag are….just haven’t figured out how to do them. LOL Gotta work on this. At this point, I don’t really care about a hook but I’ve been trying to find a easy way to do tags in Blogger.

Leave a Reply

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>