Fork me on GitHub
#other-languages
<
2022-01-10
>
quoll01:01:10

Since I’m writing JavaScript, I’m using VSCode, and it has copilot. I’m getting freaked out by it.

quoll01:01:08

To explain… I have a constants that I declared:

const TWO_32 = 0x100000000;
const INT_MASK = 0xFFFFFFFF;
It’s 2^32, and it one larger than the largest number that can fit into an unsigned int (which is the INT_MASK value). ie. it has overflowed into the 33rd bit position. I also have a function called unsignedLonger, which converts a 32-bit number into a positive number, even if the top bit is set to 1 (which normally makes it negative). This means, for instance, that 0xFFFFFFFF will be returned as 4294967295 instead of -1.

quoll01:01:02

With that in mind, I was about to port this Java code (which I’m sure that copilot has already seen and analyzed):

boolean carry = (sum >>> 32 != 0);
while (xIndex > 0 && carry)
    carry = ((result[--xIndex] = x[xIndex] + 1) == 0);
Copilot suggested this:
var carry = (sum >= TWO_32);
while (xIndex > 0 && carry) {
    sum = unsignedLonger(x[--xIndex]) + 1;
    result[xIndex] = sum & INT_MASK;
    carry = (sum >= TWO_32);
}

quoll01:01:20

This is entirely correct. But I had to check it carefully, because… what the hell!

didibus04:01:19

That's neat. My feeling right now though is how often can it be wrong, and does it take me longer to validate it isn't wrong, or to just do it from scratch myself?

didibus04:01:14

Like when you say you had to check it carefully, did that take you more time than it would have to convert it yourself?

Martynas M16:01:43

It's code without tests. This is why it took time. I think it should be the same as reading a function written by another person and without tests.

quoll16:01:58

It does take me longer to check it, and sometimes it’s wrong. Worse, sometimes it’s subtly wrong. But I’m amazed at when it gets it right

didibus04:01:34

> I think it should be the same as reading a function written by another person and without tests. That often takes me longer then writing it myself haha

didibus04:01:17

I guess maybe it would work really well in a TDD workflow though, since you'd write your tests first, then auto-complete the full implementation if possible and just see if it passes your tests

👀 1
Martynas M05:01:08

I can already imagine having a seed for the generator and then only writing tests. And having a source directory which you can't ever edit... And for mutation testing... you only change the seed xD

didibus05:01:22

That would kind of be crazy, in the future, programmers only write tests lol, Copilot writes all the implementation for you