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).

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

The fourth "Forth" style is stack-based. It's the same one PostScript uses. For instance, 3 4 5 + * . will print out 27 (the . is the print command). Its advantage is that it's very simple and easy to implement.

But functional is my preference. If you're really interested in the functional style, you should check out Haskell (http://haskell.org/).

Date: 2003-07-22 05:27 pm (UTC)
lovingboth: (Default)
From: [personal profile] lovingboth
Hmm, although it is stack based, I'd say its style is factored simplicity.

When it costs almost nothing to do a function call, you can factor away with no loss of runtime performance but all the benefits of ease of interactive testing.

Jump To Subroutine!

Date: 2003-07-23 04:16 am (UTC)
ext_9394: (Default)
From: [identity profile] antimony.livejournal.com
(uh, hi Elf. I'm a random fan of the Journal Entries who couldn't resist commenting on Forth.)

The Forth paradigm includes a hugely minimalistic style: originally, you were limited to a 40x80 character block for your main program, and it was considered the ultimate in good form to have your subroutines be one-liners. The handful of us who learned Forth as our first language tend to bemuse the rest of the programming world.

It's also all reverse-polish, stack-based, parentheses are used to denote comments, and all variable names are just literals pointing to memory. And it can be interpreted, which was evidently rare back in the day. You can put entire Forth systems on little processors and develop on them. (That's what my father used to do for a living, which is why I was taught Forth at the tender age of 11.)

Re: Jump To Subroutine!

Date: 2003-07-23 05:36 pm (UTC)
lovingboth: (Default)
From: [personal profile] lovingboth
Well, 16 lines by 64 characters is the traditional size of 'block' as 16x64 = 1k and you can treat a disk as a series of 1k blocks very simply. And I've some quibbles with some of the rest :)

If you want to see what the inventor's done with it, see http://www.colorforth.com/

I particularly like the IDE disk driver in five lines of code.

code examples

Date: 2003-07-22 04:13 pm (UTC)
From: [identity profile] popefelix.livejournal.com
do you have bits of your code available for people to look at? I try to be concise in my coding, but I have a feeling that my code still suffers from a bit of bloat.

Congratulations!!

Date: 2003-07-22 04:17 pm (UTC)
From: [identity profile] ouranophobe.livejournal.com
Sounds a right sexy hack! A nice realisation, isn't it? :)

Date: 2003-07-22 07:48 pm (UTC)
From: [identity profile] johno.livejournal.com
I'm slowly coming to the point where I accept that about myself too.

I'm damn good at my job. I have a innate understanding of how the system works. I can design and implement very complex system changes. I can even articulate how it works and what the changes mean to my co-works and bosses.

Thanks for crystallizing that realization for me.




From: [identity profile] wolfwings.livejournal.com
...well at least this one does. It's mostly for some random MU* servers but Forth-like languages (without the silly 'pages' of the older forth implementation) are still going quite strong, but I very definately agree that Forth is a language with it's own programming style that nothing else can, or should, duplicate.

And it's a style I find remarkably intuitive and easy to program in when I'm just banging out code to test an idea before building it again more properly in some other language, as if I get something wrong it breaks where I got it wrong, no sooner, no later, so I can find flaws in my ideas faster.

Date: 2003-07-23 03:35 pm (UTC)
From: [identity profile] j5nn5r.livejournal.com
This is why, when I found out we were both competing for the same job at your company, I had no doubt you were:
1) more qualified
2) should get the job
3) I'd be happy about it

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. 9th, 2025 04:20 am
Powered by Dreamwidth Studios