Ahammell wrote at Wed, 12 Jun 2002 05:32:19 +0200: > Janek Schleicher wrote: >> It's a real crime to copy source code.
I missed to say :-). Sorry. >> Here you see why. >> >> Cheerio, >> Janek >> >> > Janek, > Im sorry but I dont quite understand your statements. I sincerely hope > that you are not accusing me of copying source code. I truly dont know why you would >think that > and if you dont I apologize for this part of my response. I simply posted with a >question about my > source code that I thought someone could help with. > I didn't mean that it is a crime to copy source code from another program. I mean't it is very dangerous to program with a copy+paste style. Why? First of all, if you have to make a change later, then you should only have to change the code at ONE position. There's also a great danger that little errors are done by copying+paste. The source code posted here, showed some of the little errors: > > if ($href->{st_name1} eq "$state") { > > #print "$href->{quad_name}, $href->{st_name1}\n" ; > > $state_hash{"$href->{quad_name}"} = "$href->{st_name1}" ; > ^ > > } > > } > > elsif ($href->{st_name2} eq "$state") { > > #print "$href->{quad_name}, $href->{st_name1}\n" ; > > $state_hash{"$href->{quad_name}"} = "$href->{st_name1}" ; ^ As you can see, both if-constructs are nearly the same. In fact there's only one character different (st_name1 <=> st_name2). The constructs make only sense when in the assignment the 1 is replaced by 2. Such little mistakes are typical for copying+paste - programming. It seems, that the author wanted to say: set the state of the hyperlink reference to quad_name to the reference of st_nameX, where the reference to st_nameX is the $state. Instead of that, the code says something like: set the state ... of quadname ... to st_name1 if reference of st_name1 eq $state set the state ... of quadname ... to st_name2 if reference of st_name2 eq $state set the state ... of quadname ... to st_name3 if reference of st_name3 eq $state set the state ... of quadname ... to st_name4 if reference of st_name4 eq $state As you can see, the real idea is hidden. That's an alert signal. Well, you could say, I have to be more carefully when copying. I should write a short comment to explain the idea. But that's not the way. You'll become a better programmer avoiding doubled code. (Or just take BASIC - use goto; peek; poke; and randomness line numbering) Doubled code have a similar functionality - that's why write a loop, subroutine, module, class, macro or use Perl's powerful eval. Of course it needs a little time - but you get it back later (with factor 3). As in the example above - you also could write a pseudocode like: foreach X (1 .. 4) set the state of the hyperlink reference to quad_name to the reference of st_nameX, if the reference to st_nameX is the $state. what should be possible to implement. I know it's hard, always to remember that I shouldn't copy code. In addition it's hard, when you're a programming newbie. So I always say - and that's simple to remember - that it is a real crime to copy code. Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]