Live data from Hacker News

Perl code that is syntactically correct only on Fridays

github.com

171–180 of 233 posts

Re: Perl code that is syntactically correct only on Fridays

#171
post #10

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.

Saw some tests that had the same pattern. Passed half the day, and failed the other half of the day. I assume it always worked during India work hours.

Re: Perl code that is syntactically correct only on Fridays

#172
post #67

Earlier 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".

Oh, hey, Randal. Thanks for the correction.

Looking forward to the next time we can have steaks and Scotch.

Re: Perl code that is syntactically correct only on Fridays

#173

I 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…

This is why we can't have nice things.

Re: Perl code that is syntactically correct only on Fridays

#174

Why 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.

Afaik Perl is not declining in popularity, it's just not growing in popularity as fast as many other languages, so it's market share shrinks while the number of users it has grows.

Re: Perl code that is syntactically correct only on Fridays

#175

Earlier 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.

It's also one of those things that actually is simple in restricted cases, then when you try to generalise it blows up badly, and it blows up like a time bomb rather than a landmine. When a time bomb explodes you don't quite know when it was triggered, but you have to deal with it then and there, learning a heck of a lot about time libs in general before you can proceed. What's a leap second, which years have a leap day, are time zones connected to places somehow, and so on. Just so you can fix your calendar that's part of a larger app.

Re: Perl code that is syntactically correct only on Fridays

#176
post #129

Earlier 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.

Hmm, I think you should use TAI over UTC because UTC has leap-second corrections, Which means that the current time + X seconds might not actually be X seconds from now

Re: Perl code that is syntactically correct only on Fridays

#178
post #88

Earlier 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?

There are seven time zones in Indiana in the tz database[1] - this doesn't count the two most used ones America/Chicago and America/New_York there's also a Kentucky tz that slightly spills into the state. Whenever anyone makes any comment about dates and times being easy to compute I just mention that yes, there are seven time zones in Indiana. Now the actual issues tend to arise when software makes assumptions like "every second will actually occur", "each second only happens once", "every minute has 60 seconds", "every day has 86400 seconds" amongst a plethora of other bad assumptions... but those are a lot more complicated to explain. I like leaning on Indiana.

1. https://en.wikipedia.org/wiki/Time_in_Indiana#tz_database

Re: Perl code that is syntactically correct only on Fridays

#179
post #10

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.

Like many here, I’ve faced similar challenges in debugging time-dependent code.

What is the best way to set or mock system time during testing?

Re: Perl code that is syntactically correct only on Fridays

#180

Earlier 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.

For security? Kerberos usually has a 5 minute tolerance. Are you saying that's wrong? Because if your hardware/firmware isn't literally broken you won't drift anywhere near that in a day.

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.

Post reply on HN