Live data from Hacker News

Perl code that is syntactically correct only on Fridays

github.com

131–140 of 233 posts

Re: Perl code that is syntactically correct only on Fridays

#131
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.

I once had to implement date picker that returned the date to be sent to backend to fetch the day's reservations. It seemed to work fine the day I implemented it. Next day it broke. Turned out the widget returned MM/DD/YYYY instead of DD/MM/YYYY. And I implemented it on 10th of October.

I'm a big fan of ISO 8601. Eliminates the confusion, and sorts lexicographically too.

Re: Perl code that is syntactically correct only on Fridays

#132

I don't get it! It is clearly written in the code, that the progam should behave this way. Is the proof, that perl is capable of this behaviour?! I don't get it - what is the point? I read all the comments and still don't get it. What am i missing?

What makes it "special" here is the fact that it will COMPILE only on a friday. It's not a runtime error but a compile time error. Because yes otherwise I would agree that it's doable easily in every single language.

Here's a D program that only fails to compile if the last digit of the current number of seconds is 4:

enum timestamp = __TIMESTAMP__;

void main() { pragma(msg, timestamp[$-6..$-5]); auto a = 4; static if(timestamp[$-6..$-5] == "4") { auto a = 7; } }

Re: Perl code that is syntactically correct only on Fridays

#133

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.

> Classic case of simple vs easy.

Personally, I think my definition of "simple" changed over time. Much of that was influenced by the depth of my knowledge of particular paradigms, whether that be software or knowledge of the subjects I was writing code for.

Re: Perl code that is syntactically correct only on Fridays

#134
post #58

Earlier quoted context omitted.

Unless something has changed a lot, C++ templates at least only used to be Turing complete if you assume you're allowed unlimited recursive template applications, and compilers were free to restrict that (and did). Has that changed? In theory I agree with you that this is horribly ugly - I very much prefer simple grammars (the irony being my favourite language to use is Ruby, which has an atrocious grammar). In pract…

It's not the undecidability itself that is the problem though. The undecidability is just an indicator how horribly complicated C++ is to compile. You cannot even construct the full parse tree before evaluating a mini-language that is Turing complete. Related article: why C++ compilation is slow ( https://digitalmars.com/articles/b54.html )

I have a half-finished Ruby compiler sitting around, so I'm a bit jaded when it comes to how complicated something is to compile. C++ is complex, but at least it's reasonable well specified.

Re: Perl code that is syntactically correct only on Fridays

#135
post #64

Earlier quoted context omitted.

Ha. I had an intern who wrote code that blew up if the timestamp of our DB server was ever >= 1 second after the timestamp of our app server. It couldn't fail at his desk, because he ran both servers locally while developing. And it wouldn't fail in production in the morning, since we had a cron job that synced the clocks at midnight. It took until after 5pm for the clocks to drift enough, meaning I was on call and t…

> an intern who wrote code .... his code had been in production You get what you pay for, eh?

I've done equally stupid things as a senior dev. The biggest difference, I guess, is that I had to fix the stuff I broke.

Re: Perl code that is syntactically correct only on Fridays

#136
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.

Uh oh, we’re going there again. If you’re doing anything in the future, that’s not always the correct thing to do. (Instants vs wall time etc)

Re: Perl code that is syntactically correct only on Fridays

#138

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.

In Haskell, getting the time is an IO operation. Because of this one tends to use the exact pattern you recommend.

Re: Perl code that is syntactically correct only on Fridays

#140

I don't get it! It is clearly written in the code, that the progam should behave this way. Is the proof, that perl is capable of this behaviour?! I don't get it - what is the point? I read all the comments and still don't get it. What am i missing?

What makes it "special" here is the fact that it will COMPILE only on a friday. It's not a runtime error but a compile time error. Because yes otherwise I would agree that it's doable easily in every single language.

Isn't perl an interpreted language? Or I am missing a point?

What will happen when the command is `perl -c friday.pm`?

Post reply on HN