"Usability, the Soul of Python"

J

Jonathan Hayward

I've posted "Usability, the Soul of Python: An Introduction to the
Python Programming Language Through the Eyes of Usability", at:

http://JonathansCorner.com/python/

The basic suggestion is that much of what works well in Python has
something to do with the usability it offers programmers.

Enjoy.
 
P

Phlip

Jonathan said:
I've posted "Usability, the Soul of Python: An Introduction to the
Python Programming Language Through the Eyes of Usability", at:

   http://JonathansCorner.com/python/

The basic suggestion is that much of what works well in Python has
something to do with the usability it offers programmers.

You mean like...

Order.has_many :line_items

?

Oops, sorry, wrong language. My bad!
 
J

John Nagle

Jonathan said:
I've posted "Usability, the Soul of Python: An Introduction to the
Python Programming Language Through the Eyes of Usability", at:

http://JonathansCorner.com/python/

No, it's just a rather verbose introduction to Python, in dark brown
type on a light brown background. One could write a good paper on this
topic, but this isn't it.

By the same author: "The Case For Uncreative Web Design", which
has no examples.

John Nagle
 
J

Jean-Michel Pichavant

John said:
No, it's just a rather verbose introduction to Python, in dark brown
type on a light brown background. One could write a good paper on this
topic, but this isn't it.


John Nagle
Why is it bad ?

JM
 
M

Malte Dik

Why is it bad ?
Not working code, examples, that are weird to read, and a lot of text :)
 
A

Alf P. Steinbach

* Jean-Michel Pichavant:
Why is it bad ?

Consider


<quote>
From a usability standpoint, the braces go with the lines to print out the
stanza rather than the for statement or the code after, so the following is best:

for(i = 99; i > 0; ++i)
{
printf("%d slabs of spam in my mail!\n", i);
printf("%d slabs of spam,\n", i);
printf("Send one to abuse and Just Hit Delete,\n");
printf("%d slabs of spam in my mail!\n\n", i + 1);
}
</quote>


This is just unsubstantiated opinion, but worse, it makes a tacit assumption
that there is "best" way to do indentation. However, most programmers fall into
that trap, and I've done it myself. In fact, when I worked as a consultant (then
in Andersen Consulting, now Accenture) I used the style above. Petter
Hesselberg, author of "Industrial Strength Windows Programming" (heh, I'm
mentioned) asked my why on Earth I did that, like, nobody does that? It was a
habit I'd picked up in Pascal, from very naïve considerations of parse nesting
levels, a kind of misguided idealism instead of more practical pragmatism, but
since I realized that that was an incredibly weak argument I instead answered by
pointing towards Charles Petzold's code in his "Programming Windows" books. And
amazingly I was allowed to continue using this awkward and impractical style.

I may or may not have been responsible for the similarly impractical compromise
convention of using three spaces per indentation level. At least, in one big
meeting the question about number of spaces was raised by the speaker, and I
replied from the benches, just in jest, "three!". And that was it (perhaps).


Cheers,

- Alf (admitting to earlier mistakes)
 
R

Russ P.

According to Wikipedia, this is called the Whitesmith style:

for(i = 99; i > 0; ++i)
{
printf("%d slabs of spam in my mail!\n", i);
printf("%d slabs of spam,\n", i);
printf("Send one to abuse and Just Hit Delete,\n");
printf("%d slabs of spam in my mail!\n\n", i + 1);
}

I agree with the Mr. Hayward that it is preferable to the more common
K&R style, because the braces do not violate and visually clutter the
logical indentation structure. It looks more like Python. The deeper
the level of nesting, the more this style reduces visual clutter
compared to the conventional style.

A slightly better style, in my opinion, is the Banner style:

for(i = 99; i > 0; ++i) {
// a blank line here is optional
printf("%d slabs of spam in my mail!\n", i);
printf("%d slabs of spam,\n", i);
printf("Send one to abuse and Just Hit Delete,\n");
printf("%d slabs of spam in my mail!\n\n", i + 1);
}
 
R

Robert Fendt

<quote>
From a usability standpoint, the braces go with the lines to print out the
stanza rather than the for statement or the code after, so the following is best:

for(i = 99; i > 0; ++i)
{
printf("%d slabs of spam in my mail!\n", i);
printf("%d slabs of spam,\n", i);
printf("Send one to abuse and Just Hit Delete,\n");
printf("%d slabs of spam in my mail!\n\n", i + 1);
}
</quote>

I liked this one even more:

<quote>
One way of writing the same code in Python would be:

count = 99
while count > 0:
print u'%d slabs of spam in my mail!' % count
print u'%d slabs of spam,' % count
print u'Send one to abuse and Just Hit Delete,'
count += 1
print u'%d slabs of spam in my mail!' % count
print u''

The braces are gone, and with them the holy wars. Whatever brace
styles Python programmers may happen to use in languages with
braces, all the Python code looks the same, and while the major
brace styles illustrated above are a few of many ways the C code
could be laid out, there's only one real way to do it.
</quote>

Has the fact changed that Python does not care about (1) how
many characaters you use for indentation, (1a) you can use tabs
OR spaces, (2) indentation does not have to be consistent across
a module, (3) not even across a file, (4) even in nested blocks
and (5) you can even switch from spaces to tabs and back in the
same file? So much for 'all the Python code looks the same'.

In general I do not really see what qualifies the author for an
article on Python's usability. On the same site one can also
find a lot of things e.g. on intelligent design and creationism,
and the 'The Case For Uncreative Web Design' in which the author
advocates 'uncreative' (in the sense of non-distracting) web
design while at the same time showcasing quite the opposite:
suffice it to say I found most essays rather difficult to read
from a technical point of view, to say nothing about the content.

Regards,
Robert
 
C

Chris Rebert

I liked this one even more:

<quote>
One way of writing the same code in Python would be:

count = 99
while count > 0:
   print u'%d slabs of spam in my mail!' % count
   print u'%d slabs of spam,' % count
   print u'Send one to abuse and Just Hit Delete,'
   count += 1
   print u'%d slabs of spam in my mail!' % count
   print u''

The braces are gone, and with them the holy wars. Whatever brace
styles Python programmers may happen to use in languages with
braces, all the Python code looks the same, and while the major
brace styles illustrated above are a few of many ways the C code
could be laid out, there's only one real way to do it.
</quote>

Has the fact changed that Python does not care about (1) how
many characaters you use for indentation, (1a) you can use tabs
OR spaces, (2) indentation does not have to be consistent across
a module, (3) not even across a file, (4) even in nested blocks
and (5) you can even switch from spaces to tabs and back in the
same file? So much for 'all the Python code looks the same'.

Since we're harping on block delimitation, I'll plug a post I did on
the subject a little while ago:
http://blog.rebertia.com/2010/01/24/of-braces-and-semicolons/

Hopefully it's more thorough than the OP's.

Cheers,
Chris
 
L

Lawrence D'Oliveiro

The braces are gone, and with them the holy wars.

Let me start a new one. I would still put in some kind of explicit indicator
of the end of the grouping construct:

count = 99
while count > 0:
print u'%d slabs of spam in my mail!' % count
print u'%d slabs of spam,' % count
print u'Send one to abuse and Just Hit Delete,'
count += 1
print u'%d slabs of spam in my mail!' % count
print u''
#end while
 
L

Lawrence D'Oliveiro

Alf P. Steinbach said:
This is just unsubstantiated opinion, but worse, it makes a tacit
assumption that there is "best" way to do indentation. However, most
programmers fall into that trap, and I've done it myself.

Having used so many different languages over the years, I have settled on a
reasonably common set of indentation conventions that work across most of
them.

The only one that currently annoys me is JavaScript, because its semicolons-
are-optional rule means that certain ways I write statements continued
across multiple lines are interpreted as prematurely completing the
statement.

In revenge for that, I refuse to put optional semicolons in my JavaScript
code altogether.
I may or may not have been responsible for the similarly impractical
compromise convention of using three spaces per indentation level. At
least, in one big meeting the question about number of spaces was raised
by the speaker, and I replied from the benches, just in jest, "three!".
And that was it (perhaps).

I use four. Why four? Because it’s divisible by two. Because I use the half-
step (two columns) for lines containing nothing but bracketing symbols:

for (i = 99; i > 0; --i)
{
printf("%d slabs of spam in my mail!\n", i);
printf("%d slabs of spam,\n", i);
printf("Send one to abuse and Just Hit Delete,\n");
printf("%d slabs of spam in my mail!\n\n", i - 1);
} /*for*/

for i := 99 downto 1 do
begin
writeln(i, " slabs of spam in my mail!");
writeln(i, " slabs of spam,");
writeln("Send one to abuse and Just Hit Delete,");
writeln(i - 1, " slabs of spam in my mail!\n\n")
end {for}

Actually this looks like another opportunity for a loop-with-exit-in-the-
middle:

for (i = 99;;)
{
printf("%d slabs of spam in my mail!\n", i);
printf("%d slabs of spam,\n", i);
printf("Send one to abuse and Just Hit Delete,\n");
--i;
if (i == 0)
break;
printf("%d slabs of spam in my mail!\n\n", i);
} /*for*/
 
S

Steve Holden

Jonathan said:
I've posted "Usability, the Soul of Python: An Introduction to the
Python Programming Language Through the Eyes of Usability", at:

http://JonathansCorner.com/python/

The basic suggestion is that much of what works well in Python has
something to do with the usability it offers programmers.

Enjoy.
Now try another one called "Brevity, the Soul of Technical Writing: An
Introduction to Making Yourself Understood Through the Eyes of Readability".

What I managed to read seemed to be making worthwhile points, but I felt
a bit like I was wading through a steaming pile of irrelevant verbiage
that actually made it more difficult to extract the useful nuggets.

Bravo for undertaking this task, but I do feel the treatment needs work
from a good copy editor.

Of course you have to take into account my allergy to folksy metaphors
and meandering discourse. Had I chosen your style I might instead have
written the criticism above as:

"""
I would like to begin my critique of this paper with a feature that many
competent technical writers completely fail to appreciate: why brevity
is desirable in technical writing.

Technical writing is not, of course, the only form of writing that there
is. People have been writing ever since the first caveman decided he
could leave marks on the wall of a cave to indicate that food could be
had in the vicinity. The basic concept of brevity is that you should
not, as a writer, use superfluous words because if you do then the
reader will always be in doubt about which parts of your discourse are
meaningful and which are merely decoration.

....
"""

And so on. As I say, this may be criticism dictated by my personal
taste, but I feel you could condense the presentation considerably to
good effect. Sorry if this offends. It's meant to help.

regards
Steve
 
J

John Nagle

Alf said:
* Jean-Michel Pichavant:

Consider


<quote>
From a usability standpoint, the braces go with the lines to print out
the stanza rather than the for statement or the code after, so the
following is best:

The last time I ran a C++ project, I just had everyone run their
code through Artistic Style ("http://astyle.sourceforge.net") with
"--style=ansi". No more inconsistencies.

John Nagle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top