Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Why the test didn't come first.... (was: Re^2: What to test in a new module)

by Bod (Parson)
on Jan 29, 2023 at 21:14 UTC ( [id://11150025]=note: print w/replies, xml ) Need Help??


in reply to Re: What to test in a new module (TDD)
in thread What to test in a new module

The Monastery has also taught you to write the tests first because the act of writing your tests changes and improves your module's design

You are quite correct - as usual...

However, I have extraordinary cognitive problems with doing this. Trying to work out what a module is going to do and how it will do it before writing a line of code is quite a leap of conceptualism for me. I do not doubt that I could learn this cognitive skill if coding and module design were my job but they are very much a sideline. At 55 my brain's plasticity is fading a little I notice which doesn't help.

Over in this node it was suggested that I might like to create a module for Well Known Binary (WKB) from the work I had already done to read one file. I started writing the tests for that module but it has ground to a halt because of the issue above.

Back to this "module"...
It didn't start out as a module. It started as a bit of throw away code to build an array. It then turned into a sub in a small script for my own very limited use. Then, and only then, did I think it might be helpful to other people as it is a relatively general building block.

I don't think tests are necessary for bits of throw away code. Nor for simple scripts that are only intended to be used by me.
Do you think otherwise?

  • Comment on Why the test didn't come first.... (was: Re^2: What to test in a new module)
  • Download Code

Replies are listed 'Best First'.
Re: Why the test didn't come first.... (was: Re^2: What to test in a new module)
by GrandFather (Saint) on Jan 30, 2023 at 00:13 UTC

    Tests for "throw away" code, no. Tests for scripts only for me, a qualified no - if it is important the script is "correct" or subject to revision over time (hmm, isn't that anything that's not "throw away) then test can be very useful to avoid regressions. Test for public facing code, solid yes.

    For code that evolves from throw away, to personal use, to "lets make this a module" it seems sensible that tests should evolve from none, to maybe some, to something that looks like TDD. Aside from anything else. casting the code in a TDD framework forces you to think about the scope of the code and how other people might use it. Thinking about usage and scope shapes the API. TDD then helps codify the API and test its utility and suitability.

    Agile programming advocates often suggest that the code is the documentation, but with TDD the tests are the documentation. In a sense TDD is about writing the documentation, or at least the problem description before you write the code, and that seems like an altogether good thing to do. Thinking about what code should to before you write it can't be a bad thing surely?

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Re: Why the test didn't come first.... (was: Re^2: What to test in a new module)
by Discipulus (Canon) on Jan 30, 2023 at 08:41 UTC
    Hello Bod,

    > However, I have extraordinary cognitive problems with doing this..

    you can try to follow my step-by-step-tutorial-on-perl-module-creation-with-tests-and-git to see if you get some inspiration.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Fabulous!

      That has been bookmarked and will get read properly before very long...

Re: Why the test didn't come first.... (was: Re^2: What to test in a new module)
by eyepopslikeamosquito (Archbishop) on Jan 30, 2023 at 09:31 UTC

    I don't think tests are necessary for bits of throw away code. Nor for simple scripts that are only intended to be used by me. Do you think otherwise?

    No. Bod, I think you're doing a great job. I trust you appreciate from my numerous Coventry working-class asides, I just enjoy teasing you. :)

    Of course, working as a professional programmer for large companies is a completely different ball game. If you ship buggy code that upsets a big important customer, you might even be subjected to a probing Five Whys post mortem. For still more pressure, as indicated at On Interfaces and APIs, try shipping a brand new public API to thousands of customers, with only one chance to get it right.

    I might add that when I'm doing recreational programming (as I've been doing quite a bit lately) I tend to just hack out the code without using TDD. In the tortuously long Long List is Long series, for example, I haven't written a single test, just test the output of each new version manually via the Unix diff command. Update: finally wrote my first LLiL unit test on Mar 01 2023.

    Of course, I could never get away with that at work, where you are not permitted to check in new code without passing peer code review (where you will be grilled on how you tested your code) and where you will typically check in accompanying unit and system test changes in step with each code change.

    For my personal opinion on how to do software development in large companies see: Why Create Coding Standards and Perform Code Reviews?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11150025]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found