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, a revolutionary AI tool that assists developers in writing code more efficiently. Trained on millions of lines of code, Copilot offers insightful suggestions, saving developers significant time. The video demonstrates how to use Copilot to write an application from scratch, highlighting its ability to identify patterns and accelerate development. Although not free, with a starting price of $10 per month, the tool is considered valuable for professional coders. The tutorial includes installing the extension for Visual Studio Code, using prompts and comments to guide code generation, and customizing HTML and JavaScript to create a simple calculator application. The video emphasizes Copilot's superiority over ChatGPT for coding tasks, as it provides immediate and accurate suggestions that seamlessly integrate into the coding process. Jeremy concludes by recommending GitHub Copilot for daily use and encourages viewers to like and subscribe for more informative content.

Takeaways

  • 🚀 **GitHub Copilot** is a revolutionary coding 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.
  • 💡 **Jeremy McPeak** demonstrates using GitHub Copilot to write an application from scratch, showcasing how it identifies patterns in code and reduces development time.
  • 🛒 **Codecanyon** is recommended as a marketplace for developers and programmers, offering solutions for web development, mobile apps, e-commerce, and more.
  • 💰 **GitHub Copilot** is not free; the cheapest plan costs ten dollars a month, but it provides value, especially for those who write code professionally.
  • 📥 To use Copilot, you must install an extension for your code editor and sign in with your GitHub account.
  • 🔄 **Copilot suggestions** can be cycled through using the Alt or Cmd key along with the bracket or square bracket keys for different options.
  • 📝 It utilizes comments within your code to understand what you want to achieve and provides code suggestions accordingly.
  • 🌐 **HTML and CSS** are used to create the user interface of a calculator application, with Copilot assisting in generating the necessary elements and styles.
  • 🔧 **Customization** is easy with Copilot, as it allows for changes in attributes and classes to fit the developer's specific needs.
  • 🔑 **Data attributes** are effectively used for event delegation, allowing for a more streamlined approach to handling button clicks in the calculator application.
  • 🌈 **Styling** is simplified as Copilot prompts developers with selectors and properties relevant to the current document, making it easier to apply styles.
  • 🛠️ **JavaScript** functionality is efficiently handled by Copilot, which aids in generating methods for a calculator object and setting up event delegation with minimal keystrokes.
  • ✅ **GitHub Copilot** is favored over ChatGPT for coding tasks due to its ability to offer more precise and immediately usable suggestions that integrate seamlessly into the code writing process.

Q & A

  • What is GitHub Copilot?

    -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 more efficiently.

  • How does GitHub Copilot assist in writing code?

    -GitHub Copilot assists by identifying patterns in your code and offering suggestions as you type. It can auto-generate code snippets, complete lines of code, and even suggest entire blocks of code based on the context and your coding style.

  • What is the cost associated with using GitHub Copilot?

    -GitHub Copilot is not free. The cheapest subscription plan is $10 per month. There is a free trial available, but it requires a GitHub account and a payment method to be on file. The trial period is 30 days, after which the service will charge the provided payment method if not canceled.

  • How can developers start using GitHub Copilot?

    -To start using GitHub Copilot, developers need to install an extension for their code editor. Once the extension is installed, they must sign in using their GitHub account. After signing in, they can begin receiving suggestions from Copilot as they write code.

  • How does GitHub Copilot utilize comments in the coding process?

    -GitHub Copilot can interpret comments to provide more specific suggestions. For instance, if a developer writes a comment indicating a desire to add a certain library or feature, Copilot will prompt the appropriate code to achieve that, making the development process more streamlined.

  • What is the role of data attributes in using GitHub Copilot?

    -Data attributes are used in HTML to store custom data private to the page or application. In the context of the script, they are used to differentiate between values and operators in the calculator application. Copilot recognizes these attributes and uses them to generate appropriate suggestions.

  • How does GitHub Copilot help in styling the application?

    -GitHub Copilot can suggest CSS rules that are relevant to the elements in the HTML document. It prompts developers with selectors and properties that can be used to style the application, making it easier to apply consistent styling without having to manually write all the CSS code.

  • What is the significance of using event delegation in the calculator example?

    -Event delegation is a technique in JavaScript where you attach an event listener to a parent element instead of the desired target elements. This reduces the number of event listeners and improves performance, especially when dealing with a large number of similar elements, like buttons in the calculator example.

  • How does GitHub Copilot assist in writing JavaScript for the calculator application?

    -GitHub Copilot helps in writing JavaScript by suggesting methods and logic based on the developer's input. It can prompt the creation of a calculator object with methods for adding numbers and operators, as well as evaluating expressions when the equal sign is clicked.

  • What is the advantage of using GitHub Copilot over other AI code generation tools?

    -Unlike other AI code generation tools that may require multiple prompts and adjustments to achieve the desired code, GitHub Copilot offers suggestions that fit more seamlessly into the developer's workflow. It provides a more interactive and integrated experience, making it easier to write and refine code.

  • Why is it important to add the JavaScript file to the HTML in the calculator example?

    -Adding the JavaScript file to the HTML is essential for the functionality of the web application. Without it, the browser will not be able to execute the JavaScript code that controls the calculator's behavior, such as responding to button clicks and performing calculations.

Outlines

00:00

🚀 Introduction to GitHub Copilot

Jeremy McPeak introduces GitHub Copilot, a tool that revolutionizes code writing by training on millions of lines of code. It acts as a virtual coding teammate, offering suggestions to speed up coding and save time. The video demonstrates writing an application from scratch using GitHub Copilot, highlighting its ability to identify patterns and reduce development time. Codecanyon is also mentioned as a marketplace for developers. GitHub Copilot offers a pair programming experience and requires an extension for code editors like Visual Studio Code. It's not free, with a cheapest plan at $10/month, but a free trial is available. The tool prompts for code as it's being written, and the user can cycle through different suggestions using keyboard shortcuts. The video also shows how to use comments to guide Copilot's suggestions.

05:02

🌐 Building a Calculator UI with Copilot

The video continues with constructing the user interface for a calculator application using HTML and Bootstrap. Copilot assists in generating HTML elements and attributes based on the current context. The presenter opts for event delegation over inline event handlers and uses data attributes to store information about calculator buttons. The process involves defining the calculator's display as an input element and organizing the buttons in a grid format. Copilot's suggestions are refined according to the pattern established in the code, differentiating between numeric values and operators, and applying appropriate classes for styling. The presenter also discusses adding a clear button with a distinct visual style to warn users of its function.

10:02

🎨 Styling the Calculator and Preparing for JavaScript

After establishing the HTML structure, the focus shifts to styling the calculator for better visual appeal. The video shows how to use inline CSS to style the calculator container, display, and buttons. Copilot prompts CSS rules that are relevant to the current document, suggesting properties like width, margin, and text alignment. The presenter chooses to right-justify the display and sets the button width and margin. The styling is then reviewed in the browser to ensure the layout appears as intended. With the UI complete, the video prepares to move on to JavaScript, indicating a plan to use object-oriented programming to handle calculator functionality.

15:03

🤖 JavaScript Implementation and Event Delegation

The final part of the video covers the JavaScript needed to make the calculator functional. An object-oriented approach is taken to create a calculator object with methods for adding numbers and operators, as well as evaluating the expression when the equal sign is clicked. Copilot assists in writing the JavaScript code, including prompting for methods and properties. The presenter discusses using event delegation to handle click events for all calculator buttons. The process involves checking data attributes to determine whether a button press is a number or an operator, then calling the appropriate method. After resolving a JavaScript error due to a missing script reference and a typo, the calculator is tested in the browser, confirming that it performs basic arithmetic operations as expected. The video concludes with the presenter's endorsement of GitHub Copilot for its efficiency and utility in daily coding tasks.

Mindmap

Keywords

💡GitHub Copilot

GitHub Copilot is an AI-powered coding assistant developed by GitHub. It analyzes millions of lines of code from various sources and provides real-time suggestions to developers as they write code. In the video, GitHub Copilot is showcased as a groundbreaking tool that significantly speeds up the coding process by offering insightful suggestions and identifying patterns in the code.

💡Code Editor

A code editor is a software application used by developers to write, edit, and manage source code for programming languages. In the video, code editors such as Visual Studio Code are mentioned as platforms where developers can install extensions to integrate GitHub Copilot and access its features.

💡Pair Programming

Pair programming is a software development technique where two programmers work together on the same code, typically sharing a single workstation. GitHub Copilot is described as offering a pair programming experience because it provides suggestions and assistance while developers write code, acting as a virtual coding teammate.

💡Event Delegation

Event delegation is a programming technique where a single event listener is attached to a parent element, instead of multiple listeners on individual child elements. In the video, event delegation is mentioned in the context of setting up event handling for user interactions in the calculator application being developed.

💡Data Attribute

A data attribute is an HTML attribute that allows developers to store custom data within HTML elements. In the video, data attributes are used to attach additional information to HTML elements, such as distinguishing between numeric values and operators in the calculator application.

💡Eval

Eval is a JavaScript function used to evaluate a string containing JavaScript code. In the video, the eval function is utilized within the calculator application to evaluate mathematical expressions entered by the user and display the result.

💡Object-oriented Programming

Object-oriented programming (OOP) is a programming paradigm based on the concept of objects, which can contain data and code to manipulate that data. In the video, OOP is mentioned in the context of organizing the calculator application's functionality into methods and properties within a JavaScript object.

💡External CSS

External CSS refers to a separate CSS file that is linked to an HTML document to style its elements. In the video, GitHub Copilot suggests using an external CSS file for styling the calculator application, demonstrating its awareness of best practices in web development.

💡Query Selector

Query Selector is a method in JavaScript used to select HTML elements based on CSS selectors. In the video, querySelector is mentioned in the context of retrieving elements from the DOM to manipulate them within the calculator application.

💡CDN (Content Delivery Network)

A CDN is a network of distributed servers that deliver web content to users based on their geographic location. In the video, Copilot suggests using a CDN to link external libraries like Bootstrap, demonstrating its knowledge of web development practices.

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, significantly cutting development time.

Jeremy McPeak demonstrates using GitHub Copilot to write an application from scratch.

Copilot identifies patterns in your code and suggests completions based on those patterns.

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

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

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

A free trial is available, but requires a GitHub account and a payment method on file.

Extensions for various code editors are available to integrate GitHub Copilot into your development environment.

In Visual Studio Code, an icon indicates whether the Copilot extension is active.

Copilot prompts developers with suggestions as they write code, which can be accepted or cycled through for alternatives.

Developers can use comments to guide Copilot on specific actions or code to generate.

Copilot can understand and use data attributes to generate code based on user preferences.

The tool can differentiate between numeric and operator buttons, applying appropriate classes and attributes.

GitHub Copilot is capable of generating an entire UI for a calculator application with minimal input from the developer.

It can also assist in writing JavaScript, providing object-oriented programming structures and methods.

Event delegation is set up easily with Copilot's guidance, handling click events for calculator buttons.

Despite its capabilities, GitHub Copilot may not always generate perfect code and may require manual adjustments.

In comparison to ChatGPT, GitHub Copilot provides a more integrated and efficient coding experience.

Jeremy McPeak highly recommends GitHub Copilot for developers, especially those who write code professionally.