|
Re: I think I am Python Challenged
|
Posted: Jun 10, 2005 10:42 AM
|
|
> * list and dictionary data types with literal syntax > [2, 4, 3], {'bob':34.3, 'jerry':12.0}
With varargs support in Java, the list thing is easy to do. With some clever programming constructs you can do
new Map<String,double>().add("bob",34.3).add("jerry",12.0)
which is a bit more verbose, but, I do like to see some explicit indication of what code is doing.
When I designed my RCL language back in 1990, I copied this kind of abreviated construction from the keykit language that Tim Thompson did for his midi language. I had lists as python does, and I used {name=val, name2=val} notation for maps. So, I am familar with the convenience of this...
> * generator expressions / list comprehensions > sum(x*x for x in range(10))
One can define a method called range(int) that returns <List<Integer>> and then use some of the loop abreviations in JDK1.5. But, you will have some extra variables.
What I notice the most about these clever, notational shortcuts is that they are typically used in line, in places that I would be compelled to write a simple method to do the same so that there was a name for the operation that made it more obvious what I wanted to happen.
> def qsort(l): > if len(l) <= 1: > return l > return (qsort([x for x in l[1:] if x < l[0]]) > + l[0:1] > + qsort([x for x in l[1:] if x >= l[0]]))
Collections.sort(...) takes care of sorting things, and one can define the appropriate objects/methods to make these sorted versions to be usable as R-values.
> * generators, ie. the yield keyword. Like in Icon.
I am not familar with generators.
> * relatively easy to use C interface for reusing C > libraries
This is a crutch to me. But, I guess I do less integration at the code level where there is such needs. I do write some JNI code from time to time, and I don't find it to be difficult. In my RCL language, I had a simple mechanism for attaching native code libraries. It's hard to manage the interaction between garbage collected objects and native objects without copying...
> In general, Python helps me mix Functional Programming > techniques with other mostly Object Oriented style to good > effect.
I'm still not finding anything but some brevity. I have no issues with how much I have to type. I am capable of typing with both hands and so brevity of typing is not something that I consider first. I do consider the encapsulation of complex actions where recoding can create bugs as a more compelling issue...
|
|