12 messages in com.perforce.p4ruby[p4ruby] Canvassing opinions...| From | Sent On | Attachments |
|---|---|---|
| Tony Smith | 07 Dec 2004 09:12 | |
| Bennett, Patrick | 07 Dec 2004 09:42 | |
| Tony Smith | 07 Dec 2004 10:08 | |
| Bennett, Patrick | 07 Dec 2004 10:24 | |
| Shackelford, John-Mason | 07 Dec 2004 11:08 | |
| Johan Nilsson | 08 Dec 2004 00:11 | |
| Tony Smith | 08 Dec 2004 06:25 | |
| Bennett, Patrick | 08 Dec 2004 06:42 | |
| Shackelford, John-Mason | 08 Dec 2004 08:18 | |
| Tony Smith | 08 Dec 2004 08:20 | |
| Tony Smith | 08 Dec 2004 08:24 | |
| Tony Smith | 09 Dec 2004 05:47 |
| Subject: | [p4ruby] Canvassing opinions...![]() |
|---|---|
| From: | Tony Smith (to...@smee.org) |
| Date: | 12/08/2004 08:20:04 AM |
| List: | com.perforce.p4ruby |
On Wednesday 08 December 2004 08:11, Johan Nilsson wrote:
-----Original Message----- From: p4ru...@perforce.com [mailto:p4ru...@perforce.com] On Behalf Of Tony Smith Sent: den 7 december 2004 18:13 To: p4r...@perforce.com Subject: [p4ruby] Canvassing opinions...
I've got a change to P4Ruby that I'm considering to run by you. I'd like to know if this is something that people want/need or whether I should leave well alone.
The idea is that all the form parsing methods would return a P4::Spec object instead of a Hash - though you'll notice little difference since a P4::Spec object is a subclass of Hash. The advantage of a P4::Spec object is that it:
(a) ensures that you only set valid fields (b) provides you with accessor methods for all valid fields (c) the accessor methods are all prefixed with an '_' to avoid colliding with methods from Hash itself (Hash#update was the one that bit me). The underscores are a bit Pythonesque, but seemed like a reasonable choice. I'm open to suggestions though.
What about appending _field instead? Prepending underscores certainly means less typing, but it's a bit too cute (i.e. ugly) for me. Some alternatives:
client.root_field = "/tmp" client["root"] = "/tmp" # redefine to validate client.fields["root"] = "/tmp" # same
The _field suffix seems overly verbose to me (sorry, I like brevity!) and visually interferes with scanning of the code. I'm after something simpler. So far the '_' prefix seems the best of the alternatives.
Anyway, what's the problem with name collisions - you mean that the existing users expect an 'update' method (doing Hash#update) available on the 'spec' object?
No, the problem is that you can't access the update (modified) timestamp on any of your specs because it calls Hash#update instead.
With the risk of breaking compability, why not use delegation/aggregation instead and provide e.g. to_h/from_h methods in the Spec class?
That's an interesting idea. I'll give that some thought.
Thanks for your comments, much appreciated.
Tony




