The Artima Developer Community
Sponsored Link

Java Community News
The Expressive Power of Languages

14 replies on 1 page. Most recent reply: Mar 13, 2007 1:42 PM by Jean-Daniel Nicolet

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 14 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

The Expressive Power of Languages Posted: Mar 8, 2007 7:04 PM
Reply to this message Reply
Summary
In a recent blog post, Neal Gafter makes a distinction between conciseness and expressiveness in a programming language, and relates that difference to the various proposals to add closures to Java.
Advertisement

When comparing the relative merits of programming languages, developers often mention conciseness and expressiveness as virtues to seek in a language. As Neal Gafter points out in his latest blog post, On The Expressive Power of Programming Languages, using these terms interchangeably can lead to confusion, since, according to Gafter, expressiveness does not necessarily imply conciseness:

Conciseness is pretty obvious... , and you can compare [language constructs] on this measure by writing snippets of code that do basically the same thing as each other, but written using existing constructs and then each of the proposed constructs. How many characters, or tokens, does it take to write the code? By the measure of conciseness, shorter is better...

In my mind, a language construct is expressive if it enables you to write (and use) an API that can't be written (and used) without the construct. In the context of the Closures for Java proposed language extension, control abstraction APIs are the kind of thing that don't seem to be supported by the competing proposals. You don't see the proposals compared side-by-side on this measure because this is something only supported by one proposal. Programmers who have become accustomed to programming with closures find them very useful for factoring out common code in ways that are not currently possible in Java.

Gafter definition of expressiveness refers to an earlier study by Matthias Felleisen, On the Expressive Power of Programming Languages (1990) [PostScript file], whose more general conclusion about the expressive power of a language agrees with Gafter's in that more kinds of APIs can be defined in a more expressive language:

"More expressive" means that the translation of a program with occurrences of one of the constructs ci to the smaller language requires a global reorganization of the program.

Gafter's tacit point is that adding new features to the Java language should make Java more expressive: proposed language changes, therefore, should enable the creation of new kinds of APIs and not merely add syntactic sugar to the language.

Closures are an obvious language addition that will enable new types of Java APIs. In addition to closures, what language features do you think would increase Java's expressiveness the most?


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: The Expressive Power of Languages Posted: Mar 9, 2007 2:26 AM
Reply to this message Reply
My take on the definition is slightly different (and almost certainly more naive). I would define the expressiveness of a programming language as the ease with which it can be read (or expressed) as a spoken language. Alternatively, the ease with which the code's intent can be determined by reading it.

Unreadable code is not expressive.

Carson Gross

Posts: 153
Nickname: cgross
Registered: Oct, 2006

Re: The Expressive Power of Languages Posted: Mar 9, 2007 3:04 AM
Reply to this message Reply
Almost all languages are turing complete, and are therefore as expressive as one another. The only difference between them is conciseness or "mere" syntactic sugar. That's what makes all the difference.

To me, at least.

Cheers,
Carson

Frank Wilhoit

Posts: 21
Nickname: wilhoit
Registered: Oct, 2003

Re: The Expressive Power of Languages Posted: Mar 9, 2007 8:08 AM
Reply to this message Reply
The game is complexity management. A "powerful" language is one that enables complexity to be organized hierarchally in a manner that avoids "lumps" of complexity, which I in turn associate with a high risk of defects and with difficult maintenance.

Object-oriented languages have great power in this area that is not often exploited. I have often said that the hallmark of a bad C++ program is that it contains six classes of a thousand lines each, whereas a bad Java program contains a thousand classes of six lines each. The common failing of both of these caricatures is that complexity is not being managed optimally. The hierarchy must not be too deep or too wide.

The point is that in studying a complex artifact such as a software system one navigates constantly back and forth along a spectrum of detail and that navigation needs to be easy and unforced. A "powerful" language allows levels of coarser detail to allude convincingly to levels of finer detail.

Erik Engbrecht

Posts: 210
Nickname: eengbrec
Registered: Apr, 2006

Re: The Expressive Power of Languages Posted: Mar 9, 2007 10:23 AM
Reply to this message Reply
> My take on the definition is slightly different (and
> almost certainly more naive). I would define the
> expressiveness of a programming language as the ease with
> which it can be read (or expressed) as a spoken language.
> Alternatively, the ease with which the code's intent can
> n be determined by reading it.
>
> Unreadable code is not expressive.

Often the least technical definitions are the most useful.

I think expressiveness is the inverse of the impedance mismatch the language creates between the problem domain and the solution in code.

IMHO object orientation is the biggest hitter here, probably followed by metaclasses (Python definition).

Getters/setters are bad, because they turn one construct with two facets (a property with that can be read and written) into two independent constructs only bound together throw naming convention. So another big hitter is descriptors (again, Python definition).

Operator overloading is good, at least for mathematical applications.

IMHO closures don't add that much in terms of expressivity. Also, much of the gain that can be had from closures can be had through first-class functions combined with anonymous functions.

Erik Engbrecht

Posts: 210
Nickname: eengbrec
Registered: Apr, 2006

Another thought on closures... Posted: Mar 9, 2007 10:29 AM
Reply to this message Reply
I think introducing closures without first-class functions is a really good idea, because it makes regular methods second-class citizens compared to closures.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Expressive Power of Languages Posted: Mar 9, 2007 11:56 AM
Reply to this message Reply
> My take on the definition is slightly different (and
> almost certainly more naive). I would define the
> expressiveness of a programming language as the ease with
> which it can be read (or expressed) as a spoken language.
> Alternatively, the ease with which the code's intent can
> be determined by reading it.

By that measure, one could argue that COBOL is one of the most expressive languages ever created, if not the most expressive. Isn't that in fact the concept behind the language?

I have to agree with Neil Gafter on this. Expressiveness is the measure of expression. If I cannot express what I mean in a language, it is limiting expression. Whether someone reading that code can understand it is a different measure called readability. I don't think we improve or vocabulary my muddying the distinction between different terms.

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: The Expressive Power of Languages Posted: Mar 9, 2007 4:39 PM
Reply to this message Reply
> > My take on the definition is slightly different (and
> > almost certainly more naive). I would define the
> > expressiveness of a programming language as the ease
> with
> > which it can be read (or expressed) as a spoken
> language.
> > Alternatively, the ease with which the code's intent
> can
> > be determined by reading it.
>
> By that measure, one could argue that COBOL is one of the
> most expressive languages ever created, if not the most
> expressive. Isn't that in fact the concept behind the
> language?
>
> I have to agree with Neil Gafter on this. Expressiveness
> is the measure of expression. If I cannot express what I
> mean in a language, it is limiting expression. Whether
> someone reading that code can understand it is a different
> measure called readability. I don't think we improve or
> vocabulary my muddying the distinction between different
> terms.

I have to agree with that sentiment completely. Expressing what you mean is completely orthogonal to people's ability to understand what you are saying. I think mathematical notation is a perfect example of this. To express a lot of mathematical constructs in plain English can be a Herculean task in some cases. A half page of math can expand to dozens of pages of English prose. And the intent still probably isn't as clear. You've just used a lot more words to less clearly explain something.

John Zabroski

Posts: 272
Nickname: zbo
Registered: Jan, 2007

Re: The Expressive Power of Languages Posted: Mar 10, 2007 2:02 PM
Reply to this message Reply
Conciseness and expressiveness can be different for another reason that was not mentioned. In fact, conciseness and expressiveness depend on the context you wish to use them in. There are two contexts: low-level languages and high-level languages. The terms mean completely different things in each.

C is incredibly concise. "K&R" is considered the systems programming bible by many programmers. It is a modest 274 pages long. However, C is a relatively low-level language. It focuses on how things are to be computed, rather than what is to be computed. C provides direct manipulation of the heap with its pointer semantics. Pointers are *how* we express and share resources. C provides the ability to organize computational tasks into small steps, and organize memory management during computation. C is unique, in that dogmatic people will tell you describing precisely *how* something will be computed reduces portability, yet C code has been ported to more environments than any other language I can think of. How things are done in one environment usually isn't the same on another platform. (I have a theory as to why C is so unique, and I will explain why in a bit.)

Higher-level languages place greater emphasis on what is to be computed. They minimize the control programmers have on how we express and share resources. In exchange for giving up this control, programmers are rewarded with a greater ability to describe what is to be computed. This ability allows developers to focus more on speed of development, maintainability and flexibility. Higher-level languages have APIs that abstract away unnecessary details in order to facilitate speed of development, maintainability and flexibility. An API can allow for multiple back-ends, such as in Java a developer has ORM layer options like Hibernate, JDO, and iBATIS SQL... or even JDBC.

High-level languages tend to be more declarative. In this context, languages' expressiveness can be measured by their ability to declare what is to be computed. However, this only describes one form of knowledge. There is also interrogative knowledge, exclamatory logic and imperative knowledge. You can measure expressive power of languages based on how much power they give the programmers to describe each of these knowledge types.

In terms of describing imperative knowledge, C stands alone. C is arguably the most powerful imperative language in the world. Its code bases are ported to so many different platforms from its incubation environment because of its imperative knowledge expressiveness.

Expressive languages tend to be a dime a dozen. This doesn't mean they are worthless, just that their individual benefits don't leap out at the average person. Given that all application code is a sunk cost, someone will be perfectly content to stick with a language their team is used to. Keep in mind programming languages are not merely technologies, but also what people think in. One person may prefer to express their thoughts a certain way, or only able to express their thoughts one way.

Erik Engbrecht

Posts: 210
Nickname: eengbrec
Registered: Apr, 2006

Re: The Expressive Power of Languages Posted: Mar 12, 2007 10:26 AM
Reply to this message Reply
> > My take on the definition is slightly different (and
> > almost certainly more naive). I would define the
> > expressiveness of a programming language as the ease
> with
> > which it can be read (or expressed) as a spoken
> language.
> > Alternatively, the ease with which the code's intent
> can
> > be determined by reading it.
>
> By that measure, one could argue that COBOL is one of the
> most expressive languages ever created, if not the most
> expressive. Isn't that in fact the concept behind the
> language?

No, I do not think one could argue that. In order to clearly express intent a language has to provide good facilities for defining abstractions.

You also have to define "expressive to whom?"
1. The computer
2. The person who wrote it, reading it later
3. Some other person reading it

You also have to define what it is expressing. Does it need to express intent, or just the structures and actions required to achieve the desired result? Does it need to define the invariants in the code?

So you have to define what you are expressing as well.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Expressive Power of Languages Posted: Mar 12, 2007 1:23 PM
Reply to this message Reply
> No, I do not think one could argue that. In order to
> clearly express intent a language has to provide good
> facilities for defining abstractions.
>
> You also have to define "expressive to whom?"
> 1. The computer

Yes that's exactly what this thread is about.

> 2. The person who wrote it, reading it later
> 3. Some other person reading it

Again, this is mixing up terms. How easy it is for others to understand what you have expressed is a separate concept. This is not to say it isn't important. It's just a different thing altogether.

The verbs express and understand are not synonyms.

Often (but not always) expressiveness and readability/understandability are at odds with each other. Having a more extensive vocabulary improves my ability to express thoughts precisely but may make it more difficult for others to understand me.

> You also have to define what it is expressing. Does it
> need to express intent, or just the structures and actions
> required to achieve the desired result? Does it need to
> define the invariants in the code?

These are all subcategories of a expressiveness in a language.

> So you have to define what you are expressing as well.

To do what? I'm not sure what the context of this statement is.

Dave Webb

Posts: 55
Nickname: lazydaze
Registered: Feb, 2006

Re: The Expressive Power of Languages Posted: Mar 12, 2007 7:41 PM
Reply to this message Reply
> > You also have to define "expressive to whom?"
> > 1. The computer
>
> Yes that's exactly what this thread is about.
>

If that was the case, the most expressive language would be machine code.

For me, coding seems to be a feedback process a bit like having a conversation with myself, where I write code then reflect on it immediately afterwards to see whether it looks right. Because of this, the easy readibility of code is essential to its writability and expressiveness.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Expressive Power of Languages Posted: Mar 13, 2007 9:12 AM
Reply to this message Reply
> > > You also have to define "expressive to whom?"
> > > 1. The computer
> >
> > Yes that's exactly what this thread is about.
> >
>
> If that was the case, the most expressive language would
> be machine code.

I can express the same meaning in a couple lines of code that I can in hundreds or thousands of machine instructions. Just like I can use one word to replace several paragraphs of explanation. It's not just what you can express, it's how easily you can express it.

> For me, coding seems to be a feedback process a bit like
> having a conversation with myself, where I write code then
> reflect on it immediately afterwards to see whether it
> looks right. Because of this, the easy readibility of code
> is essential to its writability and expressiveness.

Again, I'm not arguing that readability is not important. I think it's of great importance. In some contexts it's more important that expressiveness. But that doesn't make readability and expressiveness the same thing.

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: The Expressive Power of Languages Posted: Mar 13, 2007 1:33 PM
Reply to this message Reply
> > I would define the expressiveness of a programming
> > language as the ease with which it can be read (or
> > expressed) as a spoken language.
> > Alternatively, the ease with which the code's intent
> > can be determined by reading it.
>
> By that measure, one could argue that COBOL is one of the
> most expressive languages ever created, if not the most
> expressive. Isn't that in fact the concept behind the
> language?
>
> I have to agree with Neil Gafter on this. Expressiveness
> is the measure of expression. If I cannot express what I
> mean in a language, it is limiting expression. Whether
> someone reading that code can understand it is a different
> measure called readability. I don't think we improve or
> vocabulary my muddying the distinction between different
> terms.

Smalltalk - both for expressiveness and readability.

Jean-Daniel Nicolet

Posts: 13
Nickname: jdnicolet
Registered: Oct, 2003

Re: The Expressive Power of Languages Posted: Mar 13, 2007 1:42 PM
Reply to this message Reply
From the various replies. I would retain the following:

Expressiveness is directly bound to the level of abstraction you may cover with a given language. Abstraction alone is however not sufficient. You must still be able to control the lowest (i.e. "operational", in the computer sense of the term) level, either directly (machine code) or indirectly (through a reasonnably good compiler).

You have to consider a ladder of abstraction levels, from the lowest (nearest to the machine) to the highest (highly abstract concepts). Your language is expressive if you are able to control the lowest level by expressing things at a higher level. The higher you can express things whilst retaining control on the loweset level, the more expressive your language is.

This is why adding closures to Java makes it more expressive, because it adds a new level of abstraction to the language, whilst still allowing a good control on how things are actually computed.

C allows a very good and wide covering of the low-level concepts (it is broad), but lacks very abstract concepts, so it is not very expressive under this definition.

Philosophical concepts allow you to express very abstract things, but do not give you control on the low-level stuff, so they are not very expressive either.

With the above definition, the most expressive language is UML, because it covers both very abstract concepts, like business rules, use cases, and business processes, yet allows a continuous spectrum down till database tables and small pieces of code. Admittedly the continuum is not very broad and versatile everywhere along the way today (there are some traceability paths between the various abstraction levels that are scarily narrow), but one may hope that the MDA graal will become a palpable reality some day, thus offering a complete (and reasonably large) spectrum.

Another difficulty is that starting from the lowest level (machine code) you have different possibilities to stack up the abstraction layers, thus leading along different paths. Some of these paths correspond roughly to the different programming paradigms we have today, like imperative programming, object-orientation, aspect-oriented programming, prolog-like rule-based programming, etc. All these paths are more or less incompatible with each other, yet they all offer a way to climb up the ladder of abstraction. It is however very difficult, if not even vain, to attempt a comparison to decide which path leads to the highest point of abstraction view.

A vast majority of people probably agree today on saying that object-orientation leads to a higher level than procedural programming alone, but what about functional programming ? which seems like a more natural extension to procedural programming, but without the "burden" of classes.

If you consider the STL (Standard Template Library) of C++, you'll see an extensive use of functor template classes (i.e. closures à la C++), yet not a single polymorphic method. All algorithms are expressed as "pure" template functions (i.e. not encapsulated within a class), which seems quite natural for an algorithm (after all, only a programmer could have the strange idea of putting a free standing function like the computation of an angle's sinus inside a "Math" class!)

Summary: Expressiveness of a given language is directly related to the height of the abstraction ladder it may cover whilst retaining a reasonably good control on the lowest level, but the problem is more about comparing the various possible ladders!

Flat View: This topic has 14 replies on 1 page
Topic: Java Content Repository with Spring Previous Topic   Next Topic Topic: Building Workflows as Composite Applications


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us