Beaujolais effect
Encyclopedia
Beaujolais effect is the name given to a class of potential semantic errors in Jean Ichbiah
Jean Ichbiah
Jean David Ichbiah was a French-born computer scientist and the chief designer of Ada, a general-purpose, strongly typed programming language with certified validated compilers....

's draft specifications for the programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 Ada
Ada (programming language)
Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages...

. The name arose from Ichbiah's promise to give a bottle of Beaujolais nouveau
Beaujolais nouveau
Beaujolais nouveau is a red wine made from Gamay grapes produced in the Beaujolais region of France. It is the most popular vin de primeur, fermented for just a few weeks before being released for sale on the third Thursday of November...

 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.

Definition

The Beaujolais effect is a situation where adding or removing a single 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 mathematical analysis and addressed by the Ada 95 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.

In principle, the Beaujolais Effect can occur in other languages that use namespaces
Namespace (computer science)
A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols . An identifier defined in a namespace is associated only with that namespace. The same identifier can be independently defined in multiple namespaces...

 or packages
Java package
A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time...

, if the language specification does not ensure to make it illegal.

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 –

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
Namespace (computer science)
A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols . An identifier defined in a namespace is associated only with that namespace. The same identifier can be independently defined in multiple namespaces...

concept for Ada.

Thus a program that has the with Ada.Text_IO; directive 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, ambiguity arises if more than one package defines a New_Line procedure with the same or similar parameter profiles. If the program does not resolve the ambiguity, the compiler should reject the program with an error message. Here is an example:

package A is
procedure New_Line (Number_Of_Lines : in Positive := 1);
end A;

with A; use A;
with Ada.Text_IO; use Ada.Text_IO;
procedure Ambiguous is
begin
New_Line; -- error
end Ambiguous;

In the example above, the call is ambiguous because it could correspond to either Ada.Text_IO.New_Line or A.New_Line with the default parameter value. There are two ways to resolve the ambiguity. One is to specify the package name, and the other is to specify the parameter name explicitly, it the subprogram to call has parameters. The four examples below all resolve the ambiguity.

Ada.Text_IO.New_Line;
A.New_Line;
New_Line (1);
New_Line (Number_Of_Lines => 1);
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK