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.
Perl code that is syntactically correct only on Fridays
131–140 of 233 posts
Re: Perl code that is syntactically correct only on Fridays
#132I 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.
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
#133Earlier 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.
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
#134Earlier 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 )
Re: Perl code that is syntactically correct only on Fridays
#135Earlier 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?
Re: Perl code that is syntactically correct only on Fridays
#136Earlier 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
#137I 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.
Re: Perl code that is syntactically correct only on Fridays
#138Earlier 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
#139Re: Perl code that is syntactically correct only on Fridays
#140I 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.
What will happen when the command is `perl -c friday.pm`?