Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^4: What to test in a new module

by Bod (Vicar)
on Mar 12, 2023 at 14:49 UTC ( #11150939=note: print w/replies, xml ) Need Help??

in reply to Re^3: What to test in a new module
in thread What to test in a new module

Code needs to develop organically and allowed to form its own flow instead of being hammered into a predefined hole of a certain shape

This definitely resonates with me and the way I tend to create things. I'm not suggesting that I do it the correct or best way but, for better or worse, it is how I usually go about things.

As an example, I've just finished writing an email editor in JavaScript and Perl. The 'spec'1 was that it has to be easy for a non-techie user to assemble components of an email (images and rich text), store those atomically and not in parts as I am using temporal tables. The stored data needs to be able to be edited at a later date and when sent out as an email, render reasonably well on Outlook for desktop and K9 for Android (I find if an email renders OK on both of those it will be reasonably alright on most email clients).

Other than that, the 'how' of the implementation or the 'what' of the appearance I had no idea.

I started off with the bit that I thought would be most difficult - the JavaScript rich text editor. I created something that did the basic formatting but also realised that execCommand is deprecated. I asked ChatGPT for help with what to use instead and it suggested Quill along with other options. So my focus changed from creating my own editor to integrating a pre-existing one. Then I had to solve the problem of adding blocks of rich text along with images and being able to drag and drop them to change order. All very different challenges to those I anticipated when I first took fingers to keyboard.

From there, I found that the HTML output from Quill is unnecessarily verbose. ChatGPT again to find DOMPurify to clean up the HTML before it is passed to Perl and stored in a database - there is still some HTML cleaning needed by Perl before sending out the emails but that differs depending on whether it is going to be a preview in the browser or sent out as an email.

The whole process from first key press to fully functioning system took about 4 days working just a few hours per day. I doubt (but don't know for sure) that I could have completed this in that time if I had written tests first. The only test it seems to need (and I'm open to being persuaded otherwise) is that allows people to create an email and that the email renders OK after being sent out. I certainly didn't envision what it was going to look like or the finer details at the start. It evolved organically.

1 - This 'spec' existed nowhere other than in my head. This post is the first time it has been articulated.

Replies are listed 'Best First'.
Re^5: What to test in a new module
by stonecolddevin (Parson) on Mar 14, 2023 at 23:45 UTC

    Yea what I've been trying to get across in this thread but apparently failing to do so is that it's a waste of time to write tests for a POC (unless you have like, a wrapper around a low level HTTP client that you have say, a GET and POST method, there's nothing wrong with writing simple tests for that since that's not going to change) until after you've gone through enough review iterations to confirm with all involved that everything looks good. If something comes up after that, I think it's a scope change and an entirely different can of worms.

    For personal projects I feel like a hard spec outside of a braindump of what you want to do really hinders you even more. Unless you have a good deal of experience in the domain you're working in I feel like you end up "prematurely optimizing" your API ergonomics because you've written out a bunch of API endpoint/method definitions without letting a workflow emerge.

    Long story short, make it work, make it clean, make it fast.

    Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2023-10-04 04:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found