Skip to content
OPQAI.
Sourced advanced / 💻 Coding

Develop a New Programming Language Feature with AI Code Generation

Job to be done: Develop a new programming language feature by leveraging AI code generation and iteration.

🇳🇬 Ways to use this in Nigeria

Ideas to get you started, adapt to your situation.

  • Student

    Generate Python code for a basic web scraper to collect data for a research project, using AI to handle initial syntax and logic.

  • 9-5 employee

    Develop a TypeSpec emitter to convert internal API schemas to OpenAPI JSON, speeding up documentation generation.

What you’ll get

You will learn how to use an AI coding assistant to help develop a new feature for a programming language, specifically by creating a new language emitter. This approach is useful when you want to rapidly prototype or build tools that require translating between different data formats or specifications, leveraging AI to handle the initial research and implementation.

Tools you need

  • Claude Code (paid): An AI coding assistant designed for code generation and iteration.
  • TypeSpec (free): A language and ecosystem for defining schemas and generating code or documentation.
  • atproto lexicon (free): A specification format used for defining data schemas in the AT Protocol.

Steps

  1. Define the project goal: Start by clearly stating what you want to achieve. In this case, the goal is to create a new language emitter for atproto lexicons using TypeSpec. The author’s initial prompt to Claude Code was:

    I want to explore the idea of making a proper idl language for writing atproto lexicons. It should compile to atproto lexicon definitions (so, json) and express the entirety of lexicon. It should also obviously disallow anything that s invalid in lexicon. I was thinking https://typespec.io/ might be a good starting point but I have not researched it deeply. I d like you to research how typespec works and whether it can serve this purpose at all. I m hoping to make this project as lean as possible in the sense that I don t want to maintain parsers or complex tooling etc. so piggybacking on a microsoft project sounds great in theory. I would suggest that you research this first and write up a detailed plan of how I d approach this before committing to anything. But you re welcome to try things too and experiment with them.

    You should see the AI begin to research the topic and formulate a plan.

  2. Research and plan with the AI: Allow the AI to research the necessary tools and documentation. The AI should download relevant specifications (like the atproto lexicon spec) and find documentation on how to create custom emitters for TypeSpec. It should then present a plan for implementation. You should expect to see a document outlining the AI’s research findings and a proposed implementation timeline and approach.

  3. Iterate on the AI’s plan: Review the AI’s proposed plan. While the direction might be correct, the specific syntax or approach might need refinement. The author notes that the initial syntax suggestions were not always optimal. You should be prepared to provide feedback or ask clarifying questions to guide the AI towards a better solution.

  4. Develop the emitter: Based on the refined plan, the AI will start generating code. This involves writing TypeSpec code to define the new language and creating an emitter that translates this into atproto lexicon JSON format. The process is iterative, often involving running tests to ensure correctness. You should see code snippets and potentially test cases being generated by the AI.

  5. Test and refine: Continuously test the generated code. The author mentions that the project was completed in a weekend, implying rapid iteration and testing. Use tests to identify errors or areas for improvement in the AI-generated code. You should aim to have a working emitter that can successfully translate TypeSpec definitions into valid atproto lexicon JSON.

Original source

This workflow is based on a blog post titled “my first week of vibecoding” by Dan Abramov, posted on his personal blog “underreacted” and shared on Hacker News. The author details his experience using an AI coding assistant to build a new tool.

Notes & variations

  • Free Tier Alternative: If Claude Code is not accessible due to cost, consider using other AI coding assistants like GitHub Copilot (which offers a free trial for individuals) or exploring open-source models run locally via tools like Ollama or LM Studio. These might require more setup and potentially higher initial data usage for model downloads.
  • Common Pitfall: Relying solely on the AI’s first output without testing or refinement can lead to errors. AI models can sometimes misunderstand instructions or generate suboptimal code. Always verify the output with tests and your own understanding.
  • Tip for Better Results: Enable iterative development by providing the AI with test cases or expected outputs. Running tests and feeding the results back to the AI helps it correct errors and improve the code more effectively, mimicking a human development cycle.

Keep going

More Coding workflows