"Usability, the Soul of Python"

Discussion in 'Python' started by Jonathan Hayward, Mar 29, 2010.

  1. 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.

    --
    Jonathan Hayward,
    An Orthodox Christian author: theology, literature, et cetera.
    My award-winning collection is available for free reading online:
    I invite you to visit my main site at http://JonathansCorner.com/
    Jonathan Hayward, Mar 29, 2010
    #1
    1. Advertising

  2. Jonathan Hayward

    Phlip Guest

    Jonathan Hayward wrote:

    > 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!

    --
    Phlip
    http://zeekland.zeroplayer.com/
    Phlip, Mar 29, 2010
    #2
    1. Advertising

  3. Jonathan Hayward

    John Nagle Guest

    Jonathan Hayward wrote:
    > 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
    John Nagle, Mar 30, 2010
    #3
  4. John Nagle wrote:
    > Jonathan Hayward wrote:
    >> 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.
    >
    >
    > John Nagle

    Why is it bad ?

    JM
    Jean-Michel Pichavant, Mar 30, 2010
    #4
  5. Jonathan Hayward

    Malte Dik Guest

    > Why is it bad ?
    >


    Not working code, examples, that are weird to read, and a lot of text :)
    Malte Dik, Mar 30, 2010
    #5
  6. * Jean-Michel Pichavant:
    > John Nagle wrote:
    >> Jonathan Hayward wrote:
    >>> 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.
    >>
    >>
    >> John Nagle

    > 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)
    Alf P. Steinbach, Mar 30, 2010
    #6
  7. Jonathan Hayward

    Russ P. Guest

    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);
    }


    On Mar 30, 4:40 am, "Alf P. Steinbach" <> wrote:
    > * Jean-Michel Pichavant:
    >
    > > John Nagle wrote:
    > >> Jonathan Hayward wrote:
    > >>> 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.

    >
    > >>                 John Nagle

    > > 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)
    Russ P., Mar 30, 2010
    #7
  8. Jonathan Hayward

    Robert Fendt Guest

    And thus spake "Alf P. Steinbach" <>
    Tue, 30 Mar 2010 13:40:22 +0200:

    > <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
    Robert Fendt, Mar 30, 2010
    #8
  9. Jonathan Hayward

    Chris Rebert Guest

    On Tue, Mar 30, 2010 at 3:32 PM, Robert Fendt <> wrote:
    > And thus spake "Alf P. Steinbach" <>
    > Tue, 30 Mar 2010 13:40:22 +0200:
    >> <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'.


    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
    Chris Rebert, Mar 31, 2010
    #9
  10. In message <>, Robert Fendt wrote:

    > 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
    Lawrence D'Oliveiro, Mar 31, 2010
    #10
  11. In message <hosnrh$6na$-september.org>, Alf P. Steinbach
    wrote:

    > 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*/
    Lawrence D'Oliveiro, Mar 31, 2010
    #11
  12. Jonathan Hayward

    Steve Holden Guest

    Jonathan Hayward wrote:
    > 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
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
    Holden Web LLC http://www.holdenweb.com/
    UPCOMING EVENTS: http://holdenweb.eventbrite.com/
    Steve Holden, Mar 31, 2010
    #12
  13. Jonathan Hayward

    John Nagle Guest

    Alf P. Steinbach wrote:
    > * Jean-Michel Pichavant:
    >> John Nagle wrote:
    >>> Jonathan Hayward wrote:
    >>>> 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.
    >>>
    >>>
    >>> John Nagle

    >> 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:


    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
    John Nagle, Mar 31, 2010
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page