SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 15th, 2002, 01:36 PM
Maarten Maarten is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Amsterdam
Posts: 22 Maarten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Classes vs multi-dimensional arrays

To be honest, i've never really used classes in my code... That's because i don't always see the use of them...
I think with multi-dimensional arrays you can accomplish the same.
So can anyone tell me of a script that can only be made with the use of classes? So i can see the use of them

Reply With Quote
  #2  
Old June 15th, 2002, 03:00 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Classes vs multi-dimensional arrays

Well, a class is alot different from an array. The major difference is that a class has functions in it as well as data. From the PHP manual:
Quote:
A class is a collection of variables and functions working with these variables.


Here is a small sample class you can look at to see the basic functionality of one:
php Code:
Original - php Code
  1. <?
  2.  
  3. class RandomNumber {
  4.    
  5.   var $number;
  6.    
  7.   function make_seed() {
  8.     list($usec, $sec) = explode(' ', microtime());
  9.     return (float) $sec + ((float) $usec * 100000);
  10.   } 
  11.    
  12.   function generate ($min = 1, $max = 10) {
  13.    
  14.     srand($this->make_seed());
  15.    
  16.     $this->number = rand($min,$max);
  17.   }
  18. }
  19.  
  20. $num = new RandomNumber();
  21. $num->generate();
  22. echo $num->number;
  23. echo "<BR>n";
  24. $num->generate(60,100);
  25. echo $num->number;
  26.  
  27. ?>


Hope that helps a bit...

Reply With Quote
  #3  
Old June 15th, 2002, 04:33 PM
Maarten Maarten is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Amsterdam
Posts: 22 Maarten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Classes vs multi-dimensional arrays

Thanks for the sample...

I know (mostly) how classes work. But i see other people use classes where i use a structure of arrays and for-loops.
For instance with the current contest. I'm sure a lot of people use classes to define the coördinates of each 'cell' in the maze.
I use an multi-dim array like this to store my coordinates:
$coords[$maze_num][$ypos][$xpos].
And it works perfectly.
The only problem i can see is that other people won't understand my code easily, because it's less structured

Reply With Quote
  #4  
Old June 15th, 2002, 04:50 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Classes vs multi-dimensional arrays

i'm all about arrays as well..

Reply With Quote
  #5  
Old June 15th, 2002, 10:06 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: Classes vs multi-dimensional arrays

Same here. Classes get far too messy way too fast imho. But i actually want to see if i can incorporate classes into my thinking structure.. maybe it has some use.. ;)

Reply With Quote
  #6  
Old June 15th, 2002, 11:08 PM
Maarten Maarten is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Amsterdam
Posts: 22 Maarten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: Classes vs multi-dimensional arrays

Quote:
But i actually want to see if i can incorporate classes into my thinking structure.. maybe it has some use.. ;)

Yeah, that's also what i'm trying to do... That's why i'm asking to think of a script/program that can only be done with classes...

Reply With Quote
  #7  
Old June 16th, 2002, 11:04 PM
greggory greggory is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Reims, France
Posts: 82 greggory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: RE: Classes vs multi-dimensional arrays


Quote:
The only problem i can see is that other people won't understand my code easily, because it's less structured


That's what I used to think, but in a couple of months, if you need to re-do sthg you did in a messy manner, you'll probably have forgotten how it works if it's not well structurated. That's also why everybody *needs* to comment is code

Reply With Quote
  #8  
Old June 17th, 2002, 01:41 AM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: Classes vs multi-dimensional arrays

I don't think it's possible to have a problem that can only be solved with classes. Classes may make some problems eaiser to think about and eaiser to code, but there are many ways to skin a cat.

Commenting code is important, but I think good, clear abstraction is more important. And usually, classes help clarify your levels of abstraction.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Classes vs multi-dimensional arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway