[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

give me advices about method name

kwatch

9/17/2008 11:17:00 PM

Hi,
I'm wondering what method names are appropriate for my library.
Could you give me advices?

Background:
I'm developping Motto-mysql library (not released yet).
http://github.com/kwatch/motto-mysql/t...
This library will improve Mysql/Ruby driver.

Motto-mysql will add some methods to Mysql::Result class.

* Mysql::Result#fetch_one_hash() returns a hash.
* Mysql::Result#fetch_one_array() returns an array.
* Mysql::Result#fetch_one_object(klass) returns an instance of klass
* Mysql::Result#fetch_all_hash() returns an array of hashes
* Mysql::Result#fetch_all_array() returns an array of arrays
* Mysql::Result#fetch_all_object(klass) returns an array of instances

# These methods convert data into proper type (Integer, Boolean, etc)
# while Mysql::Result#fetch() returns all data as String.
# For example, they return 3.14 while Mysql::Result#fetch() returns
"3.14".

But I'm not sure these method names are appropriate and correct in
English.
Could you propose me if you have better names?

--
regards,
makoto kuwata

2 Answers

Phrogz

9/18/2008 2:51:00 AM

0

kwatch wrote:
> Motto-mysql will add some methods to Mysql::Result class.
>
> * Mysql::Result#fetch_one_hash() returns a hash.
> * Mysql::Result#fetch_one_array() returns an array.
> * Mysql::Result#fetch_one_object(klass) returns an instance of klass
> * Mysql::Result#fetch_all_hash() returns an array of hashes
> * Mysql::Result#fetch_all_array() returns an array of arrays
> * Mysql::Result#fetch_all_object(klass) returns an array of instances

In English, the all* methods should pluralize their nouns...
fetch_all_hashes
fetch_all_arrays
fetch_all_objects
....or perhaps...
fetch_every_hash
fetch_every_array
fetch_every_object

I'm not sure I understand what these methods, do, though. If they
select only items of the described class, I would probably go with:
fetch_hashes
fetch_arrays
fetch_objects

However, if they take an existing results set and interpret the
entries as the described class, I would probably suggest instead:
fetch_as_hashes
fetch_as_arrays
fetch_as_objects

I hope that helps.

kwatch

9/18/2008 4:31:00 AM

0

Thank you, Phrogz.
Your advice helps me very much.
I'll adopt fetch_hashes() or fetch_as_hashes().

--
regards,
makoto kuwata


2008/09/18 11:50 am, Phrogz <phr...@mac.com> wrote:
> kwatch wrote:
> > Motto-mysql will add some methods to Mysql::Result class.
>
> > * Mysql::Result#fetch_one_hash()  returns a hash.
> > * Mysql::Result#fetch_one_array() returns an array.
> > * Mysql::Result#fetch_one_object(klass) returns an instance of klass
> > * Mysql::Result#fetch_all_hash() returns an array of hashes
> > * Mysql::Result#fetch_all_array() returns an array of arrays
> > * Mysql::Result#fetch_all_object(klass) returns an array of instances
>
> In English, the all* methods should pluralize their nouns...
> fetch_all_hashes
> fetch_all_arrays
> fetch_all_objects
> ...or perhaps...
> fetch_every_hash
> fetch_every_array
> fetch_every_object
>
> I'm not sure I understand what these methods, do, though. If they
> select only items of the described class, I would probably go with:
> fetch_hashes
> fetch_arrays
> fetch_objects
>
> However, if they take an existing results set and interpret the
> entries as the described class, I would probably suggest instead:
> fetch_as_hashes
> fetch_as_arrays
> fetch_as_objects
>
> I hope that helps.