LWN.net Logo

Oh, it's easy

Oh, it's easy

Posted Feb 9, 2008 16:17 UTC (Sat) by rsidd (subscriber, #2582)
In reply to: Oh, it's easy by khim
Parent article: Interview: Mark "Markey" Kretschmann (Not the Gentoo Weekly News)

I entirely agree with what you say about computer languages.  But as far as human languages
are concerned: the French language is tightly controlled by the Académie Française.  It has a
smallish vocabulary and well-defined rules of grammar and pronunciation.  The English language
has no controlling authority and freely borrows from languages from all over the world -- so
that the Oxford English Dictionary has 20 volumes and still doesn't cover everything -- and
grammatical rules range from incomprehensible to non-existent.  How many people in the world
speak English?  How many speak French?  How many speak Esperanto?

Similar to English, Perl is still the most widely used of the scripting languages, but I think
that's a first-mover advantage.  If Python had appeared first, nobody would have been
impressed by Perl. You are quite right that "there's more than one way to do it" is a terrible
idea for programming languages.


(Log in to post comments)

More than one way to do it...

Posted Feb 9, 2008 16:56 UTC (Sat) by jzbiciak (✭ supporter ✭, #5246) [Link]

Let's ban C then...

#include <stdio.h>

int times_two_a(int x) { return x * 2;  }
int times_two_b(int x) { return x << 1; }
int times_two_c(int x) { return x + x;  }

int main(void)
{
    int i, j;
    char buf[3];

    for (i = 0; i < 10; i++)
         printf("%d times two is %d\n", i, times_two_a(i));

    i = 0;
    while (i < 10)
    {
         j = times_two_b(i);
         printf("%d times two is %d\n", i, j);
    }

    i = 0;
    do
    {
         sprintf(buf, "%d", i);
         fputs(buf, stdout);
         fputs(" times two is ", stdout);
         sprintf(buf, "%d", times_two_c(i));
         fputs(buf, stdout);
    } while (++i < 10);

    return 0;
}

More than one way to do it...

Posted Feb 9, 2008 20:52 UTC (Sat) by tjc (subscriber, #137) [Link]

The different ways of doing the same thing in your example arise in part from properties of
arithmetic (addition and multiplication) and the binary representation of numbers (bit
shifting).  Granted, "for" loops are syntatic sugar, but a useful and common idiom.

More than one way to do it...

Posted Feb 9, 2008 21:08 UTC (Sat) by jzbiciak (✭ supporter ✭, #5246) [Link]

Surprised you didn't jump on the opportunity to point out that the latter two loops are flawed, in part because they aren't idiomatic... ;-)

I was actually making two points: The first is that allowing for many ways to approach a problem can be valuable, and second is that mindlessly straying from idioms makes it easy to make mistakes and harder for others to understand your code.

It's like goto: It is very easy to use it to turn your code into spaghetti. At the same time, it's probably a mistake to outright ban its use, as there are times when the alternative is less clear. (Escaping a nested loop comes to mind.)

It's not a mistake to ban goto... it's not a mistake to keep it...

Posted Feb 10, 2008 7:53 UTC (Sun) by khim (subscriber, #9252) [Link]

If there are two (or more) ways to do something (like for and while cycles in your samples) but they are used often in real programs - it's not a big deal: reader will remember both and it's easy to understood both. The constructs usable once per a blue moon must be rejected unless they are doing something which will be impossible or very-very hard to do otherwise.

Now about goto: while it's not very useful it's still quite simple to understand because we have "goto in disguise": return. But of course plain old goto is so rare that ban makes sense. But any choice must be justified from reader's position, not from writer's one. This is not how perl chooses the constructs...

It's not a mistake to ban goto... it's not a mistake to keep it...

Posted Feb 10, 2008 11:57 UTC (Sun) by filipjoelsson (subscriber, #2622) [Link]

The last time I saw goto in serious use (where last is defined as most recent instance of
coding - not last time I viewed ancient code), was in some DirectX example code (shipped with
DirectX in ca 1999 - so it is a half way ancient, and it is MS being responsible).

Anyway, the way they used it was to skip to a dtor-like section of a function. Not
particularly elegant, not particularly object oriented, but not outright heresy either -
which, since I thought it _was_ outright heresy confused me.

Ever since, I have been trying to solve it in more elegant ways (using C++). Nested ifs,
functors, exceptions, you name it - it's not very elegant either. Anybody know a better way to
free resources in a C++ function when failing? (I tend to think the nested ifs are the least
evil - but they do eat the line width at an alarming rate.)

EORant ;)

It's not a mistake to ban goto... it's not a mistake to keep it...

Posted Feb 10, 2008 13:48 UTC (Sun) by nix (subscriber, #2304) [Link]

The Linux kernel uses goto in this manner all the time. It's useful if you 
can't do it by splitting the non-ctor-dtor stuff into a separate function.

freeing resources

Posted Feb 11, 2008 3:26 UTC (Mon) by pflugstad (subscriber, #224) [Link]

Are you looking for RAII?

I use it quite often for things like mutexes, but it can be used in many other situations - any time you hold a resource in a function that must be cleaned up when the function exits, including when throwing an exception.

It's a fairly common design pattern for C++ these days - I think I started seeing it a year or two ago...

freeing resources

Posted Feb 11, 2008 8:19 UTC (Mon) by nix (subscriber, #2304) [Link]

In C++ it's probably two decades old: I know it was landing in published 
textbooks ten years ago.

I didn't see it in C outside the Linux kernel before about 2004.

Oh, it's easy

Posted Feb 9, 2008 18:02 UTC (Sat) by nix (subscriber, #2304) [Link]

The Academie Francaise likes to think that it controls the French 
language. (This is about as accurate as saying that the Pope controls the 
world's Christians.)

Oh, it's easy

Posted Feb 9, 2008 19:48 UTC (Sat) by jordanb (guest, #45668) [Link]

The Acadamie has about as much control over how French people speak and write as the MLA has
over Americans, and while English has a larger vocabulary, French has a much larger collection
of tenses so that comparison isn't at all relevant.

I don't know how useful it is to compare a formal programming language to a natural language.
ALL natural languages are as much a collection of cultural references, idiomatic expressions,
notions, subtexts, and connotations as they are a grammar framing a set of semantics. That is
because that is how humans naturally communicate with eachother, but it is very imprecise and
not at all  suitable for a machine interface. 

I think setting out to try to 'deformalize' a computer instruction language to make it more
like a natural language is, essentially injecting imprecision and complexity into it such that
the semantics eventually are no longer reasonably deterministic and the behavior of the
machine becomes difficult to control and predict.


Oh, it's easy

Posted Feb 11, 2008 4:59 UTC (Mon) by ikm (subscriber, #493) [Link]

> How many people in the world speak English?  How many speak French?  How many speak
Esperanto?

You know, I speak English not because I love it so very much and want to marry it, but just
because I have to, it's better at solving my particular communication problems with the
particular audience than other languages are, no matter how simple or hard it is. If I had to
pick a language from the same group, I'd rather pick German -- I like the way it sounds. But
it's not about choosing a language, it's about choosing an audience which you want to
communicate with.

With the programming languages, the situation is somewhat different -- while the language is
still a way to communicate with other people, they are limited to the people who are involved
in the same project, and as such, the less their number is, the easier it is for you to pick
the language you actually like. If you're going solo, you can use whatever that pleases you.
But if you're joining linux kernel development, you have to do C with the specific coding
styles and practices.

With spoken languages you're like doing one big project in English, one big project in French,
etc. So, yes, it's different. While with spoken languages we aren't really in a position to
choose, with programming languages we still can choose, and have criteria of our own.

Oh, it's easy

Posted Feb 11, 2008 10:35 UTC (Mon) by forthy (guest, #1525) [Link]

Tss, the English language is a lingua franca because the two last superpowers were Great Britain and the USA. So for two centuries, English was spoken by the most powerful nations in the world - no wonder it is now spoken by many people in ex-colonies or allies of these superpowers. France might think it is a superpower, but its century of power was the 18th. It's power is long past.

This century will be dominated by China, and you can expect that Chinese will be a lot more important at the end of this century than English. That's just how powers work.

Oh, it's easy

Posted Feb 11, 2008 14:52 UTC (Mon) by smitty_one_each (subscriber, #28989) [Link]

Your idea may carry out, but keep in mind that key features of English are:
-Roman alphabet
-atonal speech
-massive vocabulary
-extensive market penetration

Coming 'round to the Department of Unfair Analogies, English==Python and Ruby==Chinese.  Not
sure what the Rails equivalent for Chinese is, but the sooner they work that out, the better
their chances of growing their market share.

[OT] English features

Posted Feb 11, 2008 22:50 UTC (Mon) by man_ls (subscriber, #15091) [Link]

The roman alphabet was shoehorned into English and it feels -- that is why its devilish pronunciation is a major barrier to learners. In comparison, Spanish, Italian or German are spoken much as they are written, and even French has more or less rigid rules.

Not sure what you refer to with "atonal speech", but if you refer to intonation English and Scottish people certainly speak in a highly tonal way. In comparison, the Spanish (from Spain) or the Russians speak with much less intonation fluctuations. It is only in the US and only in certain areas with massive immigration where accents have been washed out.

As to vocabulary, English speakers always boast of their ample choice of words, but I believe what you really have is excellent dictionaries. In dictionaries for other, more formalized languages only "official" terms spoken by the majority are collected. The huge amount of slang terms which are produced in any geographically dispersed language is mostly lost on them.

In fact the best selling point of English is its almost trivial grammar rules, but you only get to appreciate them when you have learned the thing. So we are left with market penetration, which is of course why we are all learning English like crazy. Not one century ago people were praising French for its expressivity and musicality; at least now we can be honest about it. English (and in particular the US variety) is the language of business and technical endeavors, which is perfectly fine if you ask me.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds