Lazy Programmers
Jul. 17th, 2005 04:47 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I was explaining this to Megan on our Hike yesterday.
Larry Wall says that one the three principal virtues of a programmer is laziness [1]. That isn't to say that it is a virtue to lie in the pool with a beer all aftenoon [2], rather it means that it is a virtue to work smarter rather than harder.
For example, imagine you are writing a set of tools A, B, C and D. All do different but related tasks. When they start they need to emit a copyright message thus:
Copyright © 2005 ABC Corp. All rights reserved.
On each release, the year has to be updated. The hard working way to do this, would be to have a statement at the beginning of each program which prints the message out:
where as the lazy method would be to write a helper function that each of those programs call when they start out:
and to then call that function when each of the tools starts:
Now, you still have to update the call every time you make a new release and the year has to be updated, but suppose ABC Corp gets bought out by ACME. Now all you have to do is update the helper function, and ta-da! All the tools now reference ACME instead of ABC Corp.
The people I work with are mostly engineers. They are generally do not have programming backgrounds as I do. Larry Wall also says There Is More Than One Way To Do It, which is true, but some ways are more equal than others. They are all very smart people and they know their stuff quite well (mostly electrical engineering). Unfortunately, they are also the hardest working programmers I have ever come across in my life, and this is a pity, seeing as how that is what they are employed to do.
[1] The others are impatience and hubris.
[2] Nor is to not say that either, it's just that this is not what laziness means in this context.
Larry Wall says that one the three principal virtues of a programmer is laziness [1]. That isn't to say that it is a virtue to lie in the pool with a beer all aftenoon [2], rather it means that it is a virtue to work smarter rather than harder.
For example, imagine you are writing a set of tools A, B, C and D. All do different but related tasks. When they start they need to emit a copyright message thus:
Copyright © 2005 ABC Corp. All rights reserved.
On each release, the year has to be updated. The hard working way to do this, would be to have a statement at the beginning of each program which prints the message out:
int main(int argc, char *argv[]) { printf("Copyright © 2005 ABC Corp. All rights reserved.\n"); ...
where as the lazy method would be to write a helper function that each of those programs call when they start out:
void write_copyright_message(int year) { printf("Copyright © %d ABC Corp. All rights reserved.\n", year); }
and to then call that function when each of the tools starts:
int main(int argc, char *argv[]) { write_copyright_message(2005);
Now, you still have to update the call every time you make a new release and the year has to be updated, but suppose ABC Corp gets bought out by ACME. Now all you have to do is update the helper function, and ta-da! All the tools now reference ACME instead of ABC Corp.
void write_copyright_message(int year) { printf("Copyright © %d ACME. All rights reserved.\n", year); }
The people I work with are mostly engineers. They are generally do not have programming backgrounds as I do. Larry Wall also says There Is More Than One Way To Do It, which is true, but some ways are more equal than others. They are all very smart people and they know their stuff quite well (mostly electrical engineering). Unfortunately, they are also the hardest working programmers I have ever come across in my life, and this is a pity, seeing as how that is what they are employed to do.
[1] The others are impatience and hubris.
[2] Nor is to not say that either, it's just that this is not what laziness means in this context.