| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
What Are the Benefits, Exactly? Is Haskell — the language used in the preceding example — the holy grail of game programming? Probably not, but it's only one of a number of languages that have been the result of much research into language theory and implementation over the last twenty years. In the days of 20 MHz 80286-based machines (which you could still buy only eight years ago), heavier languages like Haskell, ML, and Scheme seemed out of reach for everyday work. Similarly, any graphics text written during the first fifteen years following the invention of the z-buffer dismissed the technique as hopelessly memory intensive. With gigahertz processors dotting the horizon, things have changed. C and C++ are usually cited as typical high-level languages, but they also have a reputation as "systems programming languages" or "high-level assemblers." What is it that makes so-called modern programming languages higher-level than C?
Notice in the vector example that there isn't a need to define a vector type. Grouping three values in parentheses is all that's necessary. Want to associate a difficulty with a level file? "('castle.lev', easy)" will do it. Need a binary tree? "(Left, Right)" describes the general "shape" of a tree, where Left and Right can each either be another tree or a leaf value. Things that would have been a pain are suddenly trivial. In the expression "x + 1.2" there's no need to declare the type of x, because it's obvious from context that it must be a floating point value in order to have 1.2 added to it. If you later use x in an inconsistent manner, the compiler will complain. Notation can be a lot more mathematical, instead of being bulked up with excessive punctuation and typing. Code that knows about the shape of a binary tree can operate on trees containing vectors, trees containing strings, and trees containing integers. This is much like the template feature of C++, except that you don't need any extra fussing or syntax. One search routine, for example, can be used in a variety of situations. Bottom line: you write less code. Imagine passing a point to a routine and having it return a function that moves a creature one step toward that point. This is pretty bizarre sounding, but that's because it isn't in the usual C++ toolbox. "Programming languages teach you not to want what they cannot provide," says Paul Graham in ANSI Common Lisp. It isn't possible to have wild pointers or to overrun array bounds. You can't accidentally overwrite memory. In Lisp, it isn't even possible to increment a value and have it overflow; you can add 10 billion to 10 billion — without using floating point arithmetic — and get a valid answer. A tremendous amount of work has gone into writing C debuggers, but the seemingly- unachievable goal is to code up a function and then immediately test it interactively. This is the norm in many other programming languages. As a step in this direction, Visual C++'s "edit and continue" feature is a technical marvel, letting you skip a recompile in certain situations. Lisp systems have been able to do this in an unrestricted manner since the 1960s. |
|
|