Bil Lewis

Dr. Dobb's Bloggers

The Language of Math

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.

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?"

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.

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

Answer No. 1: "Yes! Absolutely!" is a fine answer.

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.

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!