Date: 2003-07-22 04:23 pm (UTC)
One of the things I like about python is the way you can hybridize objects and functional programming. In my example, I had a List of Objects, each of which represented a remote user and methods for determining his or her authentication. I wanted only the names of those users who had SNMP authentication. Here's the code:

snmpUserNames = map( lambda a: a.getName(), filter( lambda a: a.getType() == 'SNMP', lUSers) )

The map and filter keywords are functional: they allow one to perform either named or anonymous functions (lambda allows the generation of anonymous functions with very locally scoped variables-- no contamination of the surrounding variable namespace occurs) on a collection (lUsers) of objects. This is a very trivial example, but it shows one of the steps in going from raw data to highly refined and precise output: for every user in lUsers, generate a list that has SNMP access, and then from that list generate a list of usernames. Using traditional 'for' loops and 'if' statments, this could get long, ugly, and error-prone.

Python is simply easier to learn than Perl, and by definition that makes it easier to write. A Perl programmer, a good one, can write miraculous filters in seconds-- but large programs in Perl are impossible to read.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

elfs: (Default)
Elf Sternberg

May 2025

S M T W T F S
    123
45678910
111213141516 17
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 12th, 2025 02:22 pm
Powered by Dreamwidth Studios