- Bounds checking
In
computer programming , bounds checking is any method of detecting whether a variable is within some bounds before its use. It is particularly relevant to a variable used as an index into an array to ensure its value lies within the bounds of thearray . For example: a value of 32768 about to be assigned to a sixteen-bit signed integer variable (whose upper bounds are -32768 to +32767), or accessing element 25 on an array with index range 0 through 9 only. The first is also known asrange check ing, the second asindex checking .A failed bounds check usually results in the generation of some sort of exception signal.
Because performing bounds checking during every usage is time-consuming it is not always done.
Bounds checking elimination are compiler technologies that eliminate unneeded bounds checking in many common cases.Many programming languages, such as C, never perform automatic bounds checking, in the interest of speed. However, this leaves uncaught many
off-by-one error s andbuffer overflow s. Many programmers believe these languages sacrifice too much for rapid execution. In his 1980Turing Award lecture,C. Antony R. Hoare described his experience in the design of Algol 60, a language that included bounds checking, saying:A consequence of this principle is that every occurrence of every subscript of every subscripted variable was on every occasion checked at run time against both the upper and the lower declared bounds of the array. Many years later we asked our customers whether they wished us to provide an option to switch off these checks in the interest of efficiency on production runs. Unanimously, they urged us not to - they already knew how frequently subscript errors occur on production runs where failure to detect them could be disastrous. I note with fear and horror that even in 1980, language designers and users have not learned this lesson. In any respectable branch of engineering, failure to observe such elementary precautions would have long been against the law.
Mainstream languages that enforce run time checking include Ada,
Visual Basic , Java,JavaScript , Python, Ruby,Haskell ,Lisp , and C#. The D andOCaml languages have run time bounds checking that is enabled or disabled with a compiler switch. C# also supports "unsafe regions": sections of code that (among other things) temporarily suspend bounds checking in the interest of efficiency. These are useful for speeding up small time-critical bottlenecks without sacrificing the safety of the entire program.Data Quality
In the context of data collection and data quality, bounds checking refers to checking that the data is not trivially invalid. For example, a percentage measurement must be in the range 0 to 100; the height of an adult person must be in the range 0 to 3 meters.
References
* "The Emperor's Old Clothes", The 1980 ACM Turing Award Lecture, CACM volume 24 number 2, February 1981, pp 75-83. [http://portal.acm.org/citation.cfm?id=358561]
Wikimedia Foundation. 2010.