Only Syntax

Journal of my investigation into the development of a new programming language

Monday, April 07, 2003

 

Adjectives


Part of the art of programming, in languages I've worked with at least, is balancing nouns and verbs. Before there were modules, data structures and objects, routines (verbs) had to bear all of the organizational burden of a program. Transferring some of that burden to data structures (nouns) can be a great simplification.

Human language, of course, has much more than nouns and verbs. And while I don't think human language represents a perfect model for computer languages, some of my favorite languages are English-like, so I'm willing to at least consider suggestions this analogy presents.

And I think a lot of the things I do in programming could be simpler if I had adjectives. The fields of a database record or a data structure, or the properties of objects, frequently serve the role that adjectives fill in speech. But asking simple questions about the properties can require more complexity than might be necessary.

Suppose a language had adjectives, binding a comparative test to terms for, at a minimum, superlative and comparative. I tend to think that opposite, and anti-comparative and anti-superlative are also appropriate.

Let's use width for our examples.

With adjectives Without

is r1 wider than r2? is r1.width > r2.width?

width of the widest of the_rects max = VERY_NARROW
foreach rect (the_rects)
max = rect.width if rect.width > max

is any of the_rects wider than 3? foreach rect (the_rects)
succeed if rect.width > 3
fail

Arguably, the two loops are a more accurate reflection of what's really going on in the computer - but for that matter, GOTO would be a more accurate reflection of what's going on in a loop. I think how we express things in English is a better reflection of how we think of them. So in terms of communicating intent, I think adjectives are an improvement.

SQL makes short work of questions like this; arguably it has better support for what I am calling adjectives than for nouns and verbs. But I'm after a language that falls more into the procedural family, I think, and should be useful outside of a database context.

Peeking at semantics for a moment, I think that the terms should be bound to a test, rather than a field as I've used in these examples. It would allow for more sophisticated comparisons.

Comments: Post a Comment

<< Home

Archives

03/30/2003 - 04/06/2003   04/06/2003 - 04/13/2003   10/12/2003 - 10/19/2003   01/09/2005 - 01/16/2005   01/16/2005 - 01/23/2005  

This page is powered by Blogger. Isn't yours?