Lambda the Ultimate

inactiveTopic Guide to Python introspection
started 12/16/2002; 8:46:41 AM - last post 12/30/2002; 5:32:17 PM
Ehud Lamm - Guide to Python introspection  blueArrow
12/16/2002; 8:46:41 AM (reads: 2668, responses: 10)
Guide to Python introspection
(via Daily Python-URL)

Python, a dynamic, object-oriented programming language, provides tremendous introspection support. This article showcases many of its capabilities, from the most basic forms of help to the more advanced forms of inquisition.

A nice tutorial on the various introspection facilities in Python.

Dynamic interpreted languages can easily support introspection. Until a few years ago it was usually considered bad style to use introspection or similar facilities (e.g., RTTI, tag fields in records etc.). It seems like the climate is changing.


Posted to Python by Ehud Lamm on 12/16/02; 8:48:59 AM

rev - Re: Guide to Python introspection  blueArrow
12/16/2002; 7:18:36 PM (reads: 1218, responses: 4)
I've not read this yet, but I'm looking forward to it. I do the majority of my programming Smalltalk, but a while back I was looking for information on the introspective and reflective abilities of perl and python, which are the two most popular languages in their class with a wealth of libraries. I was looking into it because I wanted to create an IDE with some of the features of a Smalltalk development system- anyone who has done more than a cursory look at Smalltalk knows that the environment is a big strength of Smalltalk and that once you've had the ability to use one, it's really hard to sink back to the level of just editing files.

To research, I looked on the web at what was available, but I also checked their respective IRC channels on irc.freenode.net. The Python community there was really unresponsive, and what their responses could even be considered ignorant and insulting. I was told that if Python couldn't do it, it wasn't worth having. They said that reflection and introspecion weren't needed because Python was open source and the source to any classes you were working with would always be available (!!). That is, you could just parse the textfile rather than using any of the dynamic features. I knew Python had some of the features I was asking about, but I didn't know what they were specifically. Unfortunately, I ended up getting mocked for wanting anything Smalltalk-like in Python and left the channel in disgust.

In #perl on the other hand, people tried to be helpful. When individuals didn't know about a certain feature, they admitted it or tried to find some resource (email address, url) which I could look for some guidance. Information and pointers from #perl led to the creation of a Perl-GTK+ pseuo-class browser. It doesn't do source (yet!), but at the very least it lets you browse APIs, which is one of the biggest things I like about a Smalltalk browser.

I know that the IRC channels on just freenode aren't the entire language community, but I still thought it was a bit weird. Over those couple of days, I went from a very strong Python/anti-perl bias to just the opposite. (Python was my language of choice before finding Smalltalk)

No, this post wasn't about introspection per se, but another very important aspect of languages, community. Have people found a similar situation elsewhere in the Python community, or is it just a quirk the kinds of people that were on the #python IRC channel? The curiousity I have hasn't driven me to doing anything that's more work- like joining a Python mailinsg list, but I sincerely hope that the Python community isn't composed so much of that horrible combination of new-to-programming and arrogant.

Adewale Oshineye - Re: Guide to Python introspection  blueArrow
12/17/2002; 1:10:51 AM (reads: 1226, responses: 0)
It sounds like you had a rather unpleasant experience.

When it comes to that kind of detailed information about Python your best bet would be to ask on comp.lang.python. Most of the core Python developers at least lurk on there and I've always found the discussions there to be fairly civilized. Or if you wanted some place more Smalltalk-friendly then asking on a relevant page on the C2 wiki might be a good idea.

Chris Clearwater - Wrong IRC network!  blueArrow
12/17/2002; 2:06:07 AM (reads: 1225, responses: 1)
Seems like they didn't really know what they were talking about, check out irc.openprojects.net #python. There you can find all kinds of people doing somewhat cool (evil ;)) things with python's introspective capabilities.

Ehud Lamm - Re: Guide to Python introspection  blueArrow
12/17/2002; 3:43:19 AM (reads: 1236, responses: 0)
Community is important.

The people I talked to from the Python community were friendly, and fairly well educated.

re IDEs: check PyCrust, IPython and pyrepl. They seem to go in the direction you are interested in.

water - Re: Wrong IRC network!  blueArrow
12/17/2002; 8:12:52 AM (reads: 1220, responses: 0)
irc.openprojects.net IS irc.freenode.net

Glyph Lefkowitz - Re: Guide to Python introspection  blueArrow
12/28/2002; 10:51:02 AM (reads: 1001, responses: 2)
First impressions are weird.

It seems like a small but vocal group of people tend to find the Python IRC community on Freenode unfriendly. As Mr. Clearwater's comment implies, most people who visit don't feel that way.

I'm going to hazard a guess that rev lead in to his questioning with some unfortunate breach of IRC etiquette and made a poor first impression, which lead to some rudeness. I suggest lurking for a while, reading more of what the regulars have to say without participating yourself, and reading the channel FAQ.

rev, possibly you are also misinterpreting agreement as unfriendliness based on a lack of shared context. Guido's semi-official position on facilities like this is that "python isn't smalltalk, deal with it". I know that this is a sore point for many #python regulars, myself included, since it would be nice if it were smalltalk, actually.

Isaac Gouy - Re: Guide to Python introspection  blueArrow
12/28/2002; 12:57:11 PM (reads: 1057, responses: 1)
it would be nice if it were smalltalk
Why?
What is it about Smalltalk that makes you use Python instead? What is it about Python that makes you wish it were more like Smalltalk?

I'm becoming infernally curious ;-)

Adewale Oshineye - Re: Guide to Python introspection  blueArrow
12/29/2002; 5:19:51 PM (reads: 1093, responses: 0)
You could take a look at something on the XTC wiki asking why does Python have generators when blocks can do the job?.

With regard to your question I'll bet that the reason people who prefer Smalltalk are using Python is that it's easier to get hold of good free Python libraries.

Glyph Lefkowitz - Re: Guide to Python introspection  blueArrow
12/30/2002; 3:56:48 AM (reads: 1023, responses: 0)
Python has one thing going for it that Smalltalk does not: modules.

As jwz said of Java, "I have to admit right off that, after that, all else is gravy. That one point makes me able to forgive just about anything else, no matter how egregious. Given this one point, everything else in this document fades nearly to insignificance."

Smalltalk systems, though there are many moves away from this in progress right now, are each one huge monolithic be-the-world environment with no modularity model, poor support for collaborative development and a very limited culture of software distribution. In general, everything is spot-welded together so you can't pry the server infrastructure loose from the GUI, or the wigdets loose from the full-screen windowing system.

This makes it unusable for a wide array of applications.

Python has enough of the really cool things about Smalltalk to still be fun, even if it's occasionally annoying that you have to deal with obscure consequences of attribute access overriding or funky syntax or inconvenient scope rules.

Also, python works with emacs, and smalltalk tends not to. GST is a notable exception to many of these problems, but in my experience it's got plenty of its own. (It's incredibly buggy, for one.)

Modularity is also a small part of the greater concession to the fact that not everything is written in Python, and it integrates VERY well into the traditional UNIX/C world using extension modules.

But...

There are a few small reasons that one wishes Python were Smalltalk:

Smalltalk generally has a better and more advanced virtual machine layout: it's almost always at least an order of magnitude faster.

The smalltalk garbage collector is the mother of all garbage collectors, both in terms of functionality and performance. There is no way that Python can ever gain parity with it given the level of native integration Python currently provides.

Smalltalk has fewer primitive operations. Only one, really: send a message. A few other ops bottom out in primitives but it's hard to see them as an average applications programmer. Smaller numbers of primitives also means that things like capability security are easier to implement.

Smalltalk includes the notion of a "block", which is very powerful, and has often been extended to be a full lexical closure.

Smalltalk's method syntax is just ... cute :-). It maps very naturally into english and there's no ambiguity. A method name specifies an exact number of arguments.

Smalltalk has more robust introspection.

Smalltalk's development environment is just ORGASMIC. There is no other word to describe the experience of debugging an ST application. Give it a try sometime: I can't even explain why it's so great, since I'm not really a Smalltalk expert.

This is all my opinion, really, and I'm a python expert who has only dabbled with smalltalk, so I tend to know a lot more about Python's flaws :-). There may be other reasons why people don't use Smalltalk.

Isaac Gouy - Re: Guide to Python introspection  blueArrow
12/30/2002; 5:32:17 PM (reads: 1004, responses: 0)
After 20 years, Smalltalk implementations are so various that generalizations often fail, never-the-less:

monolithic ST & modules
Modules (separate compilation units) are not necessarily the solution.
Java uses separate compilation units, and still suffers from bloated code.
The slides from Firewall hint at other approaches.

support for collaborative development
OTIs Envy code-repository provided excellent support for collaborative development with VW ST and IBM VAST.

very limited culture of software distribution
???

This makes it unusable for a wide array of applications
From someone "who has only dabbled with smalltalk" that's a sweeping generalization ;-)
Actually ST has been used successfully for a wide array of applications, some were mentioned in this LtU discussion.