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

June 2025

S M T W T F S
1234567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 1st, 2025 01:26 am
Powered by Dreamwidth Studios