Favorite non-python language trick?
Steve Jorgensen
nospam at nospam.nospam
Mon Jun 27 11:58:46 EDT 2005
On 24 Jun 2005 19:09:05 +0400, Sergei Organov <osv at javad.ru> wrote:
>Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
>
>> On Fri, 24 Jun 2005 00:55:38 -0600, Joseph Garvin wrote:
>>
>> > I'm curious -- what is everyone's favorite trick from a non-python
>> > language? And -- why isn't it in Python?
>>
>> Long ago, I used to dabble in Forth. You could say, the entire Forth
>> language was a trick :-) It was interesting to be able to define your own
>> compiler commands, loop constructs and so forth.
>>
>> One of the things I liked in Pascal was the "with" keyword. You could
>> write something like this:
>>
>> with colour do begin
>> red := 0; blue := 255; green := 0;
>> end;
>>
>> instead of:
>>
>> colour.red := 0; colour.blue := 255; colour.green := 0;
>>
>> Okay, so maybe it is more of a feature than a trick, but I miss it and it
>> would be nice to have in Python.
>
>... that quickly becomes quite messy:
- When abused -
>with A do begin
> .....
> with B do begin
> .....
> with C do begin
> x := y;
> end;
> end;
>end;
Like many features that can be helpful when used well, and harmful when used
poorly, it's not a simple question whether it should be in any given language.
It also makes sense to consider whether other features already in the language
can fill the same need (though I don't know Python well enough to address that
yet). Even though I like "With" in VB and use it often, I always consider its
use a warning that perhaps that code should be factored into the class
somehow.
More information about the Python-list
mailing list