December 19, 2011 Leave a comment
In this article, I will talk about naming the comparison method “diff”, what constitute a good return value for the diff method, and how I emulate exception handling in SystemVerilog, a language which does not have formal exception handling.
First, we name the comparison method diff rather than compare. Why? Because is it easier. Consider this code
if (packet1.compare(packet2)) begin // what does compare return exactly? end
Chances are that you have to look up the compare method to see what it returns before you write your code, each time. Now read this code:
if (packet1.diff(packet2)) begin // it reads like english // so packet1 must be different than packet2 $display("Packets are different); end
Much easier. And I bet you don’t have to look up the diff method. Read more of this post