From: Jonathan E. <jon...@si...> - 2005-02-25 21:46:12
|
I don't like the idea of using a default other than None. It smacks of the kind of "I'm sure you didn't mean to format the paragraph THAT way; here, let me fix it for you" crap that Microsoft likes to pull. In particular I think being able to tell whether a value was submitted or not is quite useful as a first check that you got your form inputs named the way you thought you did. :) -Jonathan sp...@ma... wrote: > Like Jonathan, I've always found the request.get1('foo', '') syntax to be cumbersome for web programming. Typically, within python apps you may or may not want to make the distinction between None and empty-string which is why the language provides the get() method on dictionary objects. The distinction is much less of a concern with web programming since everything IS a string. > > In developing web apps, I rarely if ever care if a form attribute is missing or empty. If I need to validate 'foo' if it's empty or not there, it's the same result-- an error. Similarly, if I'm creating a new form by substituting in existing form's values (as in Jonathan's example) I also don't care if the value isn't there or if it's empty because obviously, I want to default the value to an empty string, because the user needs to provide the value when submitting the page. Under no situation would I want the user to submit the page with the value 'None' (ala [[= request['foo'] ]] because then my validation goes out-the-window (the submitted value is no longer empty string nor None, it's 'None'). > > However, as Rimon pointed out, the request object isn't a dictionary, so therefor it doesn't have to behave exactly like a dictionary which is why I think request.__getitem__ should be modified to behave more elegantly for web programming and return an empty string instead of None if the value isn't present. > > In 99% of the cases the web programmer would be satisfied if the attribute 'foo' did not exist and when referencing it via request['foo'] they'd receive an empty string. In the far rarer case that the programmer needed to make this distinction then they should be able to do so in a more explicit manner, say: request.get('foo') could return None if the param 'foo' did not exist. Existing request.get('foo', '') code would still work as intended but it could be replaced with request['foo'] as desired. > > In the spirit of "not breaking existing apps", I'm not sure how many apps use the [[=request['foo'] ]] syntax liberally (especially within forms) anyhow because of the 'None' effect. In my spyce apps, I always use the request.get('foo', '') syntax because of this issue. I would prefer to use something a bit more compact to achieve the same behavior. > > Phil > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Spyce-users mailing list > Spy...@li... > https://lists.sourceforge.net/lists/listinfo/spyce-users |