Mostly Random Technology Bytes

January 1, 2008

25 years of TCP/IP

Filed under: Internet, Miscellaneous Technology — Answers 2000 @ 1:50 pm

Today is the 25th anniversary of TCP/IP, which a standard abstract model for network and computer communications. TCP/IP was originally developed by DARPA (Defense Advanced Research Projects Agency - which is an agency of the United StatesDepartment of Defense) and has proved highly influential on the structure of the Internet. For more detailed information, there is, as you might expect, a wikipedia article on TCP/IP.

That’s all very interesting to us geeks, but does anybody outside of geekdom care? Well they do now: Google’s home page displays a customized version of the company logo to celebrate the event. Mouse over the logo displays “Happy New Year & 25 years of TCP/IP”, and if you click it, Google does a search for January 1 tcp/ip.

AddThis Social Bookmark Button

November 27, 2007

Bad Copy and Paste, Good Copy and Paste

Filed under: Programming — Answers 2000 @ 7:38 pm

Note: This post is based on a discussion that I participated in at the Joel on Software message board. I’ve reused (but cleaned up) my own posts, but I’ve rewritten the original question - as that bit doesn’t belong to me.

Question: Is copy-and-pasting chunks of code into our app, a good example of code reuse? My boss thinks that it’s a good idea, as we are making extensive reuse of code that we already wrote earlier in the development cycle rather than writing new code from scratch. Code reuse is supposed to be a good thing, right? (I’m not sure why, but I feel uncomfortable about duplicating so much code).

Bad Copy and Paste

The questioner (or perhaps more so, his boss) has a basic misunderstanding. The boss is assuming that Code Reuse is a goal in itself.

He’s wrong. It isn’t.

A key fundamental goal in software development, since we all want to do things in a way that avoids unnecessary time and expense, is to reduce duplication of effort.

Code Reuse is simply one method of working towards that fundamental goal. By putting code into subroutines or functions or classes or libraries, you (a) only have to write the code once initially, and (b) only have to go to one place in the code to maintain that algorithm.

If you copy and paste code, adding near-duplicate chunks of code in scattered places throughout your application, what happens? You’ve reduced the initial effort - as you only have to write the initial code once - but you’ve vastly increased the maintenance effort. Now if you want to make a change to that algorithm, you need to make the same change in all 57 (or whatever number!) of places it occurs in your code, you also have to try to remember to update all those 57 places (which is a struggle in itself), and finally you have to deal with extra bugs that arise because you forgot to update some of those 57 different places.

Maintenance and bug-fixing is by far the largest section of work in most projects, and copy-and-paste tends to vastly increase the duplication of effort, the exact opposite of the fundamental goal, which is to reduce duplication of effort.

Good Copy and Paste

There are cases however when copying-and-pasting code, duplicating it, can be a good thing. The reason is that reducing duplication of effort isn’t always the most important fundamental goal. Sometimes a more important fundamental goal is to reduce coupling.

Used intelligently copy-and-paste can reduce coupling. If you are fighting a tough schedule, a bit of copy-and-paste between projects can eliminate a bottleneck where two or more groups of developers are all awaiting a single change in a shared module. If there were only one bottleneck of this type, then the bottleneck probably wouldn’t have too much impact on your schedule, but if there are dozens or hundreds of these bottlenecks, then copy-and-paste, even if it involves duplicating code, can be a reasonable solution. In fact in this case, unless you copy-and-paste, your schedule may no longer be under your group’s control and become entirely unpredictable. In essence, the argument in favor of copy-and-paste is the same argument about removing dependencies that Joel used in his article, In Defense of Not-Invented-Here Syndrome.

One More Case

If life was simple (or maybe if I was a better self-editor?), I’d conclude after looking at the bad case and the good case, and then ask the reader to evaluate each situation from this point of view.

But there’s a third case…

Another argument that is sometimes made in favor of copy-and-pasting near-duplicate of sections of code, is that it reduces coupling by reducing the ripple effect of changing a shared function.

Here’s the example, let’s say there’s function X. It’s placed in a shared library (maximum code reuse!), and called by various modules in several different applications. A programmer then comes along and changes X (fixes a bug, adds a feature, changes the function’s side-effects, etc.,) so it now does something slightly different - which doesn’t affect where he is calling from - but does cause an unintended effect on the other places where X is called from.

Duplicating the innards of X as inline code at each point in the calling code, rather than calling a common function, would have avoided this problem, right?

Technically, provided you only focus in on the narrow details of this one function, this is argument is correct. However in this case, I have to think the cure is worse than the disease. Taken to the extreme, this in fact would be an argument in favor of never using functions - it takes us back to the Bad Copy and Paste situation that we’ve already discussed.

As far as I’m concerned the real problem is NOT that there is a shared function X, but rather that, what X is supposed to do, was never sufficiently well-defined. If what X does had been properly specified, including a clean API (including no weird or undocumented side effects), and programmers were aware that changing X from its specified behavior would have knock-on consequences, then the problem wouldn’t have arisen in the first place.

None of this is Rocket Science

Like the subheading says, this isn’t rocket science. What is needed is thought: thought about the goals and priorities when writing code, and thought about how to achieve them.

One thing I’ll say for sure though, based on my anecdotal experience: 99 times out of 100, copying-and-pasting of chunks of code is done without any deep thought at all - and in those cases, it’s nearly always pathological.

AddThis Social Bookmark Button

April 13, 2007

Computers - We ain’t quite there yet

Filed under: Software — Answers 2000 @ 2:05 pm

There’s an interesting thread on JoelOnSoftware.com about the kind of knots that computers allow newbies to get themselves into. Of course, as in the thread, an obvious response is RTFM, but is that fair?

I know how to use a PC, but in other aspects of my life, I increasingly find that life is too darn short to read the manual. Fortunately however, even quite complex devices with a ton of functions can now be used adequately without reading or learning. I’ve been able to use my PlayStation, TV, microwave, electric oven and new mobile phone without ever reading the manual, or learning how to use them. Admittedly, I don’t necessarily know how to use every last function - for example - my oven has a feature where you can set it to come on at a certain time of day, and go to a certain mode, and run for a certain time - and while I can’t think of a use of a for that function, if I did and I wanted to use, I think that I would probably have to follow the instruction manual to use this function. Likewise I have sometimes browsed the instructions for PlayStation games, mostly for hints of how to play better - but I know it’s unnecessary - my 6 year old nephew can operate my PlayStation and its games, better than I can, without ever having read any instructions - he does it by a combination of 6-year-old commonsense plus trial and error.

The thing is computers, at least as far as the user interface is concerned, simply don’t have anything like the ease-of-use of other consumer devices yet. Read the first post in the JoelOnSoftware thread. Things like short-cuts, directory structures and needing to know which application does what are abstraction-leaks, where you need to know stuff about the internal operation of the computer which isn’t strictly relevant to getting a particular task done - such as simply wanting to prepare a document and keep it safe. By contrast, when using a mobile phone - I don’t need to know anything about how it stores my address book, or how it connects to the phone system.

With computers, because those abstractions leaks are so gigantic, the tendency is to slap a bandaid over them by using some pretty graphics, explanatory text, icons and what not. But really, when you think about it, an ordinary user shouldn’t be required to know things like the difference between a short-cut and an actual file, simply to avoid losing their work. Maybe in a decade or two, we’ll figure out how to make more usable PCs?

When these types of discussions come up, I often think of an episode of Star Trek NG, called "Hollow Pursuits". In this episode, Lieutenant Reginald Barclay’s character has an alternate life on the holodeck where he lives in a fake Starship Enterprise and is cool, commanding and respected, rather than the nervous dork that he is on the "real" Enterprise. The story is basically that of him learning to abandon his fantasy life and concentrate on real- life. At the end of the episode, Barclay tells the computer to delete all his holodeck-programs, and then after a long pause, says "Except program nine" (or something like that).

First please note that in no point during the episode did Barclay need to know the difference between a short-cut to a saved file, and the actual saved file - and nor did he need to know whether he authored his holodeck programs using PowerDeck 2457 or HoloPerfect version 900. But that isn’t what surprised me… What surprised me? Well, it’s just at the end, I always half expect the computer to say “Too late sucker, program nine has already been deleted”. I guess that I have become too used to computers being unfriendly!

AddThis Social Bookmark Button
Next Page »
 

Powered by WebRing.