elfs: (Default)
[personal profile] elfs
Yesterday, while at work, I had a mission. It was a simple one: hook up a query to a database, show the results of the query-- a list of names-- to the user, and let the user pick one.

It took me about 45 minutes to hack a basic system. I even did it using a new chunk of technology (the Python iterator system, new in 2.2) that saved me a whole lot of memory (which was useful, since I could now burn that memory for caching results of associate queries, which made follow-on main queries faster... it's all very geeky). Since it's a web application, the back end was python, the front end HTML and Javascript, with a few style sheets tossed in for good measure.

I also did it using a heavily functional style (there are four basic programming paradigms: procedural, objective, functional, and the one Forth uses that nobody really understands...). Python lets you write in all of the above styles (except the Forth one). One of the programmers who took over my job while I was gone on vacation looked at the code and said, "I would never have gotten there that way."

I asked if there was something wrong with my code. He said there wasn't, and that was his point: there wasn't a wasted line or an unneeded side effect anywhere in the code. I'd gone from raw data to correct output in a very readable way without doing anything extraneous that could introduce errors.

And then I had this realization: This is what they pay me for. The years of programming experience and the depth of knowledge about HTML, CSS, Javascript, Python, C, C++, and so on are important, but it's the ability to apply those quickly with precision and concision that keeps me employed. It's the ability to understand that the task really is about data-in, data-out, while filtering the garbage, and to know exactly what tool will do the best about filtering the garbage and arranging the rest for the human eye.

It was kind of neat, after a long bout of self-doubt, to realize what it is about my progamming abilities, particularly, that makes me economically valuable to other people.

Date: 2003-07-22 04:11 pm (UTC)
ext_3294: Tux (Default)
From: [identity profile] technoshaman.livejournal.com
Coolness. Functional, huh? I always did think this object abstraction introduced a lot of glop that didn't necessarily have to be there...

I gotta learn Python some time. There's a lot of blood on the floor over whether Perl is easier to write (thanks to syntactic sugar making it easier for the editor to keep track of where the hell it is you are), but Python is definitely easier to read.... Perl reminds me of APL...

Date: 2003-07-22 04:23 pm (UTC)
From: [identity profile] elfs.livejournal.com
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.

Date: 2003-07-22 06:14 pm (UTC)
From: [identity profile] ashley-y.livejournal.com

Btw, in Haskell this would be

snmpUserNames = map getName (filter (\a -> getType a == "SNMP") lUSers)

...assuming getName and getType were pure functional rather than in some monad (monads are how Haskell does imperative code in a purely functional way).

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 Jun. 28th, 2025 10:04 pm
Powered by Dreamwidth Studios