Date: | August 30, 2006 / year-entry #294 |
Tags: | other |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20060830-14/?p=29923 |
Comments: | 24 |
Summary: | My posting a while back on solving one problem by creating a bigger problem was written from the standpoint of an IT department doing something like tweaking a logon script. I even mentioned that context partway through but clearly didn't highlight it clearly enough. So say you're an IT department and somebody says, "Oh, just... |
My posting a while back on solving one problem by creating a bigger problem was written from the standpoint of an IT department doing something like tweaking a logon script. I even mentioned that context partway through but clearly didn't highlight it clearly enough. So say you're an IT department and somebody says, "Oh, just install this other program and learn a new programming language and convert your existing batch file to it, and then your problem will be easy to solve." You might not be too excited about that type of "solution". And even if you decide, "Okay, I can justify to my boss taking a week away from my other responsibilities to convert our existing logon script (and all the helper scripts that assumed that the root logon script was written in batch, say, because they shared environment variables with it) to this new language and debug the result," you still have the problem of getting that new script interpreter onto all your company's computers so that when people log on, your new fancy logon script can run at all. And since you're a corporation, you have a whole new set of problems. What are the licensing terms for that new script interpreter? (A home user may just click "Next" through the license agreement without reading it; a corporation doesn't have that luxury.) How are you going to deploy this new script interpreter to all your computers? (Will it require a reboot since the installer may want to do things like modify the global Maybe these questions are easy to answer, but you still have to ask them. Now, let's suppose you are, say, just a regular employee at a company rather than part of the IT department. Can you just take a program that you bought or downloaded and run it on a company computer? Odds are that if your company has an IT department, it also has a policy on running "unauthorized" software on company computers. (They probably don't care how legal it is, IT departments will almost certainly get very upset if you start running a peer-to-peer file sharing program on your corporate network.) For the home user, the activation energy is much lower. You just have to convince one person to learn this new language and translate their batch file into it. The batch files of home users are probably not hundreds of lines long, so the translation will probably be manageable. But you may have a harder time of selling your proposal if the batch file is 800 lines long. |
Comments (24)
Comments are closed. |
If you guys would just include perl like all the other operating systems, there wouldn’t be a problem!
This post is dear to my heart. It shows clearly the mentality of most of the computer scientists I know – especially those still in college.
1. Rip and Replace. The primary subject of this post, is almost always a bad idea. Yet every time I see one of my fellow CS’s approach a problem – especially problems they inherited – the first thing they want to do is rip everything out (regardless of whether it worked or not to begin with) and put in place what they think is cool (the open source crowd really favors this approach).
2. Let’s just start over! I love this one. I can’t count the number of times I have been in a group project where we reached some point of frustration and someone in the group pops up and says we should just ditch the 800 or so lines of code we have written so far (regardless of whether it worked or not) and start the ENTIRE PROJECT OVER AGAIN. What a horrible mistake!
3. That will only take 5 lines of code!! I will probably become physically hostile towards the next person who says this to me and means it. People who claim to be computer scientists are NOT being truthful when they claim that something can be done in 5 lines of code. "Hey, we need a logon form for our application." "No problem, we can do that in FIVE LINES OF CODE!!" Yeah, right. I have yet to see 5 lines of code that did anything useful.
I could go on here, but I think all of you see the point that Mr. Chen and myself are making. For those of you who still don’t get it:
Stop and think about the costs of your idea. Every idea – no matter how good it is – has a cost. That cost typically comes in the form of implementation, maintenance, or BOTH (usually both).
James
snap,
How do you know? Does everyone use perl? If yes, can you prove it?
James
Including Perl (or anything else) is nice, but has it’s own problems. What version of Perl? And If you say 5.8 is not enough, want sub-version?
Then the next request from somebody will be "oh, we have 5.8.6? I need Perl 5.8.8.812!"
And is it ActiveState or something else?
And what perl modules do you need? "Oh, my script uses this module, just take it from CPAN" :-)
You solve one problem, you add more :-)
Interesting, this is exactly what happened to me yesterday (Tuesday). When I presented our build support with a problem I wanted to solve, he asked me why I didn’t switch to this other build system, because then the problem would be much easier to fix…
If only our current build system had not taken several years to evolve into what it is now…
Xan,
Remember that I said over "some point of frustration." In other words, the person thought it would be easier to start over vs. finding ONE bug. Either way, if the original 800 lines has a few bugs in it, rewriting the whole thing may introduce more bugs or worse bugs. The ultimate point still stands – rewriting code that has already been made is not an assurance of fixing a problem or problems. Just ask Netscape. :)
James
“A home user may just click “Next” through the license agreement without reading it; a corporation doesn’t have that luxury.”
Interesting that you think that a home user *does* have that luxury.
"I have yet to see 5 lines of code that did anything useful"
Here are 6 lines of Perl-code which descrambles the DVD CSS encryption:
http://www.cs.cmu.edu/~dst/DeCSS/Gallery/qrpff.pl or something similar on a tie: http://www.cs.cmu.edu/~dst/DeCSS/Gallery/qrpff-tie-huge.gif. (NB! This is code for DVD CSS descramling, so it may not be a good idea for you to follow these links with regards to IPR, laws, etc. ;))
Anyway, my point is that it really depends on what useful means to you. One line of script commands can do everything which is necessary for your task. Why add unnecessary bells & whistles to it just to reach 100+ LOC? And it is an important question to ask yourself if you will use this code only once or multiple times…
More on-topic:
You write "computer" in the topic, but frequently the term "personal computer" is used. And many programs include personalization options as well. This *may* (I’ve not done any studies into this area!) indicate to people that the computer is their own, and therefore they should be in charge of it.
I feel more of a "personal relationship" (for the lack of better words!) to the laptop I’m using for my main work, compared to computers I use for testing etc. because I don’t have my personal desktop there and other stuff. So I then also more easily install/change "anything" on this laptop then other computers because it will be more persistant for me.
But then, isn’t this exactly why you have "group profiles" & authorization which let the IT department control if a user is allowed to "do anything" or not? :)
>> ditch the 800 or so lines of code we have written so far
800 lines of code, full of bugs (otherwise you wouldn’t feel frustration) is probably not like something to be kept around
I perfectly agree with you, if that number was 8000. 800 and bugged is very likely to be under the threshold, specially if you plan to extend that code in the future.
>> "A home user may just click "Next" through the license agreement without reading it; a corporation doesn’t have that luxury."
Paradoxically this is actually a good point towards open source software, because the lawyer department actually has only a few licenses to investigate/study. The patent problem still remains, but that is not a problem which the lawyer department could solve in any way (and I doubt there is any corporation in the world which is not violating at least one software patent right now).
>> Interesting that you think that a home user *does* have that luxury.
Beside the "standard" things (no warez copies, etc) most licenses have never be tried on court. Even if they were, chances are they were not tried in your particular country, and most licenses contain "rules" which may or may not be enforceable in some countries.
Also when you buy a software and click "Next" you actually are accepting a contract without a proof of your identity which may or may not be legal in your country (what if I see your PC unattended, install a software and then sue you for some license violation?).
Interesting is that noone in the world will ever accept a copy of Windows Server 2003 Enterprise back and refund you because "you read the license and you didn’t like it". However it could be argued that if you want every license word to count, at least you should give the customer the right to refuse to accept it.
So, you paid 69.99$ for ACDSee for your ahem pleasure. Then you read the license and discover that it explicitely prohibits you to use it to watch pr0n.
Do you think ACDSee will accept a refund because you really needed it for.. uh that kind of usage ? Do you really think that such a restriction could be easily enforceable in court ?
And, to answer your question, do you really think that ACDSee has nothing else to do that sue you, random user, because they think you might have used it that way ? They of course will not do it. Unless you are the company behind http://www.randomurlcontainingthewordsex.com
I know that is not your job but I wonder why is Power Shell not included by default in Vista. It will be ready by the ship date yes? Why not include it and save administrator the issues you just described of deploying it later.
> Do you think ACDSee will accept a refund because you really needed it for.. uh that
> kind of usage ?
They’re probably covering themselves in case somebody gets caught looking at something "truely" illegal with it.
> Here are 6 lines of Perl-code which descrambles the DVD CSS encryption
He means 5 lines of USEFUL code, not 5 lines from a obfuscated-code contest. If that code were actually written in a useful way (i.e. so that I could actually see what it was doing) then I’m sure it would be more than 6 lines.
Anybody can write a one-line program that does ANYTHING – just write it like normal, and strip out all the new-lines. Most (real :p) languages don’t use line-breaks as statement delimiters. But that’s not the point.
Anyway, I’ve found that in general developers get a little more "free reign" with their computers than non-developers. So while *you* might be able to install stuff on your computer, Joe Secretary or Jane Accountant probably can’t.
You can write useful 5 line scripts in non-obfuscated Perl.
You can write useful 5 line scripts in non-obfuscated Batch.
Speaking of perl, how come a perl script is included on the Windows XP install CDs? (check out CD:i386runw32.bat)
You can write useful 5 line scripts in non-obfuscated C.
A simple text file find&replace for example.
RC5,
Your example covers a little need that you have for whatever it is that you are doing.
I’m talking about situations where we are working on a full application that you are going to sell.
James
"You can write useful 5 line scripts in non-obfuscated Perl."
"You can write useful 5 line scripts in non-obfuscated Batch."
Some might argue that neither are true.
However some might even go so far as to say that…
"You can write scripts in non-obfuscated Perl."
"You can write scripts in non-obfuscated Batch."
…these are false as well :)
James: here’s 5 lines of code that implement a feature in my company’s content-managed web site framework:
// we only allow coreconfig to specify the page if a request has been
// set for it
if (!$coreconfig->override_switchboard_page)
$coreconfig->switchboard_page = $_SERVER["PHP_SELF"];
// similarly for the readable URL directory
if (!$coreconfig->override_readable_url_base) {
$sl = strrpos ($_SERVER["PHP_SELF"], "/");
$coreconfig->readable_url_base = substr ($_SERVER["PHP_SELF"], 0, $sl) . "/site";
}
Those two lines of code in the current version cut roughly three minutes from the operation of moving an installation from a staging server to a live one, compared with the previous version’s way of doing it, which required me to change a config file to update the location of the site. So I’d say its a useful feature.
(Obviously I’m not counting comments or lines with just braces as being lines of code.)
Nice title. It I could just persuade everyone who works here of that, life would be so much easier…
Ender: I very much suspect the answer is "by mistake", since it relies on pulling Perl from one of two hard-coded UNC paths (Kumar Pandit’s own machine, or a scratch server). There’s also a typo in it, and it appears to rely on winnt32.exe being in a subdirectory of its own (otherwise it has a documentation error as well).
I’d go along with the poster who said you couldn’t do anything useful in five lines of code. Sure there are trivial or perverse examples, but seriously, if you are counting lines you really need to count them all.
Comments: Oh yes – because I won’t deploy your amateur efforts on my system *unless* there are comments to explain what’s going on. (Especially in batch :-)
Lines that just have a block delimiter:
Yep – those too. Whitespace is code too. Heck – if you allow unreadable layouts, we’ll just write a gazillion line programme in C and put it all on one line.
Of course, there is an exception to the rule. If the useful thing you are doing is proving a point about your inner knowledge of a language, then I suppose that counts. Maybe it’s useful to have a credit from an obfuscated coding competition on your CV.
But for all other definitions of the word useful, show me the comments and the code layout too.
I agree that scrapping a system to get rid of a single minor, fixable bug is overkill. But generally, any reasonable app needs to be prototyped and scrapped at least once, possibly several times.
In-house apps tend not to have this luxury, as they usually grow organically from a short helper-script. So someone, at some point, needs to put their foot down and say "We must now migrate from this, for it has become more of a burden than a boon". This has recently happened with my own CMS, "MACE", which I have opted to migrate from, to Drupal/Civicspace. I have spent countless hours on MACE, have worked through illnesses to get it doing The Right Thing in time for a deadline. It is customised to the hilt. But because a lot of the design was done to deadline, I made shortcuts, placing tweaks inline, making the code less readable, and sometimes failed to plan ahead. I love it, but I am no longer proud of it, and development time of new features has risen to be impractical.
As for whether anything useful can be accomplished in five lines, it really depends on your definition of "useful" and your definition of "line".
One-liners (which I define as "commands that I am willing to type at the commandline without hitting enter, on systems where I have not bothered making them into an alias") are a thing I love, and collect. Some I expand into useful scripts, macros or aliases. Here are a few from my aliases list.
Here are some:
Bash: "Do STUFF, LIMIT times"
i=1;while [ $i -lt LIMIT ];do STUFF;i=
expr $i + 1
;doneBash: "Sort file or piped input by line-length"
cat file|perl -Xpe’$=length/" $"’|sort -nu|perl -pe’s/^d+ //’
Bash: "Dump all USER’s tables to one file"
mysqldump –add-drp-table -eBv
echo "show databases like 'USER_%'"|mysql -N
|fileBash: "Compare FILE1 and FILE2, side-by-side"
diff -dbByW $COLUMNS FILE1 FILE2
AutoHotKey is another very good macro language for short scripts.
This one fixes one of my common typos, in any window in which it is typed as a separate word:
::becasue::because
This one allows me to type an umlaut over an a, even in the middle of a word.
:*?:a+"::ä
This one (3 lines, not one, tut tut!) gets the mouse wheel working in JBuilder:
#IfWinActive JBuilder
wheeldown::Send ^{down}^{down}^{down}^{down}
wheelup::Send ^{up}^{up}^{up}^{up}
Another "short but not one line" one, closes the annoying Skype window which insists on grabbing focus whenever someone calls:
Loop {
WinWaitActive Skype,, Options,
WinClose
Sleep 30
}
Another, prevents my wireless headphones from blasting me with static after ten minutes of inactivity, by playing a sound periodically:
Loop {
SoundPlay %SystemRoot%MediaUtopia Critical Stop.WAV
Sleep 200000
}
Are these "useful" to everyone? No. But I’d certainly claim that they are useful to me, and I’m really the only one for whom I type in one-liners.