PenUltima Online

It is currently Wed Aug 20, 2008 9:56 am

All times are UTC - 4 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Why arrays instead of structs with non homogenous data?
PostPosted: Tue Aug 29, 2006 7:32 pm 
Offline

Joined: Sun Mar 05, 2006 11:25 am
Posts: 118
Location: Italy
I've seen a lot of distro scripts use arrays instead of distro to store non homogenous data (such as a mobile reference, a string and an integer). This happens especially when passing variabiles with StartScript(). Shouldn't be better to pass a structure when the variables are non homogenous? Is there any precise design choice behind the use of arrays? Does it improve performance? Am I doing any mistake in using structures instead of arrays for non homogeneous data?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 8:54 pm 
Offline

Joined: Sat Feb 04, 2006 9:49 pm
Posts: 732
Location: Chicago, IL USA
I think usually its just a preference. Pass it as an array because you can declare it like

array{ who, item, something }

then split it up into variables in the other script instead of

struct{ who := who, item := item, something := something }

and still breaking it up into variables in the other script since its a bit shorter to use...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 1:46 am 
Offline

Joined: Thu Feb 02, 2006 5:41 pm
Posts: 1094
Location: Southern Central USA
I think also that it has been said many times that "the way to pass variables between scripts using 'startscript' is to store them in an array". In fact I had thought that was the only way until recently. I can't remember ever reading, atleast here on the forums, of anyone using a struct to pass them.

_________________
Sincerely,
Yukiko

I know you think you understand what you thought I said but what you heard is not exactly what I meant.

Titus 2:13


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 2:05 am 
Offline
POL Developer
User avatar

Joined: Wed Jan 25, 2006 6:30 am
Posts: 382
Location: San Diego, California
You can pass anything... but only 1 thing.
Arrays are just a preference, as CWO said.
Mainly its because of how they are easier to setup and read when used.

_________________
-Austin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 2:29 am 
Offline
Distro Developer
User avatar

Joined: Thu Apr 06, 2006 9:11 pm
Posts: 350
Location: Nederland, Texas
Programmers are the laziest people--the less keystrokes the better. Why do you think we write programs to do stuff for us?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 5:21 am 
Offline

Joined: Sun Mar 05, 2006 11:25 am
Posts: 118
Location: Italy
Ok, since noneone told me I'm a fool using a more complex structure rather than an array, I'll stay with structures, which I use with startscript whenever variabiles passed are non homogeneous. Maybe I'll stay with arrays even if variables are non homogeneous only in those rare cases where performance is critical


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 5:35 am 
Offline

Joined: Thu Feb 02, 2006 5:41 pm
Posts: 1094
Location: Southern Central USA
Lagoon, if it works than you're not a fool. Fools are the ones that keep on using something even when it doesn't work.

_________________
Sincerely,
Yukiko

I know you think you understand what you thought I said but what you heard is not exactly what I meant.

Titus 2:13


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 1:50 pm 
Offline

Joined: Sat Feb 04, 2006 9:49 pm
Posts: 732
Location: Chicago, IL USA
tekproxy wrote:
Programmers are the laziest people--the less keystrokes the better. Why do you think we write programs to do stuff for us?



We're not lazy... its called efficiency... :D


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 3:05 pm 
Offline

Joined: Thu Feb 02, 2006 5:41 pm
Posts: 1094
Location: Southern Central USA
Besides that when we use other people's code to create our own programs, that's not stealing it's called recycling. Just think of how much of a problem we'd have with all those virtual landfills if we didn't reuse code.

_________________
Sincerely,
Yukiko

I know you think you understand what you thought I said but what you heard is not exactly what I meant.

Titus 2:13


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:05 pm 
Offline

Joined: Thu Feb 02, 2006 10:09 am
Posts: 325
heh.. to pile on; If you find that using a struct works best for you, then by all means, use them! My preference for arrays is due to what was mentioned above; ease of creating and passing an array. However, if a struct makes your code easier to read or understand, or just seems better to you, use it :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 6:49 pm 
Offline

Joined: Sun Mar 05, 2006 11:25 am
Posts: 118
Location: Italy
Yes, I find it much easyer to read, especially when the array is big after months it's hard to remember which index was what (or, one can add comments, but I prefere to have variables autoexplaining their meaning)
I asked onyl because I wanted to know if there is any relevant efficiency different behind that choice of if it's just a different style


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 3:52 am 
Offline

Joined: Thu Feb 02, 2006 10:09 am
Posts: 325
There -might- be the most miniscule of effeiciency differences between the two. However, it's not likely to even be measurable unless we're talking really huge collections (array vs dictionary). Generally, indexing an array is faster than searching an index of a dictionary, but the difference is likely to be terribly small, unless you are talking about comparing an array or collection of hundreds or thousands of items in them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 4 hours


Who is online

Users browsing this forum: No registered users and 0 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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subice by phpBBservice.nl