473,851 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessors in Python (getters and setters)

Hello,

What is the Pythonic way of implementing getters and setters. I've
heard
people say the use of accessors is not Pythonic. But why? And what is
the alternative? I refrain from using them because they smell
"Javaish."
But now my code base is expanding and I'm beginning to appreciate the
wisdom behind them. I welcome example code and illustrations.

Regards

Jul 10 '06
112 13899

Ed Jensen wrote:
Diez B. Roggisch <de***@nospam.w eb.dewrote:
Ah, you mean like in JAVA

Java is not an acronym. That is: it's "Java", not "JAVA".
where the compiler prevents you from accessing
private variables, but the runtime allows access to these very variables
via reflection?

Java does not allow access to private members via reflection.
Actually it does.

Jul 21 '06 #111
Ed Jensen schrieb:
Diez B. Roggisch <de***@nospam.w eb.dewrote:
>>Java is not an acronym. That is: it's "Java", not "JAVA".
Now THAT was an important information RIGHT on topic.

It was not meant offensively.
Ok.

>>Java does not allow access to private members via reflection.
For somebody nitpicking on natural language usage to a non-native
speaker, you show an impressive lack of knowledge in the actual subject
discussed.

Again: It was not meant offensively.

Maybe you can try turning the flames down a bit.
I'll try.
>http://www.onjava.com/pub/a/onjava/2...eflection.html

Does that approach work on sealed jars as well? I would imagine any
jars that need any kind of "real" security would be sealed...
Well, lets put it like this: I work for a Java (see, I'm capable of
learning... :)) shop. We deploy pretty large clustered J2EE thingies. In
the last five years working there, I never once produced a sealed jar.

And actually the use-case for a sealed jar is to allow _more_ in an
otherwise restricted environment.

Which puts us to the next question: the sealing itself doesn't do
anything to restrict the code, the SecurityManager does. Which AFAIK is
something hooked into the VM. Now, I'm not on sure grounds here on how
to altere its behaviour, but I'd say if we're talking me working on a
secure application that introduces its own SecurityManager , I'm still
the one in control. I could use your lib, turn off privacy, and fiddle
around.

If things were the other way round, and I'd have to work in a restricted
context, it actually might be that someone restricted private access
(because he owns the VM!). But then - he'd also be able to forbid
threading or file access or all kinds of things that I'd otherwise be
used to work with which will suddenly make my code burst in flames.

And if we are honest: the most problematic cases of abused code arenÄT
the ones of strangers exploiting your code, but instead your fellow
coders at the other department. Which most probably means that they
aren't restrained by security management anyway.

To summarize: it might be possible to jump through a few hoops to
increase the security. But in 99.9% of cases this doesn't happen, as it
would increase complexity by orders of magnitude - for a comparatively
small gain (talking about private declarations. The sandbox-restrictions
of Java for running applets certainly are worth it).

Diez
Jul 21 '06 #112
Diez B. Roggisch <de***@nospam.w eb.dewrote:
Which puts us to the next question: the sealing itself doesn't do
anything to restrict the code, the SecurityManager does. Which AFAIK is
something hooked into the VM. Now, I'm not on sure grounds here on how
to altere its behaviour, but I'd say if we're talking me working on a
secure application that introduces its own SecurityManager , I'm still
the one in control. I could use your lib, turn off privacy, and fiddle
around.

If things were the other way round, and I'd have to work in a restricted
context, it actually might be that someone restricted private access
(because he owns the VM!). But then - he'd also be able to forbid
threading or file access or all kinds of things that I'd otherwise be
used to work with which will suddenly make my code burst in flames.

And if we are honest: the most problematic cases of abused code aren't
the ones of strangers exploiting your code, but instead your fellow
coders at the other department. Which most probably means that they
aren't restrained by security management anyway.

To summarize: it might be possible to jump through a few hoops to
increase the security. But in 99.9% of cases this doesn't happen, as it
would increase complexity by orders of magnitude - for a comparatively
small gain (talking about private declarations. The sandbox-restrictions
of Java for running applets certainly are worth it).
Interesting stuff! And thanks for the link from your earlier post.

Where I work, this little discovery will actually help us stop jumping
through some hoops we've been jumping through to unit test private
methods.

It also gives us more to think about since we had been assuming
private could not be circumvented.

Thanks Diez. :)
Jul 21 '06 #113

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
5798
by: Zap | last post by:
Widespread opinion is that public data members are evil, because if you have to change the way the data is stored in your class you have to break the code accessing it, etc. After reading this (also copied below for easier reference): http://groups.google.it/groups?hl=en&lr=&safe=off&selm=6beiuk%24cje%40netlab.cs.rpi.edu&rnum=95 I don't agree anymore.
21
1931
by: Raj | last post by:
Hi, We just executed a project with Python using TG. The feedback was to use more python like programming rather than C style code executed in Python. The feedback is from a Python purist and for some reasons we cannot solicity his help. So we'd like to do is to scrub through the codebase and identify places where the codebase needs improvement, both from styling as well as design. Is there any website that can provide me with...
0
9747
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10670
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9506
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7906
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5736
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.