StyleSpark: Analyzing and Matching Code to Iconic Programming Styles using GitHub Actions

StyleSpark: Analyzing and Matching Code to Iconic Programming Styles using GitHub Actions


This is a submission for the GitHub Copilot Challenge : New Beginnings



What I Built

StyleSpark is a productivity tool designed to help developers gain insights into their coding styles by analyzing their code snippets and matching them to the styles of iconic programmers. Specifically, it is a new GitHub Action that programmers can include in their workflows to inspire personal growth and improvement in coding practices by providing users with a fun and educational way to explore different programming styles. It leverages Llama 3 to analyze snippets from your GitHub repos to identify how your style compares to computing’s heroes! When it’s done, it will update your README with a snazzy badge powered by Shields.io, like this one:
StyleSpark

StyleSpark offers a unique interpretation of “new beginnings” in the context of productivity tools, encouraging developers to reflect on their coding habits and strive for continuous improvement.

In its initial release, I asked GitHub Copilot about the most influential programmers of all time and what it thought about their programming styles. As we stand on the shoulders of giants, it’s helpful to reflect on the people who got us here! This is the list of styles StyleSpark will compare your code to, and I hope to grow it in the near future.

No. Programmer Description Style Characteristics
1 Grace Hopper Compiler Pioneer Focus on readability, with extensive comments and descriptive names. Modular and structured for ease of maintenance. Known for COBOL, emphasizing readability and documentation.
2 Ada Lovelace First Programmer Focus on logical precision, algorithmic clarity, and mathematical elegance. Abstract, rigorous, and concise algorithms.
3 Linus Torvalds Creator of Linux Minimalist, performance-focused code with short, simple functions. Few comments, prioritizing efficiency and pragmatism.
4 Guido van Rossum Python Creator Code should be clear, simple, and easy to understand. Emphasis on readability and explicitness, with functions that do one thing well.
5 Donald Knuth TeX Creator Detailed documentation and mathematical rigor. Pedantic formatting with highly structured, well-documented algorithms.
6 Vint Cerf Father of the Internet Focus on modular, well-structured, and reusable components. Robust documentation and error handling with adherence to standards.
7 James Gosling Java Creator Object-oriented design with a focus on portability. Verbose syntax and clear separation of concerns.
8 Bjarne Stroustrup C++ Creator Code prioritizes efficiency and flexibility, with extensive use of object-oriented and generic programming features.
9 Ken Thompson UNIX Creator Simple, efficient code designed for quick execution. Modular design and focus on system-level efficiency.
10 Brian Kernighan C Co-author Clear, simple, and minimalistic code. Focus on small programs with precision and clarity.
11 Tim Berners-Lee Web Creator Clean, simple, and modular code designed for interoperability and following standards for web technologies.
12 Margaret Hamilton Software Engineering Pioneer Safety-focused, with extensive error handling and documentation. Prioritizes reliability in high-stakes systems.



Demo

You can try out StyleSpark by adding it to your project today! Since it is a GitHub action, adding it to your project and getting your own StyleSpark badge is simple!

Create a Workflow File: Add a new workflow file in your repository’s .github/workflows directory.

name: StyleSpark Analysis

on:
  push:
    branches:
      - main

jobs:
  analyze-code:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Run StyleSpark
        uses: kevinl95/StyleSpark@main
        with:
          FILE_EXTENSIONS: "py,java,js"
          COMMIT_CHANGES: "true"
          README_PATH: "README.md"
Enter fullscreen mode

Exit fullscreen mode

Here’s a breakdown of how you can configure StyleSpark:

FILE_EXTENSIONS: A comma-separated list of file extensions to analyze. For example, “py,java,js” will analyze Python, Java, and JavaScript files. This variable tells StyleSpark which types of files to include in the analysis.

COMMIT_CHANGES: A boolean value (“true” or “false”) that determines whether the changes should be automatically committed to the repository. If set to “true”, StyleSpark will update the README file with the badge indicating the matched programming style and commit the changes. If set to “false”, the changes will not be committed.

README_PATH: The path to the README file that should be updated with the badge. This variable specifies the location of the README file in your repository. For example, “README.md” indicates that the README file is located in the root directory of the repository.

Here are some screenshots of StyleSpark in action:

Console output with the text 'Guido van Rossum<br>
The provided Python code snippet is written in a clear and concise manner, following best practices for readability. It uses descriptive variable names, proper indentation, and logical structure to make the code easy to understand. This src aligns with Guido van Rossum's emphasis on simplicity, clarity, and ease of understanding in his own coding philosophy.<br>
'
StyleSpark prints the name of the programmer your style is closest to as well as provides a brief explanation as to why it selected them for your project.

Screenshot of GitHub.com showing that github-actions bot has committed a badge to README.md with the text StyleSpark - Guido van Rossum
StyleSpark has committed a badge to my README, showing the community that my style was most similar to that of Guido van Rossum



Repo

You can find the source code for StyleSpark in the following public GitHub repository:

Analyzing and Matching Code to Iconic Programming Styles using GitHub Actions


StyleSpark

Overview

StyleSpark is a GitHub Action that analyzes code snippets and matches them to the coding styles of iconic programmers. You’ll be able to get a snazzy badge for your repository- an example is above! By leveraging large language models (particuarly Llama 3), StyleSpark provides insights into which famous programmer’s style your code most closely resembles. Use this as a fun tool to explore computing’s heros, share a bit about your coding style with the community, or motivate yourself to change up how you write your code!

Features

  • Code Analysis: Analyzes code snippets to determine their stylistic attributes.
  • Style Matching: Matches code to the styles of iconic programmers such as Grace Hopper, Ada Lovelace, Linus Torvalds, and more.
  • Badge Generation: Automatically updates the README with a badge indicating the matched programming style.

Supported Programming Styles



Copilot Experience

Throughout the development process, GitHub Copilot was an invaluable assistant. Here are some ways I used Copilot:

  • Prompts: I used Copilot to generate initial code snippets by providing natural language prompts. For example, I asked Copilot to help me write a function to analyze code styles and match them to predefined styles. Copilot also guided me through validation errors and stack traces as I encountered them testing my new GitHub Action.
  • Edits: Copilot assisted in refining the code by suggesting improvements and catching potential errors. It was especially helpful when I created a rats nest of code to truncate inputs based on tokens when an early version of the action utilized GPT-2. It helped me understand where I had made errors and why I was getting bad output.
  • Autocomplete: Copilot’s autocomplete feature helped speed up the coding process by providing relevant code completions based on the context.
  • Model Switcher: I experimented with different models, primarily using GPT-4o with its expanded token window for writing code and finding that Claude 3.5 Sonnet was a great help writing text for the README and summarizing documentation.
  • Chat: I used Copilot’s chat feature to ask questions and get explanations about specific code snippets and concepts. It summarized documentation pages for libraries I utilized like GPT4All. Its opinion on the most influential programmers was also key to starting this project.

Overall, Copilot significantly enhanced my productivity and made the development process smoother and more enjoyable.



Conclusion

Building StyleSpark was an exciting and rewarding experience. The project not only helped me improve my coding skills but also provided a fun and educational tool for other developers. By analyzing and matching code to iconic programming styles, StyleSpark encourages developers to reflect on their coding habits and strive for continuous improvement by helping them see themselves in their heroes. The use of GitHub Copilot played a crucial role in the development process, making it more efficient and enjoyable.

I believe StyleSpark has the potential to positively impact the developer community by promoting personal growth and better coding practices. I look forward to seeing how other developers use and build upon this tool!



Source link
lol

By stp2y

Leave a Reply

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

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.