Content Developer II at Microsoft, working remotely in PA, TechBash conference organizer, former Microsoft MVP, Husband, Dad and Geek.
122725 stories
·
29 followers

Reviewing Code With GPT-4o, OpenAI’s New ‘Omni’ LLM

1 Share
AI

This week OpenAI gave us access to GPT-4o (“o” for “omni”), which aims to compete better in speech recognition and conversation. It’s is almost certainly a stronger LLM, too. But can it do a code review? I put it through some tests to find out.

To start with, I checked if it could do long multiplication:

This is correct, as you can confirm on any online calculator. Note that it doesn’t attempt to “work through” the result for you — it has just passed it to a calculator. The “view analysis” icon at the end basically confirms this. Finally! This has failed to work on previous models.

I have no personal interest in formal code reviews. Yes, sometimes a junior developer might actually demand one, but unit tests and pairing sessions will usually suffice in sanding away bad code practice. But a few mumbled comments can help indicate mild unease with code, without appearing to be imposing some kind of authoritarian order over easily rewriteable snippets. In short, a code review is more of a social interaction than anything. Focus on engineering issues, not code semantic detailing.

However, code reviews are a good LLM use case for developers. Here I’ll look at three different bits of code, each of which simply draws a box with a diagonal line. I’ll add problems and see how GPT-4o (via ChatGPT) reviews them.

Here we start with our simple diagonal line routine in C#:

using System; 

public class Program 
{ 
  public static void Main() 
  { 
    BoxWithDiagonalLine(5); 
    BoxWithDiagonalLine(6,1); 
    BoxWithDiagonalLine(6,-1); 
    BoxWithDiagonalLine(2); 
    BoxWithDiagonalLine(-1); 
  } 

  // Example 1
  public static void BoxWithDiagonalLine(int boxsize, int linepos = 0) 
  { 
    for(int i=0; i < boxsize; i++) 
    { 
      for (int j = 0; j < boxsize; j++) 
      { 
        if (j == linepos) Console.Write("x "); 
        else Console.Write("o "); 
      } 
      linepos++; 
      Console.Write("n"); 
    } 
    Console.Write("n"); 
  } 
}


You can throw this into https://dotnetfiddle.net/ (set the compiler to .NET 6 at least, though) and see the responses:

This is fairly simple, and relatively self-explanatory. An outer loop controls the rows, an inner loop places the “x” in the right place. The variable naming is minimal, but the code is short. There is a default value for the method to give a full diagonal line from top left to bottom right. Whereas we can move the start line position left or right, it doesn’t make much sense to have a negative boxsize. So we could improve it by turning the method parameter to an unsigned int. This would immediately stop the last example from even compiling. A wildly large linepos will not be visible, but it isn’t dangerous.

So far, there is little to comment on.

In the second example, I will replace the for loops with while loops:

// Example 2 
public static void BoxWithDiagonalLine(int boxsize, int linepos = 0) 
{ 
  int i = 0; 
  while(i++ < boxsize) 
  { 
    int j = 0; 
    while (j++ < boxsize) 
    { 
      if (j == linepos + 1) Console.Write("x "); 
        else Console.Write("o "); 
    } linepos++; 
    Console.Write("n"); 
  } 
  Console.Write("n"); 
}


Now this works, but deserves a slight eyebrow raise. By post-incrementing the loop variables (the ++ after the i and j mean the values are read first before they are increased by one) we save some space, but we need that ungainly linepos + 1 expression. A while  doesn’t express the beginning and end state quite so nicely as a for loop does — but we are not sliding into any madness.

We make one last change. We now have a variation that does the wrong thing. It tries to use linepos to control the outer loop:

//Example 3 
public static void BoxWithDiagonalLine(int boxsize, int linepos = 0) 
{ 
  while(linepos < boxsize) 
  { 
    int j = 0; 
    while (j++ < boxsize) 
    { 
      if (j == linepos + 1) Console.Write("x "); 
        else Console.Write("o "); 
    } 
    linepos++; 
    Console.Write("n"); 
  } 
  Console.Write("n"); 
}


In an unnecessary attempt to remove one loop variable, the box itself will no longer be complete — although it will work with the default value. In fact, this solves a different problem, always reliably finishing with a cross in the bottom corner.

This poor code could probably come about because the developer continued to use a while inappropriately.

So let’s summarize the way we can look at the different versions:

  • The first example is fine, but we could force the parameter to be positive. Although, it is not crystal clear what the code does without comments.
  • The second uses a while loop, which doesn’t quite have the certainty of a for loop. It also makes for an ugly expression to take into account the post-increment.
  • The third example is plain wrong, even though it gets the result right in the default case

What do we expect from an AI code review? First of all, I have given it no comments, so will it work out what the code does? Only the name of the method reveals this.

Here is GPT-4o response:


“Your code is functional and effectively generates a box with diagonal lines based on the provided parameters. However, there are a few improvements and edge cases to consider:

  1. Input Validation: Ensure that the box size is positive and greater than 1, since a box with a size less than 2 doesn’t make much sense.
  2. Handling linepos: Improve handling of diagonal positions to ensure the diagonals are correctly drawn when linepos is negative or greater than the box size.
  3. Code Readability: Add comments and improve variable naming for better readability and maintenance.”

So it kind of did understand what the code did — even if it thought the program drew “lines” not a “line”. This is still very good.

The code it suggested was the following:

// ChatGPT4o suggested code 
public static void BoxWithDiagonalLine(int boxSize, int linePos = 0) 
{ 
  if (boxSize < 2) 
  { 
    Console.WriteLine("Box size must be greater than 1."); 
    return; 
  } 

  // Adjust linePos if it's out of the box boundaries 
  if (linePos < 0) linePos = 0; 
  if (linePos >= boxSize) linePos = boxSize - 1; 
  for (int i = 0; i < boxSize; i++) 
  { 
    for (int j = 0; j < boxSize; j++) 
    { 
      if (j == linePos) Console.Write("x "); 
        else Console.Write("o "); 
    } 
    linePos++; 

    // Reset linePos if it goes out of the box boundaries 
    if (linePos >= boxSize) linePos = 0; 
    Console.Write("n"); 
 } 
 Console.Write("n"); 
}


Here are the results of putting this into dotnetfiddle.net:

I think most people would be happy with the size less than two guards. It also camel-cased the params nicely, as this is right for C#. Unfortunately, it missed the idea of changing the position to allow for the line to start lower down. And by resetting the linepos, we get that unfortunate error at the bottom of the second example.

However, as code review, it hit the right note.

More Examples

Let’s feed it the second example and see how it does. Let me pick out the interesting comments:


“The use of while loops is functional but could be less intuitive compared to for loops for such iterations.”


Excellent. This is exactly the right note.


“The condition j == linepos + 1 is used to determine where to place “x”. This works but can be made more intuitive by aligning with the index i.”


Again, this is good. It understands the difference between functionality and readability.

The produced code clamped the value of linepos, and rather oddly used the modulo function to change the value. But it ended up with the same result. It reverted to for loops, which is excellent.

Finally, let’s deliver the bad Example 3, and see how it fairs. Oddly, it didn’t spot the bug, but did suggest the following:


“Edge Cases:

– When linepos is negative, it works but may not be intended.”


This is an indication that it didn’t quite understand the code — although, again, I never explicitly stated what I was doing. So perhaps a wrapping line may have been a reasonable guess?

Conclusion

Overall, I was quite impressed with the nature and the delivery of the review. The code GPT-4o produced was less promising, but it did ok. There was no “great clomping foot of nerdism” in the criticism of the code; instead, it gently nudged the reader in a better direction.

This is perhaps not where I expected to end up — with a good attitude but slightly inaccurate code. However, I would be happy to let this review be seen by a nervous junior; in that respect it does a slightly better job than some humans.

The post Reviewing Code With GPT-4o, OpenAI’s New ‘Omni’ LLM appeared first on The New Stack.

Read the whole story
alvinashcraft
44 minutes ago
reply
West Grove, PA
Share this story
Delete

Rust <=> C++

1 Share
Mara Bos joins Phil and Timur. Mara talks to us about her work on the Rust evolution team and how she uses embedded Rust for drone flight controllers. We chat about some of the differences and similarities between C++ and Rust, and what the two languages can, and should, learn from each other.

News

Links





Download audio: https://traffic.libsyn.com/cppcast/CppCast-382.mp3
Read the whole story
alvinashcraft
44 minutes ago
reply
West Grove, PA
Share this story
Delete

Build a Generative AI App in C# with Phi-3-mini LLM and ONNX

1 Share

Microsoft recently released the new Phi-3-mini SLM (small language model), and I previously wrote about running Phi3 locally using Ollama. I’ve been exploring the world of hosting AI models in code lately, and this stuff is getting really interested. It turns out that among the tools to run AI models locally, there are developer tools […]

The article Build a Generative AI App in C# with Phi-3-mini LLM and ONNX appeared first on Build5Nines.

Read the whole story
alvinashcraft
45 minutes ago
reply
West Grove, PA
Share this story
Delete

Yet another reason to love Go: math/rand/v2

1 Share

With the recent explanation of how math/rand evolved into math/rand/v2 I got reminded why I first fell in love with Go. Design decisions are not always made to match what every body else is doing, but rather what is the better decision. By some definition of better that I happen to agree with.

While the blog post on math/rand/v2 goes into interesting details around different pseudo random algorithms, exciting optimizations, and how to generally update a widely used library (like the standard library) with new versions are all interesting it is really three other things that make me even more excited.

One of the first things that I appreciate is the openness in recognizing that the original math/rand library has several bad design decisions in it. And this is a tone in the whole article. Very appreciated and directly related to the next two things I'm excited about.

It might seem like a small thing but the fact that the new library recognizes that different pseudo random algorithms needs to be seeded in different ways, just like different crypto algorithms need to be seeded (with a key and other parameters) in different ways.

But the final thing is really the best; the removal of the Read method from any math/rand/v2 types since this introduces a risk of accidently using the weaker randomness in math/rand vs the cryptographically secure crypto/rand package. In my opinion this shows and amazing attention to detail and is definitely in the spirit of Go - prevent developers from accidently making mistakes.

Read the whole story
alvinashcraft
45 minutes ago
reply
West Grove, PA
Share this story
Delete

Build your next website in Swift

1 Share

Swift's result builders are a powerful language feature that let us create domain-specific languages right inside our Swift code. With a little thinking, this means we can actually create whole websites in Swift, with our code automatically being converted to valid, accessible Swift, and we can even sprinkle in a little SwiftUI magic to complete the effect.

Let's get to it…

Starting from scratch

For over 30 years, HTML has been a great language for describing the structure of web pages.

For example, we can write HTML like this:

<h1>Wise words</h1>
<p>"If you don't take risks, you can't create a future" - <em>Monkey D. Luffy</em> in <a href="https://en-wp.org/wiki/One_Piece">One Piece</a></p>

That has a heading, a paragraph of text with some emphasis, and a link to another page. But, what happens if we forget the closing </em> tag? Without it, web browsers will assume everything that follows should also be emphasized.

That's not what I intended, but it's easy to do because HTML is just a bunch of text.

But even if you write perfect HTML, there are other, bigger problems:

  1. How can you make sure your pages look the same on all browsers?
  2. How can you make your page adapt to different screen sizes, such as iPhone and iPad?
  3. How can you use more advanced UI elements such as dropdown menus, carousels, and accordions?
  4. Most importantly, how can you be sure your site is accessible to everyone?

Ultimately, all these boil down to one huge problem: most people don't have enough time to become experts in Swift and also experts in HTML.

And so I want to suggest that the answer is to not use HTML, or at least not directly. Instead, I would you like to propose that we use Swift to build our websites.

Introducing result builders

Back in 2019 when Apple announced SwiftUI there the usual What's New in Swift presentation. During that talk they showed the following HTML:


<html>
    <head>
        <title>Jess...


Read the whole story
alvinashcraft
6 hours ago
reply
West Grove, PA
Share this story
Delete

How to integrate continuous integration and deployment with WordPress on App Service

1 Share

Why use Continuous integration and deployment with WordPress?

 

CI/CD is a system that automates steps in software delivery. For WordPress developers, it means less manual work: once you push updates, the system automatically tests and deploys them. It's like having a assistant that not only speeds up your work but also checks for errors with each update, ensuring your WordPress site runs smoothly. This constant testing and feedback loop means you can fix bugs quickly and improve your site continuously without disrupting the live version. In short, CI/CD makes your development process faster, more efficient, and less error prone.

 

How to get started with Continuous integration and deployment in WordPress on App Service?

 

Note: This code integration feature is currently enabled with WordPress on App Service images having tags PHP 8.2 or greater. https://github.com/Azure/wordpress-linux-appservice/tree/main?tab=readme-ov-file#image-details

 

Part 1: Before integrating code with Git, it is important to decide which files to include. It is recommended that you keep track of a smaller number of files. For example, keeping track of files in wp-content/uploads is inefficient as it might contain large static files. Instead, files like these must be stored on blob storage. Another example is wp_config.php file, since this file contains separate settings for development and production environments.

You should also choose to ignore WordPress core files if you are not making any changes to them.

 

This is a simple .gitignore file to get you started: (ref: https://github.com/github/gitignore/blob/main/WordPress.gitignore)

 

*~ *.log .htaccess wp-content/uploads/ wp-content/upgrade/ wp-content/cache/ wp-content/backups/ wp-content/backup-db/ wp-content/blogs.dir/ wp-content/advanced-cache.php wp-content/object-cache.php wp-content/wp-cache-config.php sitemap.xml sitemap.xml.gz # WP Core /wp-admin/ /wp-content/index.php /wp-content/languages /wp-content/plugins/index.php /wp-content/themes/index.php /wp-includes/ /index.php /license.txt /readme.html /wp-*.php /xmlrpc.php # Configuration wp-config.php

 

 

Part 2: Downloading WordPress code from App Service

 

Step 1: Go to Kudu dashboard https://<sitename>.scm.azurewebsites.net/newui (Ref: Kudu Dashboard explained)

Step 2: Go to file manager and download the /site/wwwroot folder as a zip file

abhishekreddy_0-1716031377784.png

 

Step 3: Extract the zip file, use the gitignore file from step 1, and push it to your remote repository.

 

Part 3: Enabling CI/CD with GitHub

 

Step 1: Go to Deployment Center on your app service dashboard.

Step 2: From the Source dropdown, select ‘GitHub’

Step 3: Select the repository and the branch from step 2.

abhishekreddy_1-1716031377791.png

 

Step 4: Select ‘Add a workflow’ from the workflow options.

Step 5: Under ‘Authentication settings’, it is recommended that you select User-assigned authentication type.

Step 6: Click on Save

abhishekreddy_2-1716031377798.png

 

 

Support and Feedback 

In case you need any support, you can open a support request at New support request - Microsoft Azure. 
 For more details about the offering, please visitAnnouncing the General Availability of WordPress on Azure App Service - Microsoft Tech Community. 

 If you have any ideas about how we can make WordPress on Azure App Service better, please post your ideas atPost idea · Community (azure.com) 
 
or you could email us atwordpressonazure@microsoft.com to start a conversation. 

 

Read the whole story
alvinashcraft
6 hours ago
reply
West Grove, PA
Share this story
Delete
Next Page of Stories