Think of a really good piece of software, a program that is either really popular, has a really fanatical following, or is just your personal favorite. I predict that the program you chose has a scripting language embedded in it. That's it. That simple. I'm right aren't I? Mere coincidence? No.
Benfits of language centric design
All really good software development takes place around a language. Why? Having a language embedded into a piece of software gives several important benefits:
SeparableAn embedded scripting language allows modules to be separated. Each module just interfaces to the script engine to export it's functionality.
TestableTest cases are faster to write in a scripting language. This speeds up your test, code, integrate cycle.
ExpandableNew functionality can be added to the program just by adding to the set of scripts the program ships with.
FlexibleIt is easier to adapt your program to specific customers just by changing a script rather than re-building a new executable.
Attributes of a good embedded languageJust because you have a scripting language doesn't mean your going to get all the above benefits. There are some attributes that your embedded language should have:
SizeHow much of the program is touched by the scripting language. The higher the percentage the better. This means that the scripting language is central to the operation of the program and that a large percentage of the program can be manipulated from, or is implemented in, a script.
FocusThe language you choose must be focused on solving the problem at hand. Don't build just any language, build a language in the domain of the problem you are trying to solve.
If you are writing a text editor, write a language that makes string and buffer manipulation easy.
If you are writing blogger software, write a language that makes short work of content manipulation and formatting.
If you are writing drafting software, create a language where geometric shapes and transformations are fundamental operations.
If you are writing a statistical software package, create a language tailored to manipulating data sets.
How about some positive examples of good programs organized around languages:
|Text Editing||Emacs Lisp|
Other programs that have scripting languages:
- Almost any text editor, including vi.
- Even modems understand their own AT language.
How about a list of poor programs? Just because a program has a scripting language doesn't guarantee success. Well in this case I am just going to list one item:
- Any application with Visual Basic in it.
Why are these programs slow, clunky and difficult to work with? How often to you write a 'quick' little script in Word? Excel? Access? Outlook?
What is the difference between:
- Visual Basic in Word and Emacs Lisp?
- Visual Basic in Excel and Mathematica?
- Visual Basic in Access and SQL?
The latter are languages tuned to solve problems in a very specific domain. The former are all the same language with a different object model stuck on the side of it. Applications with Visual Basic in them ignore the Size and Focus attributes of a good embedded scripting language.
How come I can easily switch among 10 languages with out missing a beat yet I can't retain the object model for Word?