[Tutor] simplifications : are they good ?

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Thu, 6 Dec 2001 19:03:20 -0800 (PST)


On Thu, 6 Dec 2001, Jean Montambeault wrote:

>     Of course I'm a beginner, but when I see something like :
>=20
> Label(fen1, text =3D 'Premier champ :').grid(sticky =3DE)
> Label(fen1, text =3D 'Second :').grid(sticky =3DE)
> Label(fen1, text =3D 'Troisi=E8me :').grid(sticky =3DE)
> entr1 =3D Entry(fen1).grid(row =3D0, column =3D1)
> entr2 =3D Entry(fen1).grid(row =3D1, column =3D1)
> entr3 =3D Entry(fen1).grid(row =3D2, column =3D1)
>=20
>     instead of the full form I'm sceptic. Is the omission of a viariable
> affectation going to speedup the program ? Same question for grouping

Hi Jean,

Good question!  I don't believe it's a matter of speedup, but instead of
convenience.  Sometimes it's just easier to say:

###
>>> 3 * 4
12
###

instead of:

###
>>> x =3D 3
>>> y =3D 4
>>> x * y
12
###



In the same vein, the author of:

> Label(fen1, text =3D 'Premier champ :').grid(sticky =3DE)
> Label(fen1, text =3D 'Second :').grid(sticky =3DE)
> Label(fen1, text =3D 'Troisi=E8me :').grid(sticky =3DE)

probably felt that giving a name to each Label was unnecessarily
convoluted, when the author wasn't planning to do anything more with the
Label.  This is often the case of Labels, because the user doesn't really
interact with labels after they're placed in a GUI.

The author could have written:

##
l1 =3D Label(fen1, text=3D'Premier champ :')
l2 =3D Label(fen1, text=3D'Second :')
l3 =3D Label(fen1, text =3D 'Troisi=E8me :')
l1.grid(sticky =3D E)
l2.grid(sticky =3D E)
l3.grid(sticky =3D E)
###

but as far as Python is concerned, there's negligible difference in the
efficiency of this process.


Hope this helps!