Write Code With GitHub Copilot... and Why It's Better Than ChatGPT

Envato Tuts+
22 Jul 202317:01

TLDRJeremy McPeak from Envato Tuts+ introduces GitHub Copilot, an AI-powered coding assistant trained on millions of lines of code. The tool serves as a virtual teammate, offering code suggestions to accelerate development. In the video, Jeremy demonstrates how Copilot can identify patterns and auto-generate code snippets, significantly reducing coding time. He also discusses the tool's integration with Visual Studio Code and its extension, and provides a walkthrough of building a simple calculator application using HTML, CSS, and JavaScript with Copilot's assistance. The video concludes with a comparison between GitHub Copilot and ChatGPT, highlighting the former's efficiency and practicality for developers.

Takeaways

  • 🤖 GitHub Copilot is a groundbreaking tool that assists in writing code faster by providing insightful suggestions based on patterns it identifies in your code.
  • 📚 Trained on millions of lines of code, Copilot acts as a virtual coding teammate, enhancing the development process with its extensive knowledge base.
  • 🚀 To utilize Copilot, an extension must be installed in your preferred code editor, after which you sign in using your GitHub account to start receiving suggestions.
  • 💡 Copilot prompts developers with next steps as they write code, making it easier to follow a logical structure and complete tasks more efficiently.
  • 💻 The tool is not free, with the cheapest plan costing $10 per month, but it offers a 30-day free trial for users to evaluate its value.
  • 🔄 Users have the option to cycle through different suggestions by holding down the Alt or Cmd key and using the bracket keys, offering flexibility in choosing the desired code structure.
  • 📝 Comments within the code can be used to guide Copilot, allowing for more specific instructions on what the developer wants to achieve.
  • 🌐 Copilot understands the context of the current file and language, adjusting its suggestions to fit the developer's needs within HTML, JavaScript, and other languages.
  • 🎨 The tool can also assist in styling the application by providing relevant CSS selectors and properties based on the elements present in the HTML document.
  • 🔢 When creating interactive elements, such as a calculator, Copilot can help structure the UI and even suggest JavaScript methods for functionality like event delegation.
  • 🔄 Copilot's suggestions can be a starting point, but developers should always review and adjust the code to fit their specific requirements and ensure it works as intended.

Q & A

  • What is GitHub Copilot and how does it assist in writing code?

    -GitHub Copilot is a groundbreaking AI tool that has been trained on millions of lines of code from various programming languages and repositories. It acts as a virtual coding teammate, offering insightful suggestions to help developers write code faster and save valuable time by identifying patterns in the code.

  • Who is Jeremy McPeak and what is his role in the video?

    -Jeremy McPeak is the presenter in the video, associated with Envato Tuts+. He demonstrates how to use GitHub Copilot to write an application from scratch, showcasing its capabilities in identifying code patterns and reducing development time.

  • What is the purpose of Codecanyon mentioned in the video?

    -Codecanyon is mentioned as the ultimate marketplace for developers and programmers. It features solutions for web development, mobile apps, e-commerce, and more, allowing users to explore, build, and transform their projects with the resources available on the platform.

  • How does GitHub Copilot provide a pair programming experience?

    -GitHub Copilot offers a pair programming experience by providing suggestions as the user types their code. It actively participates in the coding process by predicting and offering code that the developer might want to use next, simulating a collaborative coding environment.

  • What are the costs associated with using GitHub Copilot?

    -GitHub Copilot is not free. The cheapest subscription plan is ten dollars a month. There is a free trial available, but it requires creating a GitHub account and providing a payment method. If the user does not cancel before the 30-day trial period ends, they will be charged.

  • How does one get started with using GitHub Copilot?

    -To start using GitHub Copilot, one must install an extension for their code editor—extensions are available for various editors. After installation, users sign in using their GitHub account. Once signed in, they can begin using Copilot, which will provide suggestions in the editor as they write code.

  • How does GitHub Copilot utilize comments in the code?

    -GitHub Copilot can be used with comments to specify what the developer wants to achieve. For instance, if the developer writes a comment about adding Bootstrap, Copilot prompts to include Bootstrap in the code. Comments can also be used to guide Copilot in generating specific code structures or including libraries.

  • What is the process of using data attributes in HTML to create buttons for a calculator application?

    -In the video, data attributes such as 'data-value' and 'data-operator' are used in HTML to define the functionality of calculator buttons. These attributes hold the value or operator associated with each button, allowing for easier manipulation of the calculator's state and enabling event delegation for handling button clicks.

  • How does GitHub Copilot assist in styling an HTML document?

    -GitHub Copilot can prompt developers with CSS selectors relevant to their HTML document when a style element is added. It suggests styles such as setting the width of a container, text alignment for the display, and button widths, making it easier to apply consistent styling across the application.

  • What is the approach for handling JavaScript in the calculator application created with GitHub Copilot?

    -The approach involves creating a calculator object using object-oriented programming principles. The object contains methods for adding numbers and operators to the display, as well as a method for evaluating the expression when the equal sign is clicked. Event delegation is set up to handle click events for all calculator buttons.

  • Why is GitHub Copilot considered more efficient than ChatGPT for writing code?

    -GitHub Copilot is considered more efficient for writing code because it provides immediate and contextually relevant suggestions as the developer types, fitting seamlessly into the coding process. Unlike ChatGPT, which might require multiple prompts and adjustments to achieve the desired outcome, Copilot offers a more streamlined and integrated coding experience.

Outlines

00:00

🚀 Introduction to GitHub Copilot

Jeremy McPeak introduces GitHub Copilot, a revolutionary AI tool that assists in writing code by offering suggestions based on patterns it identifies. It's trained on millions of lines of code and is designed to function as a virtual coding teammate. The video demonstrates using GitHub Copilot to write an application from scratch, showcasing how it can significantly reduce development time. Codecanyon is also mentioned as a valuable resource for developers. GitHub Copilot requires an extension for the code editor, such as Visual Studio Code, and a GitHub account to get started. The video also covers the process of installing and using the tool, including how to navigate its suggestions and customize the code writing experience.

05:02

🌐 Building a Calculator UI with GitHub Copilot

The video continues with the process of building a calculator user interface using GitHub Copilot. It details how to structure the HTML with a container, input element for the display, and rows for number and operator buttons. The use of data attributes and classes to differentiate between number buttons and operator buttons is explained. Copilot's ability to follow the pattern set by the developer and suggest corresponding HTML is highlighted. The video also demonstrates how to use comments to guide Copilot's suggestions and how to implement event delegation for button functionality.

10:02

🎨 Styling the Calculator and Preparing for JavaScript

This section focuses on adding style to the calculator application. It covers how to use the style element to define CSS rules that affect the layout and appearance of the calculator. The video shows how to use GitHub Copilot to suggest relevant CSS selectors and properties, such as setting the text alignment, button width, and margins. The process of refining the calculator's layout and visual appeal is discussed, emphasizing the ease with which Copilot can assist in generating the necessary CSS code.

15:03

🔧 Implementing JavaScript Functionality with GitHub Copilot

The final part of the video script describes the implementation of JavaScript functionality for the calculator application. It outlines the creation of a calculator object using object-oriented programming principles. The video demonstrates how to use GitHub Copilot to generate methods for adding numbers and operators to the display, as well as evaluating the expression when the equal sign button is clicked. Event delegation is set up to handle click events for the calculator buttons, and the use of data attributes to determine whether a button press corresponds to a number or an operator is explained. The video concludes with the integration of the JavaScript file into the HTML and a demonstration of the calculator's functionality, highlighting the efficiency and utility of GitHub Copilot in the development process.

Mindmap

Keywords

💡GitHub Copilot

GitHub Copilot is an AI-powered code completion tool developed by GitHub and OpenAI, designed to assist developers by providing suggestions for code as they type. In the video, it is highlighted as a groundbreaking tool that accelerates the coding process by predicting and auto-filling code based on the context of the project. The script uses GitHub Copilot to build an application from scratch, demonstrating its capability to save developers time and improve their workflow.

💡Codecanyon

Codecanyon is mentioned in the video as a premier marketplace for developers and programmers, where they can find a wide array of solutions tailored for web development, mobile apps, e-commerce, and more. It represents an essential resource for developers looking to enhance their applications with pre-built tools and scripts, aligning with the video's theme of utilizing advanced tools to optimize software development.

💡Pair programming

Pair programming typically involves two programmers working together at one workstation to accomplish programming tasks, where one, the 'driver', writes code while the other, the 'navigator', reviews each line of code as it is typed. The video likens GitHub Copilot to a virtual pair programming partner, offering real-time suggestions and corrections, which enhances coding efficiency and accuracy.

💡HTML

HTML, or HyperText Markup Language, is the standard markup language used to create web pages. In the video, HTML is used as the primary language for building a sample calculator application with GitHub Copilot, showcasing how the tool seamlessly integrates suggestions for HTML elements like doctype, head, and body as the developer types.

💡Bootstrap

Bootstrap is a free and open-source CSS framework directed at responsive, mobile-first front-end web development. It includes design templates for typography, forms, buttons, navigation, and other interface components. The script demonstrates using GitHub Copilot to quickly integrate Bootstrap into a project via a CDN, illustrating the AI's ability to understand the developer's intent and provide appropriate code snippets.

💡JavaScript

JavaScript is a programming language used primarily for creating interactive effects within web browsers. In the video, JavaScript is used to add dynamic functionalities to the calculator app, such as processing button clicks and performing arithmetic operations. The script discusses using GitHub Copilot to generate JavaScript code snippets, thereby aiding in quicker and more efficient coding.

💡Data attributes

Data attributes are special attributes used in HTML and JavaScript that allow developers to store extra information or metadata in standard HTML elements without other hacks such as non-standard attributes, extra properties on DOM, or Node.setUserData(). The video showcases how GitHub Copilot can suggest HTML code using data attributes for organizing the calculator's logic, demonstrating its utility in creating structured and functional web interfaces.

💡Event delegation

Event delegation is a JavaScript technique involving adding event listeners to a parent element instead of multiple child elements. This approach enhances performance and simplifies script logic. In the script, the presenter opts for event delegation to manage calculator button interactions, and GitHub Copilot assists by generating the necessary JavaScript code, showcasing the AI's capability to adapt to developer preferences and best practices.

💡CSS

CSS, or Cascading Style Sheets, is a style sheet language used for describing the presentation of a document written in HTML or XML. The video includes a segment where the presenter uses GitHub Copilot to suggest CSS properties to improve the appearance of the calculator, such as adjusting margins and widths. This demonstrates Copilot’s ability to not only assist with functionality but also with aesthetic aspects of web development.

💡Object-oriented programming

Object-oriented programming (OOP) is a programming paradigm based on the concept of objects, which can contain data, in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods). In the video, the presenter designs a calculator object using OOP principles to manage the calculator's operations, with GitHub Copilot generating the appropriate methods for addition, subtraction, and other operations.

Highlights

GitHub Copilot is a groundbreaking AI tool that assists in writing code faster by offering insightful suggestions.

It has been trained on millions of lines of code from various programming languages and repositories.

GitHub Copilot acts as a virtual coding teammate, saving developers valuable time.

Jeremy McPeak demonstrates using GitHub Copilot to write an application from scratch, identifying patterns in code to reduce development time.

Codecanyon is a marketplace for developers offering solutions for web development, mobile apps, e-commerce, and more.

GitHub Copilot provides a pair programming experience by offering real-time suggestions as code is typed.

The service is not free, with the cheapest plan costing ten dollars a month, but a free trial is available.

To use Copilot, an extension must be installed in the code editor of choice and requires a GitHub account sign-in.

Visual Studio Code users can see an icon indicating if the Copilot extension is active.

Copilot prompts developers with suggestions for the next line of code based on the current context.

Developers can cycle through different options by holding down the Alt or Cmd key and using bracket keys.

Copilot can understand comments and use them to guide code suggestions, tailored to the language in use.

The tool can generate HTML elements and attributes based on the context and patterns it identifies in the code.

Custom data attributes and classes can be used to refine Copilot's suggestions to fit specific needs.

Copilot follows the pattern of data-value and data-operator attributes to structure the calculator's UI.

The tool can automatically assign appropriate CSS classes based on the context, such as 'danger' for clear buttons.

Inline CSS can be added directly to the HTML document, with Copilot prompting relevant selectors and styles.

JavaScript functionality can be outlined in comments, with Copilot generating the corresponding code.

Event delegation is set up with a few keystrokes, leveraging Copilot's understanding of data attributes for event handling.

GitHub Copilot is favored over ChatGPT for writing code as it provides more direct and accurate suggestions.

Jeremy McPeak emphasizes that GitHub Copilot will be a daily tool for him due to its efficiency and practicality.