When I was reviewing PL/SQL code written by a fellow developer, trying to understand what it does, I came across the following code snippet:
IF org_rec.planning_make_buy_code = 2 THEN IF org_rec.customer_order_enabled_flag = 'Y' THEN p_dc1 := v_originating_org; ELSE p_dc1 := v_default_shipping_org; END IF; END IF;
Now, I can easily guess that the
customer_order_enabled_flag can have a value of “Y” or “N” or maybe NULL, but, how am I supposed to know what
2 means in the statement
IF org_rec.planning_make_buy_code = 2 ?!
Of course, I can spend time trying to figure out what
2 means. However, had the original author spent a minute or less adding a comment just prior to that IF statement explaining the meaning of that code, It would have saved me time and effort and made the logic a lot clearer:
/* 1 = buy, 2 = make */ IF org_rec.planning_make_buy_code = 2 ...
This is a perfect example when commenting your code makes a huge difference.