Member-only story

AI Titans: DeepSeek, Copilot, ChatGPT — Decoding the Best in Code Assistance

Emad Dehnavi
3 min readJun 20, 2024

--

Since the code language models are rising, as a developer I’m using them in a daily basis and today I did an experiment on my top 3:

  • DeepSeek
  • ChatGPT
  • GitHub Copilot

if you are not a Medium premium member, you can read it for free here.

I wrote a function that does not follow best practises, have performance issues, using redundant loop, bad variable naming, … a terrible code:

function maxNum(arr) {
if (arr.length === 0) {
return null;
}

let max = arr[0];
for (let i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}

for (let i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}

console.log("The max number is: " + max);
return max;
}

// Example usage
maxNum([3, 5, 1, 9, 2]);

And then used the same prompt to refactor it

Refactor this function to improve the performance and use best practises: My awful function

And here are the result from imo the worst to the best:

GitHub Copilot

Apart from the result of this experiment, I kind of disappointed many times when I used Copilot, and this time also disappointed me

GitHub Copilot

Few points why I didn’t liked it:

  • Throws an error for empty arrays, returning null is often more flexible and aligns with common JavaScript practices for handling missing values
  • Including logging inside the function can be seen as intrusive. Functions should generally avoid side effects like logging, making them more reusable and testable.

ChatGPT

Here is what ChatGPT come with:

ChatGPT

--

--

Emad Dehnavi
Emad Dehnavi

Written by Emad Dehnavi

With 8 years as a software engineer, I write about AI and technology in a simple way. My goal is to make these topics easy and interesting for everyone.

No responses yet

Write a response