Re: [web2py] Re: gluon.storage.Storage interface discrepancy?

2011-11-02 Thread Jonathan Lundell
On Nov 2, 2011, at 10:15 PM, Magnitus wrote:

 I agree.
 
 s.a is not sufficient if you want to avoid code repetition.
 
 You'll naturally want use something like s['a'] at some point if you
 want to write good code and you will also want to rely on the
 convenient returns None instead of throwing an exception facility.
 
 There are workarounds for this (personally, I just wrote a wrapper
 class to go around it so that I could use a natural dictionary
 notation with keeping the None behavior).
 
 As part of your mandate is to support backward compatibility, someone
 probably relies on that peculiarity at this point, so you are stuck
 with the behavior of s['a'] throwing an exception the way it is now.
 
 Perhaps just make sure the behavior of the storage object is properly
 documented so that it doesn't catch new people off guard.
 
 Still, it'd make sense for s['a'] to have the same semantics as s.a.

I'm of two minds on classes like Storage. In my non-web2py work I stick with 
dict, using dict.get and dict.setdefault where appropriate. But web2py has a 
lot of Storage objects floating around...

Re: [web2py] Re: gluon.storage.Storage interface discrepancy?

2011-10-27 Thread Jonathan Lundell
Sure. On the road now, but shortly. 

On Oct 27, 2011, at 10:57 AM, Massimo Di Pierro massimo.dipie...@gmail.com 
wrote:

 Any suggestion for improvement?
 
 On Oct 25, 3:32 pm, Jonathan Lundell jlund...@pobox.com wrote:
 On Oct 25, 2011, at 1:18 PM, Anthony abasta...@gmail.com wrote:
 
 On Tuesday, October 25, 2011 4:08:20 PM UTC-4, pepper_bg wrote:
 You can do
 s.get(6,None)
 
 Still have to anticipate what my keys are and write different code
 accordingly. Which is fine in most cases I guess. Or may be I am
 trying to be too generic here. Thanks for your input...
 
 If you're not sure whether a key might be a string or integer, you can use 
 the s.get() method in all cases.
 
 Still, it'd make sense for s['a'] to have the same semantics as s.a.


Re: [web2py] Re: gluon.storage.Storage interface discrepancy?

2011-10-27 Thread Jonathan Lundell
On Oct 27, 2011, at 10:57 AM, Massimo Di Pierro wrote:

 Any suggestion for improvement?

I'm not sure when I'll have time to get around to it, but my idea is to 
implement both Storage.__getattr__ and .__getitem__ in terms of 
super(get(whatever, None)). (That's not quite the syntax, but you get the 
idea.) I don't suppose that __setattr__ needs any special attention.

 
 On Oct 25, 3:32 pm, Jonathan Lundell jlund...@pobox.com wrote:
 On Oct 25, 2011, at 1:18 PM, Anthony abasta...@gmail.com wrote:
 
 On Tuesday, October 25, 2011 4:08:20 PM UTC-4, pepper_bg wrote:
 You can do
 s.get(6,None)
 
 Still have to anticipate what my keys are and write different code
 accordingly. Which is fine in most cases I guess. Or may be I am
 trying to be too generic here. Thanks for your input...
 
 If you're not sure whether a key might be a string or integer, you can use 
 the s.get() method in all cases.
 
 Still, it'd make sense for s['a'] to have the same semantics as s.a.




Re: [web2py] Re: gluon.storage.Storage interface discrepancy?

2011-10-27 Thread Jonathan Lundell
On Oct 27, 2011, at 5:03 PM, Jonathan Lundell wrote:

 On Oct 27, 2011, at 10:57 AM, Massimo Di Pierro wrote:
 
 Any suggestion for improvement?
 
 I'm not sure when I'll have time to get around to it, but my idea is to 
 implement both Storage.__getattr__ and .__getitem__ in terms of 
 super(get(whatever, None)). (That's not quite the syntax, but you get the 
 idea.) I don't suppose that __setattr__ needs any special attention.

__setitem__, I meant.

 
 
 On Oct 25, 3:32 pm, Jonathan Lundell jlund...@pobox.com wrote:
 On Oct 25, 2011, at 1:18 PM, Anthony abasta...@gmail.com wrote:
 
 On Tuesday, October 25, 2011 4:08:20 PM UTC-4, pepper_bg wrote:
 You can do
 s.get(6,None)
 
 Still have to anticipate what my keys are and write different code
 accordingly. Which is fine in most cases I guess. Or may be I am
 trying to be too generic here. Thanks for your input...
 
 If you're not sure whether a key might be a string or integer, you can use 
 the s.get() method in all cases.
 
 Still, it'd make sense for s['a'] to have the same semantics as s.a.
 
 




Re: [web2py] Re: gluon.storage.Storage interface discrepancy?

2011-10-25 Thread Jonathan Lundell
On Oct 25, 2011, at 1:18 PM, Anthony abasta...@gmail.com wrote:

 On Tuesday, October 25, 2011 4:08:20 PM UTC-4, pepper_bg wrote:
  You can do 
  s.get(6,None) 
 
 Still have to anticipate what my keys are and write different code 
 accordingly. Which is fine in most cases I guess. Or may be I am 
 trying to be too generic here. Thanks for your input...
 
 If you're not sure whether a key might be a string or integer, you can use 
 the s.get() method in all cases. 

Still, it'd make sense for s['a'] to have the same semantics as s.a.