About This eBook by Bart De Smet

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Asserts and Contracts

Statically discovering typical code defects is a big convenience, but it isn’t a silver bullet. Lots of conditions are intrinsic to the algorithms you’re coding up and simply cannot be detected by tools without particular knowledge of the developer’s intent.

To communicate intent, various mechanisms have been created over the years. The oldest and simplest one is to use asserts, which are pieces of code that perform a logical check, typically only in special builds of your software. If the check fails, the developer is notified and invited to break in the debugger to analyze what’s going wrong. Maybe the condition makes a false assumption about code invariants, or you’ve just caught a problem on the spot before it can do ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required