Development Use Cases for AI

Mar 7, 2025

I've recently been thinking about AI a lot more (who hasn't?), but I struggle to find relevant use cases for it while developing software. What are the real world applications for AI in this space? I can only think of a few low-hanging fruit:

  • Writing inline documentation (e.g., method docstrings)
  • Writing unit tests (if you do that sort of thing; I don't)
  • Explaining legacy code that may be hard to parse
  • Developing one-off scripts in infrequently used areas; for example, writing a Bash script (or Windows batch file) to complete a one-time action

What other areas am I missing? If you write software, and you're currently using AI to assist you, in what ways are you putting it to use? I'd love to hear your thoughts.

6 Comments

Gary

2:04 PM on Mar 8, 2025
  • I imagine a LLM could provide really intelligent completion suggestions but it's going to have to be really fast to be useful.
  • I recently asked for a short Python script to be translated to a Bash script. The result looked correct but didn't work properly.
  • It generated some correct code for a non-linear optimization function in Javascript but I didn't use it.
  • I could imagine it helping find bugs. I think I saw a post on how Meta is using it for finding bugs and getting good results.
  • I saw that 95% of the code used in recent YC startups was automatically generated.
  • I also saw a post about including undetectable backdoors in generated code. Pretty scary.
  • I would truly hate having to debug a giant codebase that was machine generated.

Jonah

8:32 PM on Mar 8, 2025

Interesting points!

Gary

12:20 PM on Mar 17, 2025

Today I wanted a metric ruler for my phone. I'm terrible at judging the size of things and I figured a ruler on my phone might help. I looked for a few minutes for images but found nothing. So I asked chatgpt.com I would like Javascript code to generate a SVG of a metric ruler scale marked in centimeters with marks at millimeters. It should be able to generate images in horizontal or vertical orientation.

It responded with this Javascript code.

function generateRulerSVG(lengthCM = 10, orientation = 'horizontal') {
    const cmWidth = 10; // Width of each centimeter in pixels
    const mmWidth = cmWidth / 10; // Width of each millimeter
    const height = 50; // Height of the ruler
    const longTick = 40, mediumTick = 30, shortTick = 20; // Tick lengths

    let svgWidth = lengthCM * cmWidth;
    let svgHeight = height;

    if (orientation === 'vertical') {
        [svgWidth, svgHeight] = [svgHeight, svgWidth];
    }

    let svg = ``;

    for (let cm = 0; cm <= lengthCM; cm++) {
        let x = cm * cmWidth;
        let y = 0;
        let lineLength = longTick;
        let label = `${cm}`;

        if (orientation === 'vertical') {
            [x, y] = [0, cm * cmWidth];
            label = `${cm}`;
        }

        svg += ``;
        svg += label;

        for (let mm = 1; mm < 10; mm++) {
            let mmX = x + mm * mmWidth;
            let mmY = y + mm * mmWidth;
            let tickLength = mm % 5 === 0 ? mediumTick : shortTick;

            if (orientation === 'vertical') {
                svg += ``;
            } else {
                svg += ``;
            }
        }
    }

    svg += '';
    return svg;
}

// Example usage:
document.body.innerHTML += generateRulerSVG(15, 'horizontal');

You have to calibrate it by adjusting a single variable. I would have included that as a parameter but I'm not picky. It actually works!

Gary

12:36 PM on Mar 17, 2025

Oh, I see you filtered out the hmtl in the strings. Doh!

If you'd like to see it you can find it here: https://gb.cs.unc.edu/~gb/tmp/ruler/ruler.js

Jonah

7:30 PM on Mar 18, 2025

Very cool application!

Gary

8:19 PM on Apr 2, 2025

I have the following from OS-DPI/src/eval.js:

  exp = exp.replaceAll(/(?!])=/g, "==");

Safari versions before 17 complain that this regex is invalid syntax. Can you show me how to rewrite it so Safari 16 will accept it?

🤖:[flash] Okay, I understand the problem. Safari 16 (and possibly earlier versions) doesn't support negative lookbehind in regular expressions. The goal is to replace all single = characters with ==, but only when they are not preceded by =, <, >, or !.

Here's how we can approach this problem:

1. Understand the limitations:

We can't use negative lookbehind. Therefore, we need to match the characters before the = and then use a capturing group and conditional replacement.

2. Devise a solution using capturing groups and conditional logic:

The strategy here is to match either: * One of the forbidden characters =, <, >, ! followed by a = * Any other character or the beginning of the string followed by a single =

Then, in the replacement, we can use a conditional to only do the replacement of = to == when the first capturing group contains none of the forbidden characters.

3. Translate this to a regular expression and replacement string.

The regex will look like this: ([=<>!])=|=

4. Write the javascript code

function replaceEquals(exp) {
  return exp.replace(/([=<>!])=|=/g, (match, group1) => {
    if (group1) {
      return match; // If it's preceded by =, <, >, or !, keep the original match
    } else {
      return "==";  // Otherwise, replace with ==
    }
  });
}

5. Test the code

Let's consider a few test cases to make sure we have covered all possibilities:

  • x = 1 should become x == 1
  • x == 1 should remain x == 1
  • x != 1 should remain x != 1
  • x <= 1 should remain x <= 1
  • x >= 1 should remain x >= 1
  • === 1 should remain === 1
  • a=b=c should be a==b==c
  • a==b=c should be a==b==c

6. Putting it all together to produce the final answer

function replaceEquals(exp) {
  return exp.replace(/([=<>!])=|=/g, (match, group1) => {
    if (group1) {
      return match; // If it's preceded by =, <, >, or !, keep the original match
    } else {
      return "==";  // Otherwise, replace with ==
    }
  });
}

// Example Usage and tests (you can uncomment to run them)
let testString1 = "x = 1";
let testString2 = "x == 1";
let testString3 = "x != 1";
let testString4 = "x <= 1";
let testString5 = "x >= 1";
let testString6 = "=== 1";
let testString7 = "a=b=c";
let testString8 = "a==b=c";

console.log(testString1 + " becomes: " + replaceEquals(testString1));
console.log(testString2 + " becomes: " + replaceEquals(testString2));
console.log(testString3 + " becomes: " + replaceEquals(testString3));
console.log(testString4 + " becomes: " + replaceEquals(testString4));
console.log(testString5 + " becomes: " + replaceEquals(testString5));
console.log(testString6 + " becomes: " + replaceEquals(testString6));
console.log(testString7 + " becomes: " + replaceEquals(testString7));
console.log(testString8 + " becomes: " + replaceEquals(testString8));

This code avoids negative lookbehind, uses a capturing group, and then uses a conditional inside the replace function to apply the correct replacement logic. This should work correctly in Safari 16 and other older JavaScript environments.

Leave a Comment

Ignore this field:
Never displayed
Leave this blank:
Optional; will not be indexed
Ignore this field:
Both Markdown and a limited set of HTML tags are supported
Leave this empty: