Pigheadedness (was Re: Newbie; Perl/Tk Event models) 
Author Message
 Pigheadedness (was Re: Newbie; Perl/Tk Event models)



Quote:

> : my $update = sub {

> : ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
> : $day=(Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)[$wday];
> : $month=(January,February,March,April,May,June,July,August,September,
> :  October,November,December)[$mon];

Barewords galore!

Quote:
> : $century = $year - 99 ? 20 : 19;
> : $string = sprintf <<"eop", $year, $hour, $min, $sec;
> : It is $day, $month $mday, $century%02d %02d:%02d:%02d
> : eop

> : };

> It is obvious that the person who wrote this code read the documentation
> for localtime(), as he's obviously learned that the year field will
> contain a value greater than 99 in the next century.  But why didn't he
> make the obvious connection and simply add 1900 to the year rather than
> trying to simulate a fortran arithmetic IF statement?  I can only guess
> that he had a presupposition that century-handling *had* to be more
> complex than it really is, and dutifully wrote needlessly complicated code.

Needlessly complicated and remarkably wrong!  The years that code would
report are 2097 2098 1999 20100 20101 .

That godforsaken code *could* be:

    $century = $year > 99 ? 20 : 19;
    $string = sprintf <<"eop", $year % 100, $hour, $min, $sec;
    It is $day, $month $mday, $century%02d %02d:%02d:%02d
    eop

And we all know what it *should* be.

--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.*-*-*.com/



Fri, 09 Nov 2001 03:00:00 GMT  
 Pigheadedness (was Re: Newbie; Perl/Tk Event models)
: my $update = sub {

: ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
: $day=(Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)[$wday];
: $month=(January,February,March,April,May,June,July,August,September,
:       October,November,December)[$mon];

: $century = $year - 99 ? 20 : 19;
: $string = sprintf <<"eop", $year, $hour, $min, $sec;
: It is $day, $month $mday, $century%02d %02d:%02d:%02d
: eop

: };

It is obvious that the person who wrote this code read the documentation
for localtime(), as he's obviously learned that the year field will
contain a value greater than 99 in the next century.  But why didn't he
make the obvious connection and simply add 1900 to the year rather than
trying to simulate a Fortran arithmetic IF statement?  I can only guess
that he had a presupposition that century-handling *had* to be more
complex than it really is, and dutifully wrote needlessly complicated code.



Sat, 10 Nov 2001 03:00:00 GMT  
 Pigheadedness (was Re: Newbie; Perl/Tk Event models)

Quote:

> That godforsaken code *could* be:

>     $century = $year > 99 ? 20 : 19;
>     $string = sprintf <<"eop", $year % 100, $hour, $min, $sec;
>     It is $day, $month $mday, $century%02d %02d:%02d:%02d
>     eop

> And we all know what it *should* be.

Definitely starting to fall into the

"How hard can we possibly make things?"

Category...
-Sneex-  :]
______________________________________________________________________
Bill Jones  Data Security Specialist  http://www.fccj.org/cgi/mail?dss
______________________________________________________________________
  We are the CLPM... Lower your standards and surrender your code...
  We will add your biological and technological distinctiveness to
  our own... Your thoughts will adapt to service us...
  ...Resistance is futile...

         Jacksonville Perl Mongers
         http://jacksonville.pm.org



Sat, 10 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Newbie; Perl/Tk Event models

2. POE 0.11: event driven state machines, also supports Perl/Tk and Event

3. Can't load 'C:/perl/site/lib/auto/Tk/Event/Event.dll' for module Tk::Event:

4. how to stop further event processing in perl/tk

5. Remote DND events in Linux with Perl/Tk

6. Nonmember submission: Re: file event in perl-Tk on cygwin (using POE)

7. Close event for perl/tk?

8. Perl Tk event

9. how to stop perl/tk prog until event ?

10. perl/tk does not handle button events properly

11. newbie-perl or why am i blind to this simple

12. I am a Perl Newbie.....need some help please

 

 
Powered by phpBB® Forum Software