[-] aebletrae@hexbear.net 5 points 11 months ago

the intent of the code is to get the previous month RELATIVE to the current date.

But that isn't what it does. From the original post:

function getMonthName(monthNumber) {
  const date = new Date();
  date.setMonth(monthNumber - 1);

  return date.toLocaleString([], { month: 'long' });
}

That is a function which is meant to take a number (presumably 1 to 12) and return a localized name for it. This is essentially an array lookup and should return the same output for a given input (and locale) every time it is called. If the intent is to return a value relative to the current date, it is even more wrong, since it should gather the month from the current date, not the function paramenter. This claim of intent, not present in the original post, is an example of you changing your story over time.

Yes, it would help find the problem faster because the first time invalid date is passed in the program will crash.

No, it wouldn't. As I have said before, testing for unexpected return values is just as effective as testing for errors, that is, not very with the function originally presented under sensible assumptions. If the function actually did look like the intent you claim, the tests would be different, necessarily replacing Date for consistent runs, but would be equally likely to catch the problem whether failing on value or error. And if you are eschewing testing and relying on runtime crashes, you have bigger problems.

Given that I have agreed and commiserated, and neither of us can change JavaScript, there is nothing to be gained from pursuing this complaint. In contrast, what I have tried to say, if followed, would give you an approach that leads to more reliable code, even in the face of undesirable APIs.

I had thought that worth pursuing, and had thought you worth investing my considerable time. Alas, I can only lead you to the water...

[-] aebletrae@hexbear.net 5 points 11 months ago

Yes, and I've said that I agree with that in general. I know that this isn't hypothetical; that's exactly why I keep saying that throwing an error doesn't help you find this bug early at all.

Even the silent weirdness can be caught by the most basic of tests checking output against input, but only if your function works the same way on every invocation.

Whether making a giant fuss (as you'd prefer) or making the best of it (as it actually does), the setMonth method always works the same way. My code always works the same way. The setDate suggestion makes the code always work the same way.

Code that always works the same way is easy to test.

If the day of the month is constant and incompatible with setMonth, whether there's a thrown error or just an unwanted return value, a simple test will reveal that on every test run. If the day of the month is constant and always compatible with setMonth, the test will pass appropriately on every test run.

The bug in the code you originally presented comes from working differently over time. That's why, most days, tests won't identify the problem, even with a fussy, noisy API. Most testing days, the date will just happen to be compatible, and even the fussiest, noisiest API will carry on without any mention of the problem.

The reason the original code works differently over time has nothing to do with the silent, unexpected behaviour of setMonth. It's entirely down to calling Date() without arguments, the entire point of which is to give different values over time. That call effectively introduces state that is not controlled by the function. And not bringing it under control is the real source of the bug.

Yes, absolutely, JavaScript sucks. Make F# the only supported web scripting language! But JavaScript's suckiness is not the cause of this particular bug. JavaScript's suckiness is not the reason this bug is hard to catch. The real problem lies in code that functions differently over time when it should (and could easily) be consistent. That's what actually makes it hard to test.

Plenty of other languages and API design choices still allow code that functions that work differently over time, which is why, as justifiable as the complaints are in general, those factors are irrelevant for this particular bug. Write code that always works the same way and the problem goes away. That's the real core of the issue.

Obviously, that's easier said than done, and it's irritating that neither loud errors nor most testing will help you in this regard, but that's the way it is.

[-] aebletrae@hexbear.net 5 points 1 year ago

I was taught that side effects are not so one-sided, and that changing output in response to outside state (such as the date) is also a side effect, a side effect on the function, rather than a side effect of the function, but I'm happy to use other definitions so long as they're commonly understood.

As I said before, though, even if JavaScript did throw an error as you'd prefer, it would still allow your function to have date-based problems. They'd be a bit noisier perhaps but no less present, and just as "well it's worked fine so far". And that's because, as I keep saying, the real problem here is using a function with inconsistent output and not thoroughly dealing with the possibilities. An API change wouldn't alter that. Most of the time it would still let you write bad code.

I also probably agree with you that errors are generally better than silence in response to bad input but, as someone else has said (more or less) it's not always unreasonable to consider "31st [Month]" as 31 days after the end of [Previous Month]. Without throwing errors, this flexibility is possible. Perhaps the creators believed having to mutate the day-of-month first was an acceptable trade-off for that.

[-] aebletrae@hexbear.net 6 points 1 year ago

You've replied while I was editing, so see that regarding what I mean by side effects.

As far as throwing an error when you try to create "31st February", this wouldn't actually help much, since the error would still only occur on some days of the year, because your original code doesn't account for the range of outputs from Date() when called without arguments.

To perform correctly, your code needs to normalise the day of the month, or just create the date more explicitly to begin with, but this is a calendrical issue, not a JavaScript one.

[-] aebletrae@hexbear.net 5 points 1 year ago

It's a Klingon moon that's doing just fine.

[-] aebletrae@hexbear.net 7 points 1 year ago

I remember having to pause the video after that second bit. The piled-on criticisms, so matter-of-factly delivered, needed some recovery time. Your assessment is spot on.

[-] aebletrae@hexbear.net 6 points 1 year ago* (last edited 1 year ago)

"Instance" seems too jargon-y to me as well, and "proxy" is even worse. "Server" and "host" are probably a little more familiar, but are still technical language.

Confusion doesn't stem from individual words; people need explanations and examples, but, as an alternative to "instance", if you want to extend the "communities" metaphor, then "society" as a cluster of communities is a natural option, particularly since it relates to the widely understood concept of social media. Since most people using the Internet also know what a web "site" is, you could use the sibilant linguistic association to help cement the notion:—

Each society has its own web site, such as:

  • aussie.zone, where the communities relate to Australia;
  • programming.dev, where the communities discuss software development;
  • and lemmy.film, where the communites are about movies.

You can choose which society you want to join, although some will ask you to fill out an application. Most societies have connections to others, meaning that you can discuss things with people who are part of different societies. Often, you'll recognise them by their username saying that they're at (@) another site. Not all societies get along with one another, so which one you join will also affect who you can talk with.

Each society has its own rules it expects you to follow, whether you are a member of that society or just visiting.

This kind of language seems more intuitive to me anyway, although when I've tried describing instances and federation before now, I've likened instances to countries:—

You choose somewhere to live (and you can move later if you want). If there's a cross-border agreement, then you can send messages back and forth between people in each place.

but this has also meant stressing that your instance "country" doesn't have to match where you physically live, so a more general term probably would have been more useful.

[-] aebletrae@hexbear.net 6 points 1 year ago

Tell them that, while the "archy" of words like oligarchy means "rule" or "command", kratos means "power" or "strength", and that demos is "the common people".

A true democracy, therefore, is not rule by the majority—that would be ochlarchy or, more commonly, ochlocracy, ochlos being the "masses"—but an empowerment of the common people.

And that they're right, America is not a true democracy.

[-] aebletrae@hexbear.net 6 points 1 year ago

Oh! I see what you're doing. You're insisting on a specific, unhelpful, and—ultimately—incorrect definition of a term as a meta-commentary on the weakened definition of racism as mere racial animosity as used by the privileged who think they know better than to listen to others, that are the subject of the post.

It's trolly as hell, but very clever, and a far, far better analogy. Bravo!

[-] aebletrae@hexbear.net 5 points 1 year ago

For someone seemingly so eager to try out new distros, I'm surprised you haven't mentioned virtual machines. If the vibes are off, it's a whole lot less disruptive to find out that way.

Your experience with drivers won't be quite the same as a bare-metal installation, but checking out software shouldn't be a problem.

[-] aebletrae@hexbear.net 6 points 1 year ago* (last edited 1 year ago)

The end of "Cogenitor", where Archer blames Trip for the death of Charles.

view more: ‹ prev next ›

aebletrae

joined 1 year ago