[Ironpython-users] How can IronPython access a public static value defined in C#?
jdhardy at gmail.com
Mon Jun 20 21:11:31 CEST 2011
On Mon, Jun 20, 2011 at 12:04 PM, Jimmy Schementi <jschementi at gmail.com> wrote:
> On Jun 20, 2011, at 2:59 PM, Keith Rome wrote:
>> Evaluating a property could potentially introduce unexpected side effects. Best practices in OOP says that a property getter should never alter state, but it happens enough in the wild that I would think it to be dangerous to blindly invoke any getters during an import.
>> Also, presence of a property (as opposed to a field) implies that the code in the getter will be invoked each time the property is accessed. A consumer of such a construct expects this behavior, and might even depend on it.
>> If the auto import of properties is added, then it needs to at least be an opt-in feature.
> We already do this with "from Class import StaticProperty". (from DateTime import Now, for example). Making "from StaticClass import *" have the same behavior is what we're going for; right now they behave differently. Using import-star is already a convenience-only feature, so mucking with it's behavior is fair.
Keith's point is that 'from x import *' would be potentially dangerous
(as you don't know what the properties might do when get is called),
unlike explicit property imports. Unlikely, yes, but possible.
If someone provides some code to prove that the property getters are
safe, it would be OK, but I'm not counting on it.
More information about the Ironpython-users