3 ms·
I was recently working on something for a new feature on my Elixir-learning site and opened a new file called "fibonacci.ex" to write a tail-recursive fibonacci
by AlchemistCamp 4y ago
I was recently working on something for a new feature on my Elixir-learning site and opened a new file called "fibonacci.ex" to write a tail-recursive fibonacci function.
After typing in nothing more than, "defmodule Fibonacci do", Copilot emitted the entire module from the code on my site here: https://alchemist.camp/episodes/elixir-tdd-ex_unit https://alchemist.camp/episodes/elixir-tdd-ex_unit
The function names and documentation strings were identical. Also, the site isn't under a GPL, just a standard copyright. That said, I'm curious to learn if others see the same behavior. It's possible I once opened that file locally with Copilot installed and that my own computer was its source.
- nicmo 4y agoPossible, if the doc was open at that time, or if the file you were editing is in the same or nearby directory
- Filligree 4y agoIt gave me this: defmodule Fibonnaci do def fibonnaci(0), do: 0 def fibonnaci(1), do: 1 def fibonnaci(n), do: fibonnaci(n - 1) + fibonnaci(n - 2) end Which seems fine I guess (I don't know the language), but doesn't even have comments. I prefer my files with comments. After forcing the point, I got this: defmodule Fibonnaci do @moduledoc """ Documentation for Fibonnaci. """ @doc """ Calculates the nth Fibonnaci number """ def fibonnaci(n) when n < 0, do: nil def fibonnaci(0), do: 0 def fibonnaci(1), do: 1 def fibonnaci(n), do: fibonnaci(n - 1) + fibonnaci(n - 2) end In which I prompted the AI with everything up to (and including) @doc. So I figure it was picking it up from your computer, somehow. EDIT: I then noticed the typo, tried it with fibonacci.ex, and got the same result.
- zelphirkalt 4y agoInteresting though, that it is bad code, considering, that it is not written to be tail recursive. Maybe good to show the idea of fibonnaci numbers or a theoretically valid implementation. But hopefully people do not accept this kind of code, thinking, that because it gets the result in some simple cases and it was suggested by copilot, it must be the way to properly do things.
- phoenixreader 4y agoI got this: defmodule Fibonacci do def fib(0), do: 0 def fib(1), do: 1 def fib(n), do: fib(n - 1) + fib(n - 2) end
- AlchemistCamp 4y agoThanks for giving it a try and sharing the results, everyone! One other possible cause I thought of is that I did have the test file in my mix project already. If copilot looks at the corresponding file in the test dir, then it would not be a coincidence at all that all function names were identical or that it wrote a tail recursive solution instead of the naive solution that would have failed the final test.
- Filligree 4y agoThat’s almost certainly the cause. This is copilot working as intended.