Page 1 of 2

Scottayy Learns: Challenge 1

Posted: Thu Jun 01, 2006 3:27 pm
by s.dot
I dunno if this is the place to do this, but I'll give it a shot! Basically, I would like to get better in my OOP. Playing around with things like this is getting kind of redundant..

Code: Select all

require 'fruit.class.php';
$fruit = new fruit();

$fruit->showFruitBasket();
$fruit->addFruit('banana');
$fruit->showFruitBasket();
So basically what I would like to do is have someone challenge me with a code to do, and within a week or so I will answer with the best I could come up with. Other users can write code too and show it when the deadline is up. Then we can discuss and compare what was wrong, what was right, and what could be improved.

So, if anyone is up for it, I would like a challenge to meet the following requirements.

1. Would improve on my barbaric OOP knowledge. Perhaps setting a few method properties (big words :P).. nothing that's going to kill me... yet.
2. I would prefer not to use any databases or storing methods.
3. I don't care the subject nature of the assignment.
4. I can run either php4 or php5. So if your assignment would be specific to one or the other, please specify.

OK, so don't flame me too bad.. :oops: I just want to improve my code writing. A mix of basic OOP and procedural is starting to get really... ugly.

Thanks,
-Scott

Re: Scottayy Learns: Challenge 1

Posted: Thu Jun 01, 2006 3:38 pm
by Roja
scottayy wrote:So basically what I would like to do is have someone challenge me with a code to do, and within a week or so I will answer with the best I could come up with.
I like practical challenges - ones that actually can be used. So, with that in mind, your challenge: A user system.

Assumptions:

1. A live human being will only be one "user".
2. The "user" will have at least two properties - a first name, and a last name.

Requirements:

1. Code to add a user
2. Code to delete a user
3. Code to update a user's properties

The end. It doesn't have to have auth, login, storage, or anything else. Just a simple single page script that does the above.

That should get you thinking about objects and classes fairly well, and provide a solid foundation for discussion.

Posted: Thu Jun 01, 2006 4:08 pm
by s.dot
Alright, that sounds very much like something I could do and would help me learn a few things in the process. Others are welcome to code this and we can compare when I get mine done.

Thanks, Roja.

Re: Scottayy Learns: Challenge 1

Posted: Thu Jun 01, 2006 5:17 pm
by Christopher
Roja wrote:Requirements:

1. Code to add a user
2. Code to delete a user
3. Code to update a user's properties
That seem to be all about storage, so what if this system could sit on top of standard storage interfaces, let's say: PDO, mysqli, SQLite, ADODB, PEAR DB. You don't necessarily have to produce debugged code on all of those (others could), but the design should allow for an Adapter to be easily implemented for each -- you do the first couple that you are familiar with.

Posted: Thu Jun 01, 2006 5:39 pm
by MrPotatoes
do it in a flat file that way you learn more about files as well. it should append to the file.

rock on bro

Re: Scottayy Learns: Challenge 1

Posted: Thu Jun 01, 2006 5:54 pm
by RobertGonzalez
scottayy wrote:So basically what I would like to do is have someone challenge me with a code to do, and within a week or so I will answer with the best I could come up with. Other users can write code too and show it when the deadline is up. Then we can discuss and compare what was wrong, what was right, and what could be improved.

So, if anyone is up for it, I would like a challenge to meet the following requirements.

1. Would improve on my barbaric OOP knowledge. Perhaps setting a few method properties (big words :P).. nothing that's going to kill me... yet.
2. I would prefer not to use any databases or storing methods.
3. I don't care the subject nature of the assignment.
4. I can run either php4 or php5. So if your assignment would be specific to one or the other, please specify.
How about a flat-file content manager that stores page content in an array? Something along the lines of a simple, flat CMS. I know this borderline violates your requirement #2, but it might useful for folks.

Basic Premise:
A user has a web site with static content in a single file that contains a multi-dimensional array. There is a single page that interfaces with the content array to serve up the page that the user requested, but also allows for a single administrator to be able to login to their site to make changes to the content that is in the content array. No session handling, no databasing of content or admin user data, just flat file interaction and a lot of getting/setting within the contentDisplay object that you create.

Roja's suggestion is a good one also, I just like being a pain in the rear and coming up with ideas well after the need for ideas has been exhausted.

Posted: Thu Jun 01, 2006 6:14 pm
by Christopher
A completely different suggestion might be something like set of Http Response classes. It would deal with rendering the final output to send back to the browser, allow redirects, deal with including CSS and Javascript scripts and includes, META tags, know about different X/HTML standards. Even better would be if it would allow hierarchical page building like a CMS might use. And it should work with any template class.

Re: Scottayy Learns: Challenge 1

Posted: Thu Jun 01, 2006 6:19 pm
by s.dot
arborint wrote:
Roja wrote:Requirements:

1. Code to add a user
2. Code to delete a user
3. Code to update a user's properties
That seem to be all about storage, so what if this system could sit on top of standard storage interfaces, let's say: PDO, mysqli, SQLite, ADODB, PEAR DB. You don't necessarily have to produce debugged code on all of those (others could), but the design should allow for an Adapter to be easily implemented for each -- you do the first couple that you are familiar with.
I was thinking I could do Rojas challenge using session storage.

Re: Scottayy Learns: Challenge 1

Posted: Thu Jun 01, 2006 7:22 pm
by Roja
arborint wrote:That seem to be all about storage
No, you are misunderstanding the requirements.

This is about the simplest possible set of requirements, so its easy to start with. Just variables - no storage. One page, no persistence.

If we do well with "challenge one", yes, it would be easy to then expand the requirements to include persistence - which could be implemented in any form of storage.

I like the simplicity of a teaching concept like this user challenge. Adding storage will easily double or more the size of the example, and muddy the water.

One set of requirements at a time. No storage or persistence for this challenge. Session variables would be fine.

Re: Scottayy Learns: Challenge 1

Posted: Thu Jun 01, 2006 11:07 pm
by Christopher
Roja wrote:No, you are misunderstanding the requirements.
I probably did ... my point was that a task that has add, delete, update sounds like a storage task -- even if the storage is removed or changed to a non-database type.

Posted: Fri Jun 02, 2006 4:22 am
by Maugrim_The_Reaper
Just keep the session storage separate from the user class (presuming your approach), then you can later diversify the session storage using the Strategy Pattern. It's likely a simple refactor down the line anyway.

Posted: Fri Jun 02, 2006 7:51 am
by Roja
Maugrim_The_Reaper wrote:Just keep the session storage separate from the user class (presuming your approach), then you can later diversify the session storage using the Strategy Pattern. It's likely a simple refactor down the line anyway.
Thats exactly what I was aiming towards. I was thinking of it being an evolving codebase, starting with simple requirements, and as we expand those requirements, it will help make clear the advantages in TDD, UT, and so forth.

Posted: Fri Jun 02, 2006 8:17 am
by Maugrim_The_Reaper
I think we (me) are over-analysing the requirements given it's a learning process - sorry for butting in ahead of schedule...

Posted: Fri Jun 02, 2006 8:33 am
by Roja
Maugrim_The_Reaper wrote:I think we (me) are over-analysing the requirements given it's a learning process - sorry for butting in ahead of schedule...
Especially in learning, the value of getting the requirements right deeply outweighs any negatives to doing so.

Worse, once you start getting paid/rewarded/judged based on your ability to accomplish those requirements as stated.. its even more important. So no, we weren't over-analyzing the requirements. We were making sure we were clear about what we wanted to accomplish.

Posted: Fri Jun 02, 2006 8:44 am
by Chris Corbyn
Yeah I like Roja's suggestion, it sets a good base to develop further and further exploring many different areas whilst at the heart if it, it just started out simple :)

It's pretty much a container at this point, and maybe will stay this way, then at some point down the line we can pass the container to something else to work with ;)