I had an intern once who wrote similar code. They confused 12 hour and 24 hour clocks, so the code would break after lunch. Unfortunately, the intern only worked the mornings, so it took several days of back and forth before the bug could be finally put to rest.
Perl code that is syntactically correct only on Fridays
171–180 of 233 posts
Re: Perl code that is syntactically correct only on Fridays
#172Earlier quoted context omitted.
Perl is not parsed as it is executed. It is compiled to opcodes then run. The BEGIN block, however, explicitly runs code at compile time. It is literally compiling different code on different days, then attempting to run it.
Technically not opcodes, but internal Data Structures. A serializer was written for that, to permit ".pmc files".
Looking forward to the next time we can have steaks and Scotch.
Re: Perl code that is syntactically correct only on Fridays
#173I have written code that only works in winter because of daylight saving times and some unfortunate date conversions, but having a temporary correct syntax is really a new high.
As a part of a release always got borked, I wrote a small bash script that took currently deployed files, archived them to rollback_dateandtime.tgz, then put the freshly released files in its place. It turns out we never did a release before 10:00, because it ran fine for a few years, but the regex constructing the filename could not deal with hours consisting of 1 number. Oh well, never write production shell script…
Re: Perl code that is syntactically correct only on Fridays
#174Why only things like these float up to the front page, and not elegant and/or wholesome things written in Perl?
Because with its declining popularity, most people here are unfamiliar with the language except for its meme status as "that weird line noise language". Things that confirm pre-existing beliefs are easy to accept and upvote, whereas good Perl code would require (a) some actual thinking, and (b) challenging the socially accepted narrative - both of which are relatively much harder.
Re: Perl code that is syntactically correct only on Fridays
#175Earlier quoted context omitted.
Personally I really don't like code that deals with time - it's too easy to place a "get time stamp" call anywhere in code. If it's down in the bowels of some piece of functionality trying to test it becomes a headache.
This is one of those pieces of software engineering wisdom that only comes from experience. Try explaining to a newish dev why they shouldn't `const now = Date.now()` or whatever anywhere they want, but rather do it in one place for the lifecycle and pass it around, and they will look at you funny and think it's a waste of time. Classic case of simple vs easy. Time has the potential to complect everything it touches.
Re: Perl code that is syntactically correct only on Fridays
#176Earlier quoted context omitted.
> because how hard can it be to work with dates? Oh man, tell me about it. Timezones are the worst. No wonder so many people just give up and use Moment.js.
Use UTC UNIX timestamps (i.e. Date.now()) for ALL time-related processing and only convert to hours/minutes when taking input/output from the user.
Re: Perl code that is syntactically correct only on Fridays
#177Re: Perl code that is syntactically correct only on Fridays
#178Earlier quoted context omitted.
This is one of those pieces of software engineering wisdom that only comes from experience. Try explaining to a newish dev why they shouldn't `const now = Date.now()` or whatever anywhere they want, but rather do it in one place for the lifecycle and pass it around, and they will look at you funny and think it's a waste of time. Classic case of simple vs easy. Time has the potential to complect everything it touches.
Oh yes. Any time I see code that tries to do some kind of scheduling, the first thing I ask is if they have considered using a library someone else has written. Way too many things can subtly go wrong, but new folks tend to think it should be easy, because how hard can it be to work with dates?
1. https://en.wikipedia.org/wiki/Time_in_Indiana#tz_database
Re: Perl code that is syntactically correct only on Fridays
#179I had an intern once who wrote similar code. They confused 12 hour and 24 hour clocks, so the code would break after lunch. Unfortunately, the intern only worked the mornings, so it took several days of back and forth before the bug could be finally put to rest.
What is the best way to set or mock system time during testing?
Re: Perl code that is syntactically correct only on Fridays
#180Earlier quoted context omitted.
Our sysadmin was being paranoid about how many memory-resident programs we ran. he figured time syncing wasn't important enough to justify a daemon, so he just ran the ntpdate command on a daily schedule. It wasn't that bad - after all, how far can clocks drift in a single day!? ;-)
> he figured time syncing wasn't important enough to justify a daemon Time synchronization is very arguable THE most important thing on a server (for numerous security related reasons). How many moons ago was this incident? It's perhaps forgivable ignorance in the 90s... not so much today.
NTP can't properly fix a clock like that either since it's often capped at adjusting the speed by one part per two thousand. At most, with a consistently wrong clock, that can handle about 30 seconds per day. Any worse than that and you won't see much advantage over ntpdate.