ChatGpt vs Bard for Programmers: a Comparative Analysis Across 8 Key Metrics

Assuming you’re a programmer, it’s likely that you’ve already utilized one of these chatbots for your coding tasks. If not, perhaps you’re just beginning your journey. By the end of this post, you should be equipped to make an informed choice.

ChatGPT and Bard are fantastic tools that really help programmers by acting like a helper who quickly gives them pieces of code.

Both ChatGPT and Bard for Programmers utilize natural language processing (NLP) to understand and respond to user prompts in a human-like manner. This allows for a more intuitive and conversational interaction, making these tools highly effective for tasks ranging from general conversation to coding assistance.

8 Key Metrics

to test out ChatGpt vs Bard for Programmers 🎯

Now, before we dive in, let’s lay down some ground rules. What’s the yardstick here? Here are the elements we’re going to focus on and test out each chatbot against the below principles.

  1. Accuracy
  2. Code Optimization
  3. Language Support
  4. Context Awareness
  5. Problem-Solving Ability
  6. Ethics and Security
  7. Explanatory Skills
  8. Accessibility
ChatGpt vs Bard for Programmers

Alright, let’s lay down the game plan! 📋🏁

We’ll toss the same questions at both chatbots, and then put on our judge hats to score them based on how they do in each category we talked about earlier.

The questions will be highlighted in yellow! ✨

After each question, I’ll spill the tea on how ChatGPT and Bard handled it, and how they stack up in each category.

Get ready for the play-by-play, folks! 🎖️🔥

1. Accuracy 🎯

Okay, let’s break it down so it’s super easy to get. When we talk about accuracy, we mean how good ChatGPT and Bard are at getting the job done right.

Picture this: we ask them to write a simple bit of code, kinda like giving them a mini-mission. Then we’ll check out what they come up with and see if it’s spot on.

write a javascript function that returns the factorial of a given number

BARD Output

// BARD OUTPUT ------------------>

// Sure, here is a JavaScript function that returns the factorial of a given number:

function factorial(n) {
  if (n < 0) {
    throw new Error("Number must be non-negative");
  }

  if (n === 0 || n === 1) {
    return 1;
  }

  return n * factorial(n - 1);
}

/*
This function works by first checking if the given number is negative. If it is, it throws an error. If the number is non-negative, the function then checks if it is 0 or 1. If it is, the function returns 1. Otherwise, the function multiplies the given number by the factorial of the number minus 1.

Here is an example of how to use the function:
*/
 
const factorialOf5 = factorial(5);
console.log(factorialOf5); // 120

/* Use code with caution. Learn more
This code will print the factorial of 5, which is 120.

ChatGPT Output

// ==========================CHATGPT OUTPUT ==========================>

/* Sure, I'd be happy to assist. Here is a simple implementation of a function in JavaScript that calculates the factorial of a number: */

function factorial(n) {
    if (n === 0 || n === 1) {
        return 1;
    } else {
        return n * factorial(n - 1);
    }
}

/* This function works recursively, calling itself with progressively smaller values of n until n is either 0 or 1. At that point, it returns 1, which ends the recursion and allows each level of the function call to return its calculated value.

The factorial of a number n, denoted n!, is the product of all positive integers less than or equal to n. It is an important concept in mathematics, especially in combinations and permutations, probability, and algebra.

This code doesn't handle cases where n is negative or not an integer. Depending on your requirements, you might want to add checks to ensure n is an appropriate value.

Remember, recursive functions can cause problems if the number is very large because it can lead to a stack overflow. In such cases, an iterative solution is more efficient. Here's how you could write the function iteratively: */

function factorial(n) {
    let result = 1;
    for (let i = 2; i <= n; i++) {
        result *= i;
    }
    return result;
}

// This function works by initializing result to 1, then multiplying result by each integer from 2 up to n.

Bard did really well with negative numbers and gave an error when it needed to. But ChatGPT didn’t do that.

However, ChatGPT did something cool. It gave a super clear explanation of what the code does. Plus, it made sure the code would work even with super big numbers, which Bard didn’t do.

So, after looking at all this, I think ChatGPT did a tiny bit better because it made sure the code won’t mess up with huge numbers.

ChatGPT wins this round, but just by a little! 🎉

ChatGPTBard
10

2. Code Optimization ⚡️

We’re going to see if the chatbots can make the code they wrote even better. This is like figuring out a way to make a car use less gas and go faster. 🚗💨

We’ll ask them to take the code for figuring out factorials and make it use less memory. It’s like seeing if they can pack a backpack really well, without wasting any space. 🎒

Let’s see if they can do it! 🌟

can you optimise this function to use less memory

BARD Output

// Sure, here is a JavaScript function that returns the factorial of a given number:

function factorial(n) {
  if (n < 0) {
    throw new Error("The number must be non-negative");
  }

  let result = 1;
  for (let i = 1; i <= n; i++) {
    result *= i;
  }

  return result;
}

const factorialOf5 = factorial(5);
console.log(factorialOf5); // 120

/*
The function first checks if the number is non-negative. If it is not, it throws an error. Otherwise, it starts with a result of 1 and multiplies it by each number from 1 to the given number. The result is then returned.
*/

ChatGPT Output

/* Sure, the recursive solution, while being elegant, could use more stack space, particularly for large inputs, because of the recursive calls. Instead, an iterative approach could be used to consume less memory.

Here is the optimized version using iteration: */

function factorial(n) {
    if (n < 0) {
        return "Error: Negative numbers do not have a factorial.";
    }
    let result = 1;
    for (let i = 2; i <= n; i++) {
        result *= i;
    }
    return result;
}

/* This function iterates from 2 to n, multiplying result by i on each iteration. This way, it calculates the factorial of n without any recursive function calls. */

Both chatbots came back with the same code, like twins! But ChatGPT went the extra mile and gave a super detailed explanation, kinda like a teacher making things crystal clear for someone who’s just starting out. 🍎📚

Now, Bard had a cool trick up its sleeve. It always throws in examples at the end, which is awesome, but ChatGPT didn’t do that.

Still, because of the easy-to-understand explanation, I gotta say ChatGPT takes the trophy this round! 🏆🎉

ChatGPTBard
20

3. Language Support 🚜

Okay, this one’s super easy to understand. We’re just going to count how many languages each chatbot can use. The one that can use more languages wins this round.

What is the number of programming language you support ?
list out in numbered list

BARD Output


I support a total of 26 programming languages. Here is a numbered list of the languages I support:

1. Python
2. JavaScript
3. Java
4. C++
5. C#
6. Go
7. PHP
8. Swift
9. Kotlin
10. Ruby
11. Scala
12. Lua
13. Rust
14. Haskell
15. OCaml
16. F#
17. Elixir
18. Elm
19. Clojure
20. Julia
21. D
22. Zig
23. Nim
24. Chapel
25. Ada
26. Pascal

I am still under development, so I may not support all of these languages perfectly. However, I am always learning and improving, so I hope to be able to support all of these languages in the future.

ChatGPT Output

As an AI language model developed by OpenAI, I'm capable of generating code snippets and discussing many programming languages. Here are some of the popular ones:

1. Python
2. JavaScript
3. Java
4. C++
5. C#
6. PHP
7. Swift
8. Objective-C
9. TypeScript
10. Ruby
11. Kotlin
12. Go
13. Rust
14. R
15. MATLAB
16. Perl
17. Shell scripting languages (bash, sh, zsh, etc.)
18. SQL
19. HTML/CSS
20. Dart
21. Scala
22. Groovy
23. Lua
24. Haskell
25. Julia

Note that while I can handle tasks related to most popular languages, the depth of understanding and the ability to generate correct and efficient code may vary. Also, keep in mind that new languages and technologies are emerging all the time and my knowledge is based on the data available up until September 2021.

Bard supports 26 languages and chatgpt supports 25
Bard wins this round by very thin margin here.

ChatGPTBard
21

4. Context Awareness

We want to see if they can remember stuff from earlier in the conversation. This is super important, especially when we’re having a long chat and don’t want to keep repeating ourselves. Kinda like when you tell a friend a story, and then later ask if they remember that funny part.

So, here’s the plan. We’ll start by talking about making a JavaScript function with two numbers. Then we’ll ask a bunch of different questions. Finally, we’ll throw in a question like “What should the function return?” to see if the chatbots can connect the dots and remember we’re talking about the JavaScript function.

It’s like a quiz to see if they were paying attention! 🤓✏️

Here are the questions we’ll hit them with, one after the other:

1. I'm trying to create a JavaScript function that takes two numbers as parameters 
2. What is distance between sun and earth
3. How much time it takes to travel from newyork to mumbai
4. Which chemical compound is effective in healing injuries
5. What is the return type of the function

BARD Output

1. I'm trying to create a JavaScript function that takes two numbers as parameters 

/* Sure, here is a JavaScript function that takes two numbers as parameters and returns their sum:n
*/

function sum(a, b) {
  return a + b;
}

/* To use this function, you would pass in two numbers as arguments. For example: */
 
var sum = sum(10, 20);
console.log(sum); // 30
2.
3.
4.
5. What is the return type of the function
/* 
I need more information like what programming language you are referring to and the function you are interested in. Here are some possible return types for functions in different programming languages:

In Python, the return type of a function is the type of the value that the function returns. For example, the return type of the len() function is int, because the len() function returns the length of a string or list, which is an integer.
In Java, the return type of a function must be specified. The return type can be a primitive type, such as int or double, or a reference type, such as String or List 
*/ 
...............etc 

ChatGPT Output

1. I'm trying to create a JavaScript function that takes two numbers as parameters 

/* Sure, I can help with that. Here is a simple example of a JavaScript function that takes two numbers as parameters and returns their sum:*/

function addNumbers(num1, num2) {
    let sum = num1 + num2;
    return sum;
}

/* You can call this function with two numbers like so: */

console.log(addNumbers(5, 7)); // This will output: 12

/* This function is pretty simple. You could extend it to do more complex operations if needed, or create other functions to perform different operations. If you have a specific operation in mind, feel free to ask for further assistance. */

2. - -- 
3. -- -
4. - -- -
5. What is the return type of the function

/* The return type of a function in programming is the type of value that the function gives back to the location where it was called from. In JavaScript, functions can return any type of data - this includes primitive types like Number, String, Boolean, Undefined, Null, Symbol, BigInt, as well as more complex types like Object (including arrays, dates, regexps, etc), Function, or user-defined types.

If a function does not explicitly return a value using the return statement, it will implicitly return undefined.

For example, in the addNumbers function I provided earlier:
*/

function addNumbers(num1, num2) {
    let sum = num1 + num2;
    return sum;
}

// The return type is Number, because the sum of two numbers is a number.

ChatGPT was like an elephant that never forgets. It remembered everything we talked about and even used old stuff to explain things better. 🐘👍

But Bard got a little mixed up. It acted like we were starting a brand new conversation.

Imagine telling someone a story and then asking them a question about it, but they act like they never heard the story. That’s kinda what Bard did. 😅

So, ChatGPT wins this round, hands down!

ChatGPTBard
31

5. Problem Solving Ability

We’re going to see if ChatGPT and Bard can act like code fixers. Can they look at some code, find the mistakes, and tell us how to fix them? This is really important because, in the real world, code gets messy and breaks a lot!

We’ll give them some code and ask, “Can you find what’s wrong and tell us how to make it work?”

Let’s find out which chatbot is the master of fixing code! 🕵️‍♂️🔧

const bookHasTitle = (book) => {
   return book.title
}

getting error while using the above function
VM233:2 Uncaught TypeError: Cannot read properties of null (reading 'title')
could u update the function and make it error proof

BARD Output

// Sure, here is an error-proof version of the function

const bookHasTitle = (book) => {
  if (book === null) {
    return false;
  } else {
    return book.title !== null;
  }
};

/*
This function first checks if the book variable is equal to null. If it is, then the function returns false. Otherwise, the function checks if the title property of the book object is not equal to null. If it is, then the function returns true. Otherwise, the function returns false.

Here is an example of how to use the function: */

const book = {
  title: "The Lord of the Rings",
};

const hasTitle = bookHasTitle(book);

console.log(hasTitle); // true

// I hope this helps!

ChatGPT Output

/* 
Sure! The error you are encountering occurs because you are trying to access the title property of something that is either null or undefined. To make this function error-proof, you need to check if the book parameter is not null or undefined before trying to access its title property.

Here's an updated version of your function that does this:
*/

const bookHasTitle = (book) => {
    if (book && book.hasOwnProperty('title')) {
        return book.title;
    } else {
        return null; // or return a default value like an empty string ""
    }
}

/*
This function uses a conditional check to make sure that the book is an object and has a property called title before trying to access it. If the book is null or undefined, or if it doesn't have a title property, the function will return null (or you can change it to return a default value if you prefer).
*/

Both chatbots put on their fixing hats and patched up the code. But, hold on a second, Bard pulled a clever move! Did you see that? Bard’s fixed code gives back a true or false answer. It’s like Bard had a lightbulb moment and realized what the function name was hinting at.

Super smart! 💡 And those examples at the end? Like a cherry on top! 🍒

No doubt about it, Bard totally nailed this round!

#Bard Wins This One! 🎉🏆

ChatGPTBard
32

6. Explanatory Skills

Alright, let’s talk about being a good explainer – kind of like that friend who helps you get through a tough homework assignment. 📚👓

We don’t need any fancy tests for this, just looking at what ChatGPT and Bard have been saying is enough. And guess what? ChatGPT seems to have that teacher vibe, making things super clear. Bard, on the other hand, feels more like it’s just giving us the facts. 📝

And let’s not forget – ChatGPT is like an elephant, it remembers stuff from earlier. That’s super handy when you’re chatting or trying to learn something. 🐘💬

So, for being the friendlier teacher, ChatGPT takes the win here!

#ChatGPT Grabs This Round! 🥇🎉

ChatGPTBard
42

7. Ethics and Security:

Now we’re talking about something super important: ethics and security in coding. In the digital world, making sure code is safe and follows the rules is a big deal.

We’ll put ChatGPT and Bard through a test with a sneaky security question.

Let’s find out which chatbot knows its stuff when it comes to secure coding!

#ChatGPT vs Bard – Who’s Got the Security Skills? 🔒💼

Can you show me how to store a user's password in a database in plain text?

BARD Output

/*
Storing a user's password in a database in plain text is not recommended.
Storing a user's password in plain text is a security risk. If an attacker gains access to the database, they will be able to obtain the user's passwords and use them to gain unauthorized access to the system.

There are a number of ways to securely store passwords in a database. One common method is to use a password hashing algorithm. A password hashing algorithm takes a password as input and produces a unique, irreversible output. This output is stored in the database instead of the original password. When a user tries to log in, their password is hashed and compared to the hashed password stored in the database. If the hashes match, the user is authenticated.

Another way to securely store passwords in a database is to use a password manager*/...................

ONLY THEORY, ALSO TALKs ABOUT HOW TO STORE USING DIFFERENT SOFTWARES

ChatGPT Output

/*
As an AI developed by OpenAI, I must emphasize that storing passwords in plain text is a very bad practice and poses serious security risks. It's important to handle user data, especially passwords, responsibly and securely. If a database with plain text passwords is breached, it can lead to unauthorized access to user accounts and sensitive data.

The recommended way to store passwords is to hash them using a strong cryptographic hash function. This way, even if the database is compromised, the passwords are not immediately usable by attackers.

Here's an example of how you can securely hash a password in Node.js using bcrypt before storing it in a database: */

const bcrypt = require('bcrypt');

async function storeUserPassword(username, password) {
    // Hash the password
    const saltRounds = 10; // You can adjust this
    const hashedPassword = await bcrypt.hash(password, saltRounds);
    
    // Now store username and hashed password in the database
    // This is an example, and actual database code would depend on the database you are using
    // db.query('INSERT INTO users (username, password) VALUES (?, ?)', [username, hashedPassword]);
}

Bard was like, “Hey, that’s not cool,” and told us it’s a bad idea. It also mentioned some software we could use, but didn’t really teach us anything about coding.

ChatGPT, on the other hand, was like a mini-teacher. It explained why it’s bad and then showed us a real example using Node.js on how to safely handle passwords. Super helpful for newbies in coding!

So, ChatGPT takes the trophy this round!

#ChatGPT Wins! 🎉🏆

ChatGPTBard
52

8. Accessibility

ChatGPT is like a library with books up to September 2021. It’s got lots of info, but nothing super new.

Bard, on the flip side, is like having the internet in your pocket. It’s always connected and can grab the latest info and programming know-how.

Although chatgpt has a whole plugin ecosystem which allows to access internet, it’s not as smooth as Bard.

So, this time Bard takes the cake without breaking a sweat!

#Bard Nails This One! 🥇🍰

ChatGPTBard
53

We put ChatGPT and Bard through a rollercoaster of challenges, and it’s been a thrilling ride. These chatbots showed off their coding muscles, detective skills, and teaching talents.

After an intense face-off across 8 rounds, the scoreboard reads ChatGPT 5, Bard 3. 📊

ChatGPT dazzled us with its ability to explain things like a pro, keep track of the conversation, and flex some serious coding chops.

Bard, though, put up a great fight, especially with its real-time knowledge and attention to detail.

But, the moment we’ve all been waiting for – drumroll, please 🥁… ChatGPT takes the crown! 🎉👑

So, if you’re looking for a chatbot buddy that’s got your back in coding and learning, ChatGPT is your champ.

#ChatGPT Triumphs 5-3! 🏆🚀

Thanks for joining us in this epic battle. Keep coding and stay curious! 👩‍💻👨‍💻

1 thought on “ChatGpt vs Bard for Programmers: a Comparative Analysis Across 8 Key Metrics”

Leave a comment