Beaujolais effect is the name given to a a class of potential semantic errors in Jean Ichbiah's draft specifications for the Ada programming language. The name arose from Ichbiah's promise to give a bottle of Beaujolais red wine to anyone who could find such a situation in the draft language standard. At least one bottle was actually awarded for such a discovery.
Background
The Ada programming language allows source code to be broken up into library packages containing definitions of data and algorithms that can be used by programs or other library packages. The definitions in a package are made visible by a with clause. For example, if the line &ndash'
- with Ada.Text_IO;
appears at the top of the source code for a program or package then the data, procedures, and functions declared in the library package Ada.Text_IO can be invoked within that source code. This is the implementation of the namespace concept for Ada.
Thus a program that has the with Ada.Text_IO; directive can can "see" the definitions there, and in order to invoke the New_Line procedure in Ada.Text_IO it can be referred to by name,
- Ada.Text_IO.New_Line;
and similarly with procedures or functions that require arguments, or with reads/writes to any variables declared in the Ada.Text_IO package.
However, such fully specified names can become quite verbose, so the language standard also supports a use clause that tells the compiler to search the contents of the package when trying to identify names that occur in the source code. Thus if both the lines –
- with Ada.Text_IO;
- use Ada.Text_IO;
appear at the top of a program, the New_Line procedure in the package Ada.Text_IO is not only visible to the program, but can be invoked by the abbreviated form –
- New_Line;
because the use clause tells the compiler what package contains the definition.
However, ambiguities can arise if more than one package defines a New_Line procedure, and if the ambiguity is not resolved correctly by the compiler then the resulting program will be erroneous. In practice the ambiguity is rejected by the compiler with a compile-time error message.
The Beaujolais effect
The Beaujolais effect is a situation where adding or removing a use clause in an Ada program changes the behavior of the compiled program, a very undesirable effect in a language designed for semantic precision. Ichbiah took steps to prevent the effect when he updated his draft standard to produce the final Ada 83 language standard. The remaining possible situations for producing the effect were later identified by mathemathical analysis and addressed by the Ada 83 language standard, making any situation that still resulted in a Beaujolais effect in Ada 83 an illegal construct in the more recent Ada 95 language standard.
The Beaujolais Effect can in principle occur in other languages that use namespaces or packages as well, if the language specification does not take care to make it illegal.