Initial thoughts on AI and GitHub Copilot
AI-powered coding tools like OpenAI, Chat GPT and Bing Chat have been a game changer for me in my work as a web/software developer. Instead of having to search through endless lines of code or fumble around trying to decipher an unfamiliar language from the original coder, I can use these AI systems to quickly piece together what’s going on — especially useful when dealing with new developers! With just a few functions pasted into one of these chatbots and then asking it explain them made understanding even difficult tasks easier than ever before!
Just when I thought AI couldn’t getcooler, along came GitHub Copilot! This AI-powered extension for Visual Studio Code harnesses the OpenAI Codex to predict code based on natural language and what already exists out there – no need to reinvent the wheel. Whether it’s a single line or an entire block of code you’re after, all you have to do is prompt Copilot and let it work its magic. Guess what? It even works like a charm; check this example that hasn’t been modified at all for proof!
// Write me a WordPress function that sends an email to the ACF Options page field notification_email when a new post is published
function send_email_on_publish( $ID, $post ) {
$email = get_field('notification_email', 'option');
$subject = 'New post published';
$message = 'A new post has been published';
wp_mail( $email, $subject, $message );
}
This example would work however there is no action so it will never fire! Damn, let’s try and fix that. You will see below I asked for the action to be added and it delivered!
// Write me a WordPress function that sends an email to the ACF Options page field notification_email when a new post is published
function send_email_on_publish( $ID, $post ) {
$email = get_field('notification_email', 'option');
$subject = 'New post published';
$message = 'A new post has been published';
wp_mail( $email, $subject, $message );
}
// can you add the action here?
add_action( 'publish_post', 'send_email_on_publish', 10, 2 );
I think the email could do with some more detail as it is pretty uninformative right now.
// Write me a WordPress function that sends an email to the ACF Options page field notification_email when a new post is published
function send_email_on_publish( $ID, $post ) {
$email = get_field('notification_email', 'option');
// could you add the subject here and include the new post title
$subject = 'New post published: ' . $post->post_title;
// could you add the message here and include the new post title and link
$message = 'New post published: ' . $post->post_title . ' ' . get_permalink( $ID );
wp_mail( $email, $subject, $message );
}
// can you add the action here?
add_action( 'publish_post', 'send_email_on_publish', 10, 2 );
Now our email will include the post title within the subject line and message body. In addition to this, the link to the post is included in the message body which is quite helpful.
The second way you can use GitHub Copilot within VS Code is as an autocomplete tool. This one is harder to demonstrate but take the below block of code. This is a div
with a fontawesome icon however I’d like to add an inline element with the text “Feedback”. I started by typing <span
and it suggested the rest of the element including context aware class name and element content! Honestly, whilst this is a simple example, it is a very promising start!
Ultimately, this new integration has offered me an easier way to create the code I envision without having to put in additional hard work. With no metrics available to measure the exact impact of the tool, I’ll have to rely on my own observations and expectations. With these things in mind, I’m curious to see just how much more efficient I can become, and what results this newfound productivity will bring. Although nothing is ever certain, it’d be nice if a few other developers who come across this blog post decide to join me and test out the application themselves. It’s constructive feedback like that which will help shape how quickly we can make use of advanced coding technologies!
This article has been edited with the use of Jasper AI, content writing tool.