GitHub Copilot - Patterns & Exercises
GitHub 🌟
en 🇬🇧
en 🇬🇧
  • Introduction
  • Contributing to the Project
  • General
    • Code completion
    • Comment to code
    • Code to comment
    • Quick Q&A
    • Regular expression
    • Language translation
    • Type hinting
    • Code to document
    • Object generation from structured data
    • Showing examples
  • Client Side Tips
    • Copilot snnipet handling
    • GitHub Copilot Shortcuts
    • Go to definition
    • Pin the files you need
  • Design Patterns
    • AI readable naming convention
    • Consistent coding style
    • High-level architecture first
    • Working on small chunks
    • Context-less Architecture
    • Eliminating a tiny OSS dependency
  • Collaboration
    • AI friendly documentation
    • Coaching on prompts
  • Test
    • Creating unit tests
    • Specify how to generate test code
    • Writing failure case first
    • Writing test cases in natural language first
    • Test only what is necessary
  • Refactoring
    • Writing test code before refactoring
    • Making the calculation part independent
    • Asking with open-ended questions
  • Archived
    • GitHub Copilot Patterns & Exercises Guide
    • Translations
      • German 🇩🇪
      • Spanish 🇪🇸
      • French 🇫🇷
      • Italy 🇮🇹
      • Japanese 🇯🇵
      • Portuguese 🇵🇹
      • Chinese 🇨🇳
Powered by GitBook
On this page
  • Description
  • Example
  • Exercise
  • Checklist for Further Learning
Edit on GitHub
  1. Design Patterns

Consistent coding style

Consistent coding style leads to better suggestions from GitHub Copilot.

Last updated 1 year ago

Description

Consistent coding style is crucial in software development, as it not only enhances code readability but also leads to better suggestions from GitHub Copilot. Indentation, tabs, naming conventions, comment writing, language-specific abbreviations, and many other areas of coding style. By adhering to a uniform coding style and pattern, developers find it easier to follow excellent coding practices.

Example

Here's a positive example of using clear function names and following the codebase pattern using snake_case:

def calculate_area(length, width):
    return length * width

Compare this with the inconsistent coding style below, where inappropriate function naming may lead to generic comments like "code goes here" from GitHub Copilot:

def calcSomething(l, w):
    # code goes here
    return

Exercise

  • Exercise 1: Practice writing functions using descriptive and consistent naming conventions.

  • Exercise 2: Analyze a code snippet and identify inconsistencies in coding style. Make necessary adjustments.

  • Exercise 3: Utilize GitHub Copilot to create a small project, observing how it responds to different coding styles.

Checklist for Further Learning

  • How does consistent coding style affect readability and maintainability of the codebase?

  • What communication is needed to enforce coding standards within a team or project?

  • How can GitHub Copilot assist in adhering to coding best practices? What behaviors does it promote or discourage?