7. Constraints and Validation

Introduction

When you’re programming with general purpose languages such as C# or Java, errors come in many flavors. You can mistype a keyword and get a lexical error, or you can get the order of a construct wrong and get a syntax error. These errors are the results of implicit constraints that the language imposes upon the stream of simple text that you pass to it. Strongly typed languages incorporate a type system into these constraints and produce errors at compile time, for example, when you try to set the value of a variable defined as an integer to a string value.

For many years now, good mainstream programming practice has suggested that assertions be used to impose further explicit constraints on what parameter ...

Get Domain-Specific Development with Visual Studio DSL Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.