Subject: [UFL-dev] Variable name style choice

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Wed, 2 Apr 2008 12:27:45 +0200

In Python, variables are made private or protected in an "informal
way" by prefixing their names with __ or _. Some places I've used
self._foo instead of self.foo for variables which the end-user (person
inputting a form) shouldn't touch, do you agree with this? Most of
these are variables the form compiler developers will be dealing with.
I haven't been completely consistent, so I just want green light
before I change these one way or the other.

--
Martin

---

From: Kent-Andre Mardal <[email-masked]>
Date: Wed, 02 Apr 2008 12:47:08 +0200

Agree

ons, 02.04.2008 kl. 12.27 +0200, skrev Martin Sandve Alnæs:
> _______________________________________________
> UFL-dev mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/ufl-dev

---

From: Anders Logg <[email-masked]>
Date: Wed, 2 Apr 2008 12:58:18 +0200

> before I change these one way or the other.

Agree, but shouldn't it be two underscores?

-- 
Anders

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Wed, 2 Apr 2008 13:28:15 +0200

> Agree, but shouldn't it be two underscores?

Two underscores makes it private, which is inaccessible(*) by anyone
outside the class, I don't think we have any such variables.

Try running this code:

class B:
    def __init__(self):
        self.a = 1
        self._b = 2
        self.__c = 3

b = B()

print b.a
print b._b
print b.__c

--
Martin

---

From: Pearu Peterson <[email-masked]>
Date: Wed, 02 Apr 2008 13:29:17 +0200

> Agree, but shouldn't it be two underscores?

Two underscores are reserved for Python private names and there
is some magic effects with class attributes that have two underscores
as prefix (this is actually the way to get some protection to attribute 
values). Authors of Python packages should use one underscore for 
private names, in general.

Pearu

---

From: Anders Logg <[email-masked]>
Date: Wed, 2 Apr 2008 14:20:14 +0200

> private names, in general.

ok!

-- 
Anders