[Chicago] Get/Set/Accessors in Python?

sheila miguez shekay at pobox.com
Wed Dec 5 17:34:24 CET 2012


GRAR sometimes things are so annoying. why must we suffer so?

This setter/getter stuff with cross cutting concerns or business
logic, or what-have-you. ARG

In java, sometimes I handle the validation stuff by making pojos with
no setters, but they have builders. The builders provide the
validation logic. In the past, when people have put logic in POJO
getters and setters for things that get serialized and sent across the
wire to a client, I've had reactions like being ape-shit insane due to
the annoyances that can arise. I don't know, I guess you can move the
ape-shit annoyedness by moving the logic to different parts and then
other painful things will happen. With java, I have reacted to painful
things by using god-awful builders. to avoid god-awful other things. I
bet these are all smells happening due to design but also probably due
to the language. not just the design. the design accrues to the
language. HULK SMASH



On Wed, Dec 5, 2012 at 10:22 AM, Philip Doctor <diomedestydeus at gmail.com> wrote:
> Tim,
> I agree that they get misused a lot (especially in C#) but I see it's very
> common to put validation in a set in c#.  So maybe syntactically it looks
> like you're just setting myCar.Speed to 60, but in myCar it's validating
> that Speed is not negative and it's less than MaxSpeed, etc etc.  I actually
> see this happening more and more in C# with data attributes in msft MVC.
> They have a public get/set and then an annotation that indicates things like
> not negative or required, etc etc.  I guess the caveat being that without a
> return value, your only way to really communicate that a value is out of
> bounds is with an exception throw, so your developers need to be comfortable
> with that kind of getter/setter feedback.
>
> My only point in this ramble being that public get/set, while often cargo
> culted in and bad style, can actually still be quite useful in c# and a
> little bit better than a public variable :)
>
>
>
>
> On Wed, Dec 5, 2012 at 10:15 AM, Brian Curtin <brian at python.org> wrote:
>>
>> On Wed, Dec 5, 2012 at 9:38 AM, Malcolm Newsome
>> <malcolm.newsome at gmail.com> wrote:
>> > Additionally, a separate, but perhaps related question is that I have
>> > not
>> > seen public/private classes in Python.  How might this factor into the
>> > whole
>> > accessor scenario?  (Or, am I trying to relate two topics that have
>> > nothing
>> > to do with each other?)
>>
>> There's no notion of private classes, but you could create private
>> attributes on a class using a leading double underscore. I and most
>> others don't recommend doing this.
>>
>> class MyClass:
>>     def __private(self):
>>         ...
>>
>> Python uses "name mangling" to hide the __private method, but nothing
>> is stopping you from unmangling the name and just calling mangled
>> names.
>>
>> Check out this first paragraph for more information:
>> http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Objects
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> http://mail.python.org/mailman/listinfo/chicago
>
>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>



-- 
sheila


More information about the Chicago mailing list