Download Ada in Action

Transcript
Chapter 7. Epilog
148
counter to 1. If Open is called when the reference counter is not 0, it simply increments the reference
counter without opening the device. If Close is called when the reference counter is 1, then it closes the
device and sets the reference counter to 0. If Close is called when the reference counter is greater than 1,
it just decrements the reference counter without closing the device.
All components that use shared devices must follow the "kindergarten convention." That is, "If you
opened it, close it!"
This approach gives me three options. I can let the main program open the keyboard, mouse, and screen
at the beginning of the program, and then close them at the end; or I can let every subprogram that needs a
resource open it when it needs it and close it when it is done with it; or I can do both. (I generally select
the third option.)
7.7.
Ada 95
Now that Ada 9X has become Ada 95, I've been asked if I will re-write Ada in Action with an emphasis on
the new Ada 95 features. No, I won't in the foreseeable future.
I write about what I have learned from personal experience. I don't repeat fables I've read someplace else.
There are no validated Ada 95 compilers yet, so I don't have any experience with them. GNAT, an
evolving Ada 95 compiler has been out for a year or so, but I don't enjoy working on quicksand, so I
haven't used it. I'm not even anxiously awaiting the arrival of a validated Ada 95 compiler because I don't
have an immediate need for any of the new features. Eventually I will probably come across a real
application where one of the new Ada 95 features will permit me to write a more elegant solution than
Ada 83 did, but I haven't found one yet.
For example, in section 2.4.2 I said, "Although Ada always allows you to add new operations to a data
type, she never lets you take away operations derived from a parent." That is no longer true. Ada 95 lets
you make operations abstract, which effectively takes them away. So I could have created the dimensional
units types by starting with integer or float types and taken away multiplication and division. But which is
better? to have a specification that lists all the operations a type has; or to have a specification that lists all
the operations a type doesn't have? I'd prefer to know what it can do, not what it can't. So I'm not about to
go back and rewrite the dimensional data types and use abstract operations.
The most important thing I learned from following the progress of the Ada 9X project is that Ada had very
little room for improvement. There were hundreds of suggested improvements to Ada, but the vast
majority of them were rejected because Ada already did the right thing.
Most of the changes that were made were simply syntactic sugar. There were, in my opinion, only five
significant changes.
The first significant change was the expansion of the character type from 7-bits to 8-bits, permitting the
use of accented characters. There no doubt is a need for this given the popularity of Ada outside the
United States.
The second change (really a group of changes) provided for more programmer control of real-time
performance. Although nearly all of my work for the past 18 years relates to real-time data processing and
display (with cycle times much less than 100 milliseconds), I have never experienced the problems that
these changes were supposed to solve. Therefore, I don't feel qualified to comment on whether these
changes have merit or not.
Ada in Action