[HN Gopher] Save the code or save the tests? (2020)
       ___________________________________________________________________
        
       Save the code or save the tests? (2020)
        
       Author : feltsense
       Score  : 20 points
       Date   : 2021-06-08 19:12 UTC (1 days ago)
        
 (HTM) web link (qntm.org)
 (TXT) w3m dump (qntm.org)
        
       | ravenstine wrote:
       | > Doesn't matter how good the tests are, by the time you've
       | "reconstructed the code" from tests you're out of business.
       | Running code with no tests makes money. Tests with no running
       | code don't.
       | 
       | ^^ _comment from someone named hobbs_
       | 
       | Exactly. Users can tolerate an app that's kinda broken in some
       | ways, but tests don't make money. In fact tests can often cost
       | money anyway if they're not testing what's really important. No
       | matter what, there are going to be parts of your code that simply
       | cannot be described by the tests that were written.
        
         | cogman10 wrote:
         | I look at it from a pure time perspective. I generally spend
         | something like a 10:1 ratio of writing code vs tests. That is,
         | it takes me 1/10th the time to write testing stuff vs the
         | actual code.
         | 
         | With that perspective, it's beyond silly to prefer the tests.
         | You are saying "Should I throw away 90% of the work or 10% of
         | the work?"
         | 
         | Said another way, you are asking "Should I save the chapter
         | headings of my book or the content?". I can make new chapter
         | headings, but writing the actual chapters is where I spent all
         | my time.
        
       | knightofmars wrote:
       | This is absolutely ridiculous. The code is the product, without
       | it, the company is out revenue the entire time that the
       | application is being re-written to match the tests.
        
       | drewcoo wrote:
       | > When would this hypothetical, or anything like it, ever happen?
       | 
       | Having test code and dev code in separate repos is a pattern in
       | some places. Where that exists, save the dev code. Any test code
       | that's not allowed to mingle with dev code is highly suspect and
       | almost certainly not a working spec.
        
       | scarygliders wrote:
       | If I were to lose all the code for my Elite: Dangerous 3rd party
       | application, I'd not be losing just the code - I'd be losing all
       | the UI stuff.
       | 
       | Even IF I ever wrote unit tests for it - which I don't do and
       | have never done for anything - those unit tests wouldn't have
       | anything in them from which I could reconstruct the UI.
       | 
       | No. You save the code and the surrounding UI and the UI glue
       | code.
        
       | petters wrote:
       | I have worked in the airline industry with scheduling algorithms.
       | We had a very comprehensive test suite, but reconstructing the
       | algorithms from that would take a decade. That surely only works
       | for toy code bases. No one saves the tests.
        
         | refactor_master wrote:
         | Exactly. Verifying an algorithm is easy. Writing it is hard.
        
           | postalrat wrote:
           | add(a, b) => a + b
           | 
           | How would you verify that algorithm?
        
             | cronin101 wrote:
             | Forall A:         add(A, 0) == A              Forall A B C:
             | add(add(A,B), C) == add(A, add(B, C))
             | 
             | I think that's sufficient. Rule 101 of useful testing is
             | understanding the actual constraints you rely on.
             | 
             | Maybe throw in add(A, B) == add(B, A) if you're angling for
             | a promotion...
        
             | [deleted]
        
       | slver wrote:
       | > More recently, out of curiosity, I pitched the same question as
       | a poll on Twitter. On Twitter, roughly 80% of respondents said
       | that they would save the application code and 20% said they would
       | save the tests.
       | 
       | Surprise, common sense.
       | 
       | Saving the tests is like needing to know the answer to the
       | Ultimate Question of Life, the Universe, and Everything (which is
       | 42) and discarding the question.
        
         | cogman10 wrote:
         | I'm shocked that 20% of devs value tests over working code.
         | This should have been a 99% to 1% thing.
        
       | aliasEli wrote:
       | Saving only the tests is completely nonsensical. Even with 100%
       | code coverage, tests will only cover a tiny fraction of the
       | programs behavior. The original program of course fully describes
       | its behavior. If you are lucky you might even have a description
       | in the comments why some part of this behavior was chosen.
        
       | jspash wrote:
       | Well I use elixir so of course I would save the code. The tests
       | are built into the comments!
        
       | FartyMcFarter wrote:
       | Tests are a development tool: they make it easier for developers
       | to change code confidently.
       | 
       | So to rephrase the question: save the code, or save something
       | that makes it easier to change code you no longer have? It seems
       | a bit easier to answer if asked this way...
        
       | [deleted]
        
       ___________________________________________________________________
       (page generated 2021-06-09 23:02 UTC)