Coding with AI

Zed screenshot

I’ve never been enthusiastic about the AI revolution.

However, this week, I started using Zed.dev together with their AI assistant integration. I’m surprised by the experience and efficiency gains. I still have reservations, but it can be valuable allies in tackling programming challenges and routine tasks.

For example, a few days ago, I was working on a tool that needed to parse ClickHouse explain output1, an easy task requiring recursively transverse all the properties looking for some specific properties.

With a simple prompt, the model wrote a working version.

Write code to extract all primary key granules from explain_result. An example of explain_result here:

{…}

def extract_primary_key_granules(explain_result):
    def traverse(node):
        granules = []
        if isinstance(node, dict):
            if 'Indexes' in node:
                for index in node['Indexes']:
                    if index.get('Type') == 'PrimaryKey':
                        granules.append({
                            'Keys': index.get('Keys', []),
                            'Initial Granules': index.get('Initial Granules', 0),
                            'Selected Granules': index.get('Selected Granules', 0)
                        })
            for value in node.values():
                granules.extend(traverse(value))
        elif isinstance(node, list):
            for item in node:
                granules.extend(traverse(item))
        return granules

    return traverse(explain_result)

# Example usage:
result = extract_primary_key_granules(explain_result)
for granule in result:
    print(f"Keys: {granule['Keys']}")
    print(f"Initial Granules: {granule['Initial Granules']}")
    print(f"Selected Granules: {granule['Selected Granules']}")
    print()

The task was relatively easy and I had to make changes and improve the initial code. Despite that, this saved me at least an hour of back-and-forth writing the function and running some tests to see if it worked as expected!

I started using Zed AI assistant with ChatGPT integration. A day after they released their own integration that I’m now testing together with Anthropic’s Claude model. I’m not even using Google for simple searches anymore.

Footnotes

  1. This is how a ClickHouse explain output looks like

@jrdi
Subscribe to the newsletter to keep you posted about future articles