Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your literal example, I don't think it's worth the hassle. Just write tests so that you ensure your conversions work well.</p> <p>In your real code, if your structs have "hundreds of fields", your structs may be badly designed. Maybe they should be composed of smaller objects. I've never designed anything which required hunderds of fields in exactly the same struct object - instead, these fields allowed some kind of classification so that they could be treated in smaller bunches.</p> <p>Since your code is <em>legacy</em> and you don't want to rewrite it, just write tests for your conversions functions, as I said above for the example.</p> <p>Well tested code is no longer <em>legacy</em> code. Legacy code is basically code for which you don't have automated tests.</p> <p><strong>If rewriting it is not an option, testing it is a must.</strong></p> <p>About the cost of testing it "both ways", Idan Arye's <a href="https://stackoverflow.com/questions/19377612/how-to-uniformly-implement-two-way-conversion-without-code-repetition/19377685?noredirect=1#comment28717291_19377685">comment below</a> says everything:</p> <blockquote> <p>Since the conversion is symmetric, testing it both ways is not that much more work than testing it one way. All you need to do is init two structs - <code>C c</code> and <code>D d</code> - and set them to be the converted versions of each other. Then you just have to check that <code>CtoD(c)==d</code> and <code>DtoC(d)==c</code> (or use comparison functions if you happen to have them defined). The big work here is initializing <code>c</code> and <code>d</code> - but you would have to do that anyways if you wanted to test one way conversion, so adding the test for the other way is very cheap.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload