• CanadaPlus@futurology.today
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    8 months ago

    First off, thanks for the help!

    Really responsible devs write the unit tests first, because you should know what you’re going to put in and what you’ll get out before you start writing anything.

    I’ve obviously heard the general concept, but this is actually pretty helpful, now that I’m thinking about it a bit more.

    I’ve written pretty mathy stuff for the most part, and a function might return an appropriately sized vector containing what looks like the right numbers to the naked eye, but which is actually wrong in some high-dimensional way. Since I haven’t even thought of whatever way it’s gone wrong, I can’t very well test for it. I suppose what I could do is come up with a few properties the correct result should have, unrelated to the actual use of it, and then test them and hope one fails. It might take a lot of extra time, but maybe it’s worth it.

    How do you deal with side effects, if what you’re doing involves them?

    • TheHarpyEagle@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      8 months ago

      For your vector issue, I’d go the route of some static examples if possible. Do you have a way to manually work out the answer that your code is trying to achieve?

      For side effects, that may indicate what I referred to as tightly coupled code. Could you give an example of what you mean by “side effect”?