PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Dec 18, 2018 5:27 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Sun Oct 17, 2010 6:41 am 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
Jonah Bron wrote:
I definitely agree that the developer should be able to change the century threshold.

Good name for the setting

Jonah Bron wrote:
This object is also good at simply containing this data. Would this be an implementation of the Value Object pattern?

Thanks and yes. There is a school of thought that says every object must either have an "identity" or be a value object, but I don't know if there is a strict definition, but basically yes.

Jonah Bron wrote:
One question. Why do you break up the range every time the validity is checked, instead of just once in the constructor? Also, why do you check the validity every time the range is accessed, instead of just setting a boolean variable?

In TDD it is more important to get it working first (tests passing). The goal is to write code that solves the user's problem, and minimize time writing code that does not directly solve the problem at hand. The next goal is to make that code "solid", it shouldn't break when programmers use it wrong, it should have error handling (exceptions). "Get it working first". Commit that to SVN

Once that is done the next most important goal is code readability, get the code re-factored. This produces maintainable code. Commit the cleanups to SVN. At this point our code can seem to be really inefficient compared to a procedural implementation. Often times this doesn't even create bottlenecks, and is often cited as a down side to readable code in general, it can be inefficient. However with TDD, I can add the caching on at a later date, where as if I had focused on the caching before the business logic, the main code would not be as readable in my opinion. Software is infinitely malleable (at least when doing TDD)


Top
 Profile  
 
PostPosted: Sun Oct 17, 2010 11:21 am 
Offline
DevNet Master
User avatar

Joined: Thu Mar 15, 2007 6:28 pm
Posts: 2765
Location: Redding, California
josh wrote:
Good name for the setting

Glad you like it :)

josh wrote:
[...] every object must either have an "identity" [...]

By having an identity, do you mean it should be a property of an object?

josh wrote:
[everything else]

I need to research TDD more extensively. When I first discovered version control and how it applied to developers, I was committing every twenty minutes. As I've learned more about unit tests, design patterns, and development practices in general (working on Skeleton), I've toned that down to only committing when I've made a change that actually works. After considering it, committing something that doesn't work is pretty silly; why would I want it later?

Cool stuff.


Top
 Profile  
 
PostPosted: Sun Oct 17, 2010 12:53 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
Jonah Bron wrote:
By having an identity, do you mean it should be a property of an object?

Identity, Ex: User ID #3
Value, Ex. '12 inches'

The question is, is a year a value or an identity? Can't really answer that because the definitions are ambiguous or non-existent, so its not a useful way to classify objects in all situations. So yes its technically the value pattern, but meh. Part of the definition of the value object is its not a "business object", and this object definitely is a part of the business logic in my application, so I'm not sure what the right answer is. I don't think it matters though...

josh wrote:
I need to research TDD more extensively. When I first discovered version control and how it applied to developers, I was committing every twenty minutes. As I've learned more about unit tests, design patterns, and development practices in general (working on Skeleton), I've toned that down to only committing when I've made a change that actually works.

Yes you should only commit working code. TDD allows you to commit every 5 minutes, if I get stuck for more than a few moments I just revert. I keep my time investments small so I can commit/revert frequently. Always working in small steps. I only implement enough code to make 1 test pass at a time, and then commit that. If I can't pass the test I revert it, take a break & think it over more, or work on something else for a while. I literally went from spending ~5hrs per day debugging (in a 12hr work day) to spending almost 100% of my time coding. Now if I ever need to debug, which is really rare, its usually something really simple like accidentally reversing an 'if' statement, since I made the change within the last 5 minutes - its not ever hard to find, and in fact i can just revert at any time to get back to a working state. The goal is to more readily revert than commit. I mean, when you wrote in school you did the rough draft, final draft, etc... same thing with code. It evolves over time, you keep adding better stuff and removing failed stuff.

Quote:
After considering it, committing something that doesn't work is pretty silly; why would I want it later?

Well I could tell you why you wouldn't, because its going to cost you 100x the amount of time to hunt down all the bugs later :-)


Top
 Profile  
 
PostPosted: Mon Oct 18, 2010 11:37 am 
Offline
DevNet Master
User avatar

Joined: Thu Mar 15, 2007 6:28 pm
Posts: 2765
Location: Redding, California
So, basically, TDD allows you to replace a lot of time on an unknown (i.e. debugging) with a significantly smaller amount of time on a known (i.e. unit test writing). Seems like this would also allow new developers to integrate very quickly. If the want to change a bit of code, they only have to figure out how one little piece works.

josh wrote:
[...] because its going to cost you 100x the amount of time to hunt down all the bugs later :-)

Good point. The further into the future, the less familiar I'll be with the code.


Top
 Profile  
 
PostPosted: Mon Oct 18, 2010 12:16 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13585
Location: New York, NY, US
Jonah Bron wrote:
So, basically, TDD allows you to replace a lot of time on an unknown (i.e. debugging) with a significantly smaller amount of time on a known (i.e. unit test writing).

You know ... that is one of the best succinct descriptions of the benefit of TDD I have read!

_________________
(#10850)


Top
 Profile  
 
PostPosted: Mon Oct 18, 2010 12:23 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
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).


Top
 Profile  
 
PostPosted: Fri Oct 22, 2010 1:17 am 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
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.


Top
 Profile  
 
PostPosted: Fri Oct 22, 2010 2:56 am 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria
http://php.net/manual/en/function.strtotime.php
Quote:
Note:

If the number of the year is specified in a two digit format, the values between 00-69 are mapped to 2000-2069 and 70-99 to 1970-1999.


:)

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
PostPosted: Fri Oct 22, 2010 12:29 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
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.


Top
 Profile  
 
PostPosted: Fri Oct 22, 2010 12:45 pm 
Offline
DevNet Master
User avatar

Joined: Thu Mar 15, 2007 6:28 pm
Posts: 2765
Location: Redding, California
josh wrote:
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.

So the moral of the story is, "Get it working first, then worry about performance tweaks". :mrgreen:


Top
 Profile  
 
PostPosted: Fri Oct 22, 2010 4:53 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
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.


Top
 Profile  
 
PostPosted: Fri Oct 22, 2010 5:25 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group