ARCHIVE / What is a programming closure error?
Closure errors are very common in computer programming, more or less regardless of the programming language one uses. Closure errors involve the improper definition of sets, such as XML tags, arrays, code blocks, hashes, lists and strings, which are essentially ordered sets of characters. For example, the following lines may be used to define two strings:
variable_1 := 'I am a string of text';
variable_2 := 'I am another string of text';
If we were to then abbreviate "I am" to "I'm" we would get:
variable_1 := 'I'm a string of text';
variable_2 := 'I'm another string of text';
This would result in a closure error in that the language parser would detect the apostrophe in "I'm" as the closure of the string. One might then replace the outer single quotes with double quotes, such as:
variable_1 := "I'm a string of text";
variable_2 := "I'm another string of text";
The result would be valid, but what if we accidentally only changed two of the outer single quotes to double quotes such as:
variable_1 := "I'm a string of text';
variable_2 := 'I'm another string of text";
This result would also be valid so far as the parser is concerned, but it would not achieve the desired result of creating two strings. Rather, it would create one string with two lines.
last updated 2008.03.13
How does one minimize closure errors when programming?