PHP Developers Network
http://forums.devnetwork.net/

Y2k 'Year 2000 Problem' & year string parsing Framework
http://forums.devnetwork.net/viewtopic.php?f=50&t=122369
Page 2 of 2

Author:  josh [ Sun Oct 17, 2010 6:41 am ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework


Author:  Jonah Bron [ Sun Oct 17, 2010 11:21 am ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework


Author:  josh [ Sun Oct 17, 2010 12:53 pm ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework


Author:  Jonah Bron [ Mon Oct 18, 2010 11:37 am ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework


Author:  Christopher [ Mon Oct 18, 2010 12:16 pm ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework


Author:  josh [ Mon Oct 18, 2010 12:23 pm ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework

There's really too many benefits to list in one spot. One of those is your have full awareness & control over your code's dependencies. If it runs in a unit test, it runs elsewhere. In test last, you can end up with code that has lots of dependencies to where the test is too hard to write it later on.

Also understand code coverage (Ex. 60% of my code executes under a test) is a meaningless figure, because even though a line may be hit, that doesn't imply you hit it with all possible inputs, so TDD helps conceptually 'see' all the tests we're going to need. All my code coverage analysis happens in my head. Because I have good coverage I can re-factor constantly, through small mechanical changes like "extract method" and "inline variable", etc.. my code becomes more like English than 'code' (I'd like to think so).

Author:  josh [ Fri Oct 22, 2010 1:17 am ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework

I fixed an issue with a few test cases that weren't running due to a typo on my part, and fixed corresponding production code. Now passing '2005' properly returns 2005 for both start & end.

Also I added " 2005 - 2006 " as a supported use case, there can be white-space before or after each year and it will be trimmed.

Author:  VladSun [ Fri Oct 22, 2010 2:56 am ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework


Author:  josh [ Fri Oct 22, 2010 12:29 pm ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework

The century threshold is now adjustable for the year/range objects both. See my original post for usage.

I should point out to Jonah Bro if I had implemented caching, I would have had to taken it out now or worry more about what happens if someone changes the threshold after its cached and asks for a value. As you see, caching becomes a complexity in it's own right because any feature we add has to inter-operate with other dependencies in the component. And so far its performing fast enough for me.

However maybe it would have been better to accept all inputs in the constructor and make them immutable, that would be a good way to go if caching becomes necessary in the future.

@Vlad cool but too bad it doesn't handle ranges, or have adjustable thresholds. No idea why they choose '60', 60 wouldn't work well for my users. I bet other people thought the same about my choice of 25, well now you can customize it. Imagine telling someone no products were found for your 2069 Chevy Donk. lol. Or that we have some products for you World War II Jeep made in 2045. I still think my observation is right, 2 digit years tend be used more so during the last century than this one.

Author:  Jonah Bron [ Fri Oct 22, 2010 12:45 pm ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework


Author:  josh [ Fri Oct 22, 2010 4:53 pm ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework

Yes but an even broader moral is, get the important stuff working, then worry about the less important stuff, then the slightly less important stuff (this usually goes on ad infinitum if your software is a success).

I have updated with a way to disable Y2K mode, and worked on refactoring the tests some. Updating the OP. Ok done. See y2k-v4.zip

Update 2 - Can now disable Y2k Mode:
Syntax: [ Download ] [ Hide ]
$year->setY2kMode(false);
 


Need to have a way to disable it for a 'year range' (refactoring some of the tests to make this cleaner first). Once that's done I'll probably refactor the production code some, and create an interface or an abstract base class of some sort.

Author:  josh [ Fri Oct 22, 2010 5:25 pm ]
Post subject:  Re: Y2k 'Year 2000 Problem' & year string parsing Framework

Everything I just said is now done (v5). The code itself should read a lot more like plain English now.

http://img268.imageshack.us/img268/629/difflx.jpg
http://img101.imageshack.us/img101/8895/diff2.jpg

Page 2 of 2 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/