Scottayy Learns: Challenge 1

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Scottayy Learns: Challenge 1

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: Scottayy Learns: Challenge 1

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Scottayy Learns: Challenge 1

Post 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.
(#10850)
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Scottayy Learns: Challenge 1

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Scottayy Learns: Challenge 1

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: Scottayy Learns: Challenge 1

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Scottayy Learns: Challenge 1

Post 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.
(#10850)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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...
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
Post Reply