News for hackers. Stuff that matters.
Re:Automated Unit Test Improvement Using Large Language Mode... by drowsspa on Saturday February 17, 2024 @09:17AM (#39409598)
Sometimes it's much clearer the number itself, specially when it's a mathematical formula. For instance, is

const MILLIS_PER_SECOND = 1000;

...

...

...

...

...

const durationMs = MILLIS_PER_SECOND * duration

really clearer than

const durationMs = 1000 * duration

?

Re:Automated Unit Test Improvement Using Large Language Mode... by RHSeeger on Saturday February 17, 2024 @10:06AM (#39410062)
Along the same lines, I see this a lot

    long delay = (5 * 60 * 1000); // 5 minutes, in millseconds
And it's perfectly clear to me. Now, I think the comment is really helpful there (indicating intent), but I don't think having separate constants for each of the numbers there is going to make the code better. As it is, it's very easy to read at a glance, know what it's intended to do, and determine if it's correct (should you be worried about that at the moment). Which is what's important there.
Re:Automated Unit Test Improvement Using Large Language Mode... by gregmac on Saturday February 17, 2024 @12:00PM (#39411187)
I do that as well, but typically name that variable delayMilliseconds so there's no confusion.

sleep(delay) always looks ok, but sleep(delayHours) is probably going to catch your eye as suspicious.

Re:Automated Unit Test Improvement Using Large Language Mode... by squeaky-clean on Saturday February 17, 2024 @12:42PM (#39411556)
The latter one leaves the possibility for this though

const duration = 1000 * duration

Re:Automated Unit Test Improvement Using Large Language Mode... by thebackup on Saturday February 17, 2024 @02:09PM (#39412394)
Capital M is for Mega. I would use duration_s and duration_ms.

const duration_ms = 1000 * duration_s

And _us for microsec.

const duration_us = 1000 * duration_ms

But then the tool would probably reject my code for not following the naming conventions which ”disallows using underscores in variable names”.

Guess what I wanted to say is that there are always exceptions to the rule and there should always be some way to turn off the automatic checker for certain sections of the code.