Flutterby™! : Low level constructs

Next unread comment / Catchup all unread comments User Account Info | Logout | XML/Pilot/etc versions | Long version (with comments) | Weblog archives | Site Map | | Browse Topics

Low level constructs

2007-06-13 23:16:26.356328+00 by Dan Lyke 4 comments

Sean Conner has some commentary on someone else's commentary on The Mythical Man Month in which he questions:

But “while loops” and “if blocks” are low level details? I don't necessarily think so.

Okay, I'll bite. The original commentary says "...for and while loops..." (emphasis mine), and I'll go out on a limb here and say that "for" loops are almost always a low level detail. Loops are a way of saying "for each item apply this operation" or "find" or something else. The classic C idiom for (i = 0; i < n; ++i) is a way of saying "generate the set of integers from 0 through (n-1)", and different languages may have ways of expressing that that differently. For instance, you might say 0..(n-1) in Perl[Wiki], depending on what you wanted to do with that resulting set, and if your language is smart enough both the programmer and the language win, because the programmer gets to express the thought more appropriately to the domain, and the language gets to decide how best to implement the thought.

[ related topics: Perl Software Engineering ]

comments in ascending chronological order (reverse):

#Comment Re: made: 2007-06-14 01:45:37.675402+00 by: ebradway

Rosenberg's comments are golden. Conner's are lead.

I suspect ratio if of computer users to computer programmers today is orders of magnitude greater than 1975. But what do those users do nowadays?

If you look at the realm of "power users", you might find something happening that could be called "programming". Building a Web 2.0 site out of CMS, RSS and XML without typing "while" or "for" once! Building houses and neigborhoods in The Sims without even touching the keyboard!

Keystroke Macros used to be the domain of the power user. They could string together incredible series of operations without ever messing with the low level detail of loops or even if...then blocks.

So yeah, any construct common to general-purpose programming languages are inherently low-level. That's by design. And in 1975 it was nigh impossible to even imagine a day when things could be done any other way. Brooks was visionary in that he saw that it was possible.

#Comment Re: made: 2007-06-14 13:51:25.452606+00 by: Dan Lyke

I obviously have this love/hate relationship with C++, but one of the things I'm trying to use more of is the notion of algorithms and functors, so that when I'm doing a "for each" versus a searh I express that at a fairly high level, because I can see that if I manage to abstract away from for and while loops enough I may be able to do things like automatic parallelization: This for loop is really an "apply this operation to every element of this collection", that for loop is a consolidation, and if I'm careful about how I write my functors I can apply them to the elements of the collection, and then to each other, to consolidate the data that way.

I think mostly it's just a way of making myself think in those more abstract idioms, I actually don't think there's a reasonable way to get there in the next few years with how I see processor architectures going, but maybe something will surprise me3.

#Comment Re: made: 2007-06-14 20:35:12.749451+00 by: spc476

To be fair, the actual list was “low level stuff like if blocks, for and while loops, opening and closing files, creating and deleting resources, thread synchronization etc.” And while I might agree with the for loops (Dan, you really should be using a mapping construct, or tail recursion for your loops), but the others listed?

if blocks? You could do away with explicit if's by using a series of pattern matches (like in Erlang). But can you do away entirely with these “low level details?” How abstract can you go before you scare off the power users? Or the regular users? How can a user express such things as “resize these 50 images and put the results over here”?

I feel that if blocks and the various loop constructs are fundamental to programming computers that it just seems unsettling to me to dismiss them away as mere “low level details.”

Maybe that's just me.

But then again, I'm cynical enough to yell at Dan—Dan! What the heck are you doing writing code? That's a premature optimization! You should find code that's already been written and use that! Sheesh! Programmers these days!

#Comment Re: made: 2007-06-15 15:04:21.859511+00 by: Dan Lyke

Yeah, I think it's largely a matter of where the line gets drawn, I can argue that in modern languages closing files and deleting resources is a low level detail, and opening files is getting there.

But, as you point out, we can go back to "anything beyond arithmetic, test and branch instructions is low level". Or break it back down to Turing's instructions. Hell, anything more than "and", "or" and "not" is high level.

I think, though, that acknowledging the idioms that we're trying to create, and then building tools to express our code in those idioms, is the way to get better productivity. And I think that it's important to revamp our languages rather than just build objects to plug them together, because it's not just about the nouns and the verbs, it's about the metaphors.