Allowing Arbitrary Indentation in Python

Chris Mellon arkanes at gmail.com
Wed Dec 19 18:50:59 EST 2007


On Dec 19, 2007 4:05 PM, Gary <gfixler at gmail.com> wrote:

<snipped a lot of stuff I'm not replying to>>

>
> Chris Mellon writes:
> """It's interesting that the solutions "move away from the terrible
> abomination of a GUI toolkit" and "write Python wrappers that don't
> cause actual physical pain" never occur to him."""
>
> Oh, but they have, and almost immediately. You're assuming, perhaps,
> however, that I have the chops for that at such an early stage in my
> new Python life, or that I'm excited about the prospect of jumping
> right into a new library, only to have to virtually start over,
> wrapping some 15-20 layouts, and maybe 50+ controls in wrappers. In
> either case, you would assume wrong.
>

I overestimated your Python experience when I read the first (last?
most recent) post. After I sent the email I went back through your LJ
post where your level of experience with Python is made much more
plain. I don't mean this in a bad way - you're a beginner and that's
fine - but you don't have a grasp on Pythons fundamentals and thats
why so many things about it seem strange to you. All of the things in
your first post have reasons why they are that way, and there is
internal consistency in all of them. You have been done a disservice
by whoever wrote the Maya python bindings, as far as using this tool
to improve your knowledge and understanding of Python goes.

> ...and continues:
> "He's got a lot of years invested in this layout so I understand the
> hesitance to move away from it..."
>
> Yes! I have lots of years invested! But, no! I'm not hesitant! I'm
> ready! Let's go! I'm totally prepped to be done with MEL :)
>
> ...and furthermore states:
> "...but seriously - this is a really terrible way to do GUI layout."
>
> Oh, c'mon, no it's not. It's nearly the same thing as HTML, as I said.
> Are you going to seriously denounce more than a decade of that, and
> tens of thousands, if not millions of people using it in every
> language, in countless implementations the world over?

Yes, HTML is a very bad way of doing GUI layout. It's a textual markup
language, not a layout format. HTML per se has almost no layout
capabilities at all, and CSS while much better is still quite limited.
This is the internet, we don't shy away from scoffing at millions of
misguided souls here ;)

>I'm not saying
> it can't be better, but *terrible?* Yes, I'm being declarative of my
> layouts right inside my code, which might be weird, but that's only
> because I'm adaptable, and it was the best way to do it in MEL, which
> has been my only option in Maya since the mid 90s. It's been solid for
> me, and honestly, once you're past a bit of the strangeness of it, is
> very straightforward, and simple. It's not the best, but it's not
> *terrible.*
>

It's very much like writing HTML using only the DOM apis, and not
HTMLs syntatic markup, which *is* terrible.
The structures you're defining are quite reasonable, it's the API
that's bad. I tend to group stuff into categories of "good",
"adequate", and "terrible". This, from the API alone, falls squarely
into "terrible" for me.

> ...and keeps on rolling with:
> "All those setParent calls! *shiver*."
>
> Alright, I'll give you those :) I hated them for the first year.
> Still, they're basically just HTML close tags, with the added power
> that you can replace '..' with a specific layout to jump into that.
> You can also think of them as close braces in your choice of C-like
> languages. Don't be such a scaredy-cat.
>

They aren't a close tag, they're state management, and the fact that
you have to litter your code with them is a real flaw in the GUI
toolkit. You'll note that my language of choice is Python, a language
which explicitly *excluded* the need for an "end block" marker. I'm
pretty sure that there's a way to write Python that looks like the UI,
but it's not using the API you have.

> ...will he ever stop? I don't know:
> "I notice he retreats to the "well, *I* can read it, so it's not
> unreadable" defense..."
>
> I can read it, because it's a natural style, as seen all over the
> place in HTML, XML, many UI layout tools, folder trees, complicated
> task lists, book outlines, and the list goes on. Seriously, what is
> with you people?
>

I'm not so much claiming it's unreasonable as dismissing your argument
why it is. I have to re-iterate: It's *not* markup. It's imperative
code full of explicit state management that you write in a way that
*llooks* like markup, which is a good call on your part because theres
a reason almost everyone uses declarative languages for UI layout
these days.

> ...and is almost done with:
> "I know people who can read x86 assembly directly from hex dumps"
>
> I rather enjoyed coding in x86, and once created a SWF file (compiled
> Flash binary), by hand, entirely at the *bit* (not byte) level. It
> took hours to get only several hundred bytes, but it worked! This, I
> realize, is not a good argument in my favor.
>
> ...and FINALLY finishes:
> "without really addressing the merits of a particular case."
>
> But I have, over and over. It's very readable. It's a hierarchy of
> layouts and controls, expressed in a hierarchy of indented blocks that
> match up 1:1 with each other.
>

This is where the Ruby and Lisp people will come in and gloat about
DSLs, because that's what you've been doing - you've invented a very
simple sort of DSL and embedded in your host language, which happens
to syntatically support the DSL you've chosen. You can do the same
thing in Python, but you have different syntax constraints to conform
to.

> What I've noticed is that no one in here as yet has backed themselves
> up. Let me pick one, without creating an exhaustive list:
>
> Jonathan Gardener promised this:
> "...let me try to explain why you'd never want to indent code that
> way, let alone write code that way."
>
> But then never actually explained it.
>
> He states:
> "...it's best to create functions and then nest the functions."
>
> But never says why it's best - just that it is. None of you so far
> have said why your thoughts have any merit. So far, it's just all been
> declarative statements that your ways are better, that my ways are
> "terrible," and all with not one substantiation of either sentiment.
> Weren't any of you folks in debate club? I wasn't, but I think I'm
> winning :)
>

I'm not him, but I'll say why *I* might have said this. What you're
doing with your nesting is creating and managing a stack of states. It
just so happens that you have a very powerful programming language all
ready to do this for you, because that's exactly what it does when you
make nested function calls. So rather than writing imperative code
that tries to look declarative, you can just write imperative code (or
you could use/invent a real declarative language for declaring these
GUIs, and load the UI from that. This is what GUI builders like Glade
do). Remember that you are *not* writing markup. You are writing code
in a real programming language and you have all the power of that
language at your disposal for breaking code down into small, easily
handled pieces. I too have written UIs that scale to hundreds of
individual GUI elements (although not neccesarily controls, because a
UI screen that cluttered is hard ot use) and the way to manage the
complexity is the same way you manage any other programming complexity
- by breaking it into pieces which you gradually compose together.



More information about the Python-list mailing list