Wolfram Library Archive

Courseware Demos MathSource Technical Notes
All Collections Articles Books Conference Proceedings
Title Downloads

Safer Code

Stephan Leibbrandt
Organization: Symbols and Numbers Mathematische Software GbR

Wolfram Technology Conference 2011
Conference location

Champaign, Illinois, USA

Engineers need for their daily work robust and reliable blocks of code to perform calculations and simulation. This can be difficult in Mathematica, because by default it does not check data types and continues even inconsistent calculations, which results sometimes in a mess of messages. This situation is often unsatisfactory for an engineer.

This presentation shows ways to directly identify the source of problems before they are obscured by subsequent calculations and messages. One aspect is the introduction of a type-checking system for all kinds of definitions. The flexibility of Mathematica allows for easy extension of pure types to domains like real positive numbers. In addition to Assert, preconditions and postconditions of expressions are implemented by means of an automatism, so that the user doesn't need to take care of the checks and can focus on his or her work. After detecting a problem, the configurable actions taken are for example a message or an abort of the calculation. The surveillance of assignments and matching lengths of listable operators like Plus exemplify the type-checking that can be easily expanded.

Using the presented techniques does not restrict the engineer, but gives Mathematica the same reliability as typed languages usually used in an industrial environment.

*Wolfram Technology

Downloads Download Wolfram CDF Player

SaferCode.cdf (340.2 KB) - CDF Document
SaferCode.nb (339.5 KB) - Mathematica Notebook