using assertionswhen writing code programmer must


Using Assertions

When writing code, programmer must state pre- and subtle post conditions for public operations, state class invariants and insert unreachable code assertions and loop invariants wherever appropriate.

Some languages have facilities to directly support assertions and some don't. If a language doesn't directly support assertions, then programmer can mimic their effect. For instance, first statements in a class method can test the preconditions of the method and throw an exception if they are violated. Post conditions can be checked in a similar manner. Class invariants are more awkward to check since code for them should be inserted at the start and end of every exported method. For this reasons, it's often not practical to do this. Unreachable code assertions occur comparatively infrequently and they are easy to insert, so they must always be used. Loop invariants are mainly for documenting and proving code, so they can be stated in comments at the tops of loops.

 

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: using assertionswhen writing code programmer must
Reference No:- TGS0356404

Expected delivery within 24 Hours