Re: [Pydev-code] New pydev jython scripts: Assign stuff to variable if it is None
Brought to you by:
fabioz
From: Joel H. <yo...@if...> - 2006-09-19 11:56:59
|
> def met1(self, arg=None): |<-- ctrl+1 here would bring the suggestion, > instead of having to create another line with arg to make the choice > (and if more than one argument had '=None', add one option for each). > > What do you think? I also think that this could have several benefits to it, as you could probably quite easily implement separate behaviors for constructors and conventional methods. This would probably be the most useful pattern for constructors: class MyClass: def __init__(self, arg = None): if arg is None: arg = list() self.arg = arg while you probably would want to do this for other methods: class MyClass: def method(self, arg = None): if arg is None: arg = self.arg How does that sound to you? Is it reasonable? It's certainly true for my style of coding anyway. I elaborated on the rationale for doing things this way in the use case docs for AssignToAttributeOfSelf (if I'm allowed to repeat myself... :-) '''It's often a good idea to use the same names in args, variables and data members. This keeps the terminology consistent. This way customer_id should always contain a customer id, and any other variants are misspellings that probably will lead to bugs.''' What do you think? Cheers! /Joel |