# The Language of Math

March 21, 2011

The language of math is an odd creature, idiosyncratic and given to a huge number of inconsistencies and assumptions. Some symbols are Roman, some are Greek, some are Hebrew, and some just unique. Their meanings are dependent upon the specific equation and the reader is supposed to be able to infer when a superscript is a exponential and when it's just an index. Sometimes two letters next to each other imply multiplication, sometimes not. Sometimes square brackets indicate arrays, sometimes they're just big parentheses.

Still, it works just fine for mathematicians. For computer scientists; not so much. Other than Guy Steele's Fortress language, we invariably translate from "Math" to Java or Fortran, etc. And that is a problem.

Consider the equations above (which I found on some random web page — I have no idea what it is). No computer scientists in their right minds would write out an equation that long. They'd abstract the various bits into small functions that were meaningful. The right side of the second line would probably look something like:

`ave(a, b) * area(1, n, e) + residue(e);`

My contention is that translating between different languages to do the same tasks is fundamentally a bad thing.

Math isn't going to change any time soon, but the hundreds of computer languages we have that all do the exact same thing might.

It's common to hear people talk about how Python is better than Java for some tasks, while TCL is better for others, etc. Despite the fact that they are implementing the exact same operations in nearly the same fashion. Indeed, many Python programs can be translated to Java by adding type declarations and brackets.

While I was pondering this point, a friend of mine dropped by and I felt moved to question him on this. Instead of a reasoned conversation about the issues, what I got was:

"Ruby is totally superior to Java. I can write a program in 1/10 the amount of code!"

"Cool," says I, "Can you give me an example? For example if I wanted to add the "values" of vowels in a sentence?"

In C, I might write:

```char *s = "The quick brown fox";
int sum = 0;

while (*s != 0) {
if (isVowel(*s)) sum += *s;
s++;
}
return sum;
```

How would he write that in Ruby?

He didn't give me an example. He got angry and huffed that I would have to read the Ruby book about active objects. Briefly scanning a Ruby book later, I infer he was saying that if you wrote a Java program using only JDBC, it'd be ugly. Using Hibernate, a Java program would look just about the same as a Ruby program.

Such language-religion makes discussion pretty difficult.

In Java, the above program would look something like this:

```String s = "The quick brown fox";
int sum = 0;

for (int i = 0; i < s.length; i++) {
if (isVowel(s.charAt(i)) sum += s.charAt(i);
}
return sum;
```

At this point I should like to ask the question: "Will the two programs return the same value?"

Answer No. 2: "No! Absolutely not!" is also fine.

Answer No. 3: "I think so." is not fine and is the point of this post.

"I think so" is how programs fail and how people get killed. As a Hang Glider pilot, I am putting my life on the line every time I fly. If somebody told me "I think this carabineer will hold you," I wouldn't launch.

So when we're writing complex computer systems, integrating code from dozens of languages that we think will be compatible, we are asking for trouble. Scanning a few web pages, I find that bugs due to "I think this will work" abound. I see HTML tags showing up regularly where text is supposed to be. I see odd characters where quotation marks were intended. This is a bad thing.

I believe that if we chose a single language for computational tasks and stuck to it, our world would be a far better place.

— Bil

### More Insights

 To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.

Dr. Dobb's TV