2 ms·
Copilot is limited to short snippets. You can't just ask it to write a HTTP server. Also I don't see how having copilot generate the code for listening on a ser
by charcircuit 4y ago
Copilot is limited to short snippets. You can't just ask it to write a HTTP server. Also I don't see how having copilot generate the code for listening on a server socket is any better than when I copied how to do it out of a man page. Copilot doesn't add anything new, you've always been able to look up the documentation or look up how other people approach the problem.
The fibonacci example doesn't make much sense either due to how trivial it is. Without copilot you are just copying from the definition of the function and with it copilot copies it for you. The other algorithms that follow are both online and probably in their textbook.
- johndough 4y agoCopilot can almost write an HTTP server. Here is how I did it: 1. Start a new python file with the line "# This is an implementation of an HTTP server" 2. Press autocomplete a bunch of times and stop somewhere when "enough" libraries are imported 3. Press "#" and let it autocomplete the comment about what comes next (global variables for PORT and BUFFER_SIZE in my case) 4. Again, Press "#" and let it autocomplete a bunch of comments and functions ("get_file_extension", "get_file_content_type", "get_file_size" in my case) 5. At this step, I had to cheat a bit since it was generating too many "get_*" functions, so I started a comment with "# Initialize" and let it autocomplete again to get "init_server_socket" 6. From here on, it generated handle_request, parse_request, get_file_path and send_response automatically. 7. Lastly, I wrote "def main" and let it autocomplete again. This produced an HTTP server which almost worked. I just had to fix a small issue with "file_path", since it expected that files were stored in the root directory, but I wanted it to load files from the local directory. The code is not great since it does not handle most errors gracefully and is vulnerable to directory traversal, but I didn't even have to think about the HTTP protocol while writing it, so it is still quite impressive. A few good points: It generated a huge selection of MIME types which I probably would have had to look up by hand. The generated server is multi-threaded! It automatically reuses the socket, so I do not have to wait a minute every time I restart the server. Here is the final code: https://bpa.st/CTRA https://bpa.st/CTRA