Coding Frameworks and languages are no longer the point, prompting is

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Community Hub.

copilot.png
You've spent years training as a software developer and learned a variety of different skills like:

- breaking down problems
- debugging
- architecting
- specific frameworks, languages and IDEs

and yes communication.

Now you live in 2023 and suddenly your world looks very different, ChatGPT happened and suddenly, over night, everyone is an author and coder and whatever else profession.

As a coder, you've always been an early adopter of tools to make you faster, but with AI, how fast is fast and in what way?

Let's explore some common problems you're likely to do, and let's see what GitHub Copilot is able to do for us:
 
References

 
Task - work with console

It's quite common to build apps that only work on the console and print to it and reads user input from it. So let's craft a prompt that does just that:

 C# and .NET
 
// show me C# code how to read from the console and print it out result: using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { Console.WriteLine("Enter your name: "); string name = Console.ReadLine(); Console.WriteLine("Hello " + name); } } }

If you know C#, you know that nowadays you can type a lot less like so:
Console.WriteLine("Enter your name: "); string name = Console.ReadLine(); Console.WriteLine("Hello " + name);​
So I guess human - AI, 1-0, in this example, even if the win is that my focus moves from cleaning up after AI rather than typing every single key.

Java

What about a similar prompt for Java?
 
// show me Java code how to read from the console and print it out import java.util.Scanner; public class App { public static void main(String[] args) throws Exception { System.out.println("Hello, World!"); Scanner scanner = new Scanner(System.in); System.out.println("Enter your name: "); String name = scanner.nextLine(); System.out.println("Hello " + name); scanner.close(); } }

Great, I don't need to look up the APIs, I can now focus on seeing if it works and fix it if needed.

Python
 
# show me python code how to read from the console and print it out import sys print(sys.stdin.read())​
If this was a language comparison you would probably think Python has the least amount of code. However, the point here is more that Copilot is able to produce code even here and it can.

In conclusion

What we've seen so far is that Copilot can deliver on three different languages without breaking a sweat. Lets look at different type of task next.

Task - Making a web request, fetch and store a file

For this one, we wanted to do something a bit more challenging, making a qeb request, fetch google.com's logo and store it. It's not a very hard task but being a developer, you might still need to check the docs for what the APIs are called and how to call them.

So lets see what Copilot can do..

C#
// show me C# code how to make a web request to google.com, fetch its logo using System; using System.Net; using System.IO; namespace ConsoleApp1 { class Program { static void Main(string[] args) { WebRequest request = WebRequest.Create("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"); WebResponse response = request.GetResponse(); Stream data = response.GetResponseStream(); string fileName = Path.GetFileName(request.RequestUri.AbsolutePath); string filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName); using (FileStream fileStream = File.Create(filePath)) { byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = data.Read(buffer, 0, buffer.Length)) > 0) { fileStream.Write(buffer, 0, bytesRead); } } } } } ​as usual, we see that we can shorten this code a bit using modern C#
// show me C# code how to make a web request to google.com, fetch its logo using System; using System.Net; using System.IO; WebRequest request = WebRequest.Create("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"); WebResponse response = request.GetResponse(); Stream data = response.GetResponseStream(); string fileName = Path.GetFileName(request.RequestUri.AbsolutePath); string filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName); using (FileStream fileStream = File.Create(filePath)) { byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = data.Read(buffer, 0, buffer.Length)) > 0) { fileStream.Write(buffer, 0, bytesRead); } } ​​

I see Copilot knows what the current URL is, great, I don't need to look that up.

It also helped me by identifying I need to use a class called `WebRequest` (I could have almost guessed the name there).

Also, I see that it helps show me how to construct paths in an OS independent way.

Finally it opens up a file stream, reads a bunch of bytes and my file ends up getting stored. Yea, that's definitely code I would need to look up.

Java

Let's do the same exercise for Java
// show me java code how to make a web request to google.com, fetch its logo and store it as file logo.png import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; public class App { public static void main(String[] args) throws Exception { URL url = new URL("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"); URLConnection connection = url.openConnection(); InputStream inputStream = connection.getInputStream(); FileOutputStream outputStream = new FileOutputStream("logo.png"); byte[] buffer = new byte[2048]; int length = 0; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } inputStream.close(); outputStream.close(); } }


Seems the above is a similar approach to C#. This is code I don't have to write, or look up.
 
Python

Ok, for Python then..
 
import requests r = requests.get('https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png') with open('logo.png', 'wb') as f: f.write(r.content)​

Again, Python code is a lot less, but not the point of this article but it would be weird not to point it out. The point is still Copilot and that I save time not having to look up names of libraries, names of classes and functions etc.

Last task - zip a directory
For this final task, we'll look into how to compress a directory.
C#
// show me how to zip a directory of files using System; using System.IO; using System.IO.Compression; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string startPath = @"c:\example\start"; string zipPath = @"c:\example\result.zip"; string extractPath = @"c:\example\extract"; ZipFile.CreateFromDirectory(startPath, zipPath); ZipFile.ExtractToDirectory(zipPath, extractPath); } } }
 
and just like before, it seems to be trained on the "old" way of doing things. Leveraging modern C#, we can write it like so instead (yes human, you are providing value):
 
// show me how to zip a directory of files using System.IO; using System.IO.Compression; string startPath = @"c:\example\start"; string zipPath = @"c:\example\result.zip"; string extractPath = @"c:\example\extract"; ZipFile.CreateFromDirectory(startPath, zipPath); ZipFile.ExtractToDirectory(zipPath, extractPath);

Ok, seems like the above could work.
 
Java
// show me how to zip a directory of files import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class App { public static void main(String[] args) throws Exception { String sourceFile = "C:\\Users\\jason\\Desktop\\test"; FileOutputStream fos = new FileOutputStream("C:\\Users\\jason\\Desktop\\test.zip"); ZipOutputStream zipOut = new ZipOutputStream(fos); File fileToZip = new File(sourceFile); zipFile(fileToZip, fileToZip.getName(), zipOut); zipOut.close(); fos.close(); } private static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut) throws Exception { if (fileToZip.isHidden()) { return; } if (fileToZip.isDirectory()) { if (fileName.endsWith("/")) { zipOut.putNextEntry(new ZipEntry(fileName)); zipOut.closeEntry(); } else { zipOut.putNextEntry(new ZipEntry(fileName + "/")); zipOut.closeEntry(); } File[] children = fileToZip.listFiles(); for (File childFile : children) { zipFile(childFile, fileName + "/" + childFile.getName(), zipOut); } return; } FileInputStream fis = new FileInputStream(fileToZip); ZipEntry zipEntry = new ZipEntry(fileName); zipOut.putNextEntry(zipEntry); byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zipOut.write(bytes, 0, length); } fis.close(); } }

Ok, a few more lines of code but it's probably quite fast when it runs.
 
Python

# zip all the files in a directory into backup.zip import zipfile import os with zipfile.ZipFile('backup.zip', 'w') as myzip: for file in os.listdir(): myzip.write(file)

Again it looks like a lot less to type with Python

> But I'm just saying this for everyone in the back, the number of code lines don't matter, performance do. In most languages you create abstractions that hides away complexity.

But yes, from an AI standpoint, it was able to deliver even here.

In conclusion

I've shown you three different examples so far, I didn't need to know either Python, Java or C#, or their APIs, to create what I needed. However, to fix it, if something needs fixing, I need to know how and that's where you as a developer comes in.

Summary

As a developer, you might feel a few different things seeing this. For me here's how I react:

- This is the biggest thing since auto complete, I don't want to code without it.
- I'm now a declarative programmer or "prompt engineer", or as a colleague of mine put it, Copilot is a toddler, it's very fast, and I need to control what it does :)

I also have questions like:
- What about refactoring code, can it do that? Great question, I will research that and present the finding in a future article
- Can I finally get rid of Stack Overflow? Maybe, you can definitely have it generate code AND ask it questions, for instance I learned yesterday how to use CMake, it wrote config files, showed me commands etc, all in the IDE.
- How correct is it and is my job now clean up after an AI "clean up in aisle 5"? It looks that way, a little bit at least.
- And maybe the biggest question of all, do I dare use it, or will the legal department stop it? So there's a few things to know here that hopefully answers that questions namely:

    - Copilot (or rather Codex) was trained only on publicly accessible code
    - If you're using Copilot for Individuals, AND you have the setting that allows us to use your usage to improve the model, we may use information about the request (which will include some code), the suggestions given, and whether you accepted them, and possibly a few other things. We **don't** use that data to retrain the core codex model (which is owned by OpenAI), just improve the way we're making suggestions.
    - if you're using Copilot for Business, OR you've turned that setting off, we only use that request to generate a response for you, then we immediately throw it away. In fact it never hits the disk - it's only kept in memory and is garbage collected soon after.
    - Copilot builds a context to send to the server and get a response. That context is made up of a bunch of things -  like relevant code in open files, maybe some folder structure, metadata about what you'd just written, etc

 Read more on the official FAQ page, https://github.com/features/copilot#faq

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.