Google Adds Code Generation To Bard
Written by Kay Ewbank   
Wednesday, 26 April 2023

Google has announced that its Generative Pre-trained Transformer (GPT) Bard now has the ability to generate programming code, and to debug and explain existing code.

There are a few AI code assistants out there - Copilot, Codex, Bayou and CodeWhisperer to name just the best known, but Google's Bard hasn't been promoted as such until now.

The initial launch version supports more than 20 programming languages including C++, Go, Java, Javascript, Python and Typescript. Developers will also be able to export Python code to Google Colab, and to get help writing SQL statements and functions for Google Sheets.

bardicon

The full list as reported by Bard when we asked what programming languages it knows was Python, JavaScript, Java, C++, Go, PHP, Ruby, Swift, Kotlin, Rust and Julia, and it can also generate code in other languages, including HTML, CSS, SQL, JSON, YAML and XML.

When we asked Bard how you can use it to help with coding, it said we could ask it to generate code, as an example

"you could ask me to generate a function that takes two numbers as input and returns their sum".

Another option was to ask Bard to debug code

"For example, you could ask me to find the error in a piece of code that is not working correctly."

bard1

You can also ask Bard to explain code. To test this out, we gave it some code from the extracts from Programmer's Python Async on process based parallelism elsewhere on the i-programmer website:

import multiprocessing
def myProcess():
    while True:
        pass
if __name__ == '__main__':
    p0=multiprocessing.current_process()
    p1=multiprocessing.Process(target=myProcess,
daemon=True) p2=multiprocessing.Process(target=myProcess,
daemon=False) p1.start() p2.start() print(p0.pid) print(p1.pid) print(p2.pid) print("ending")

and it responded with:

The code you have provided is a simple example of how to use the multiprocessing module in Python. The myProcess() function is a simple function that does nothing but loop forever. The if __name__ == "__main__": block is the main entry point for the program. In this block, we create two Process objects, p1 and p2. The p1 process is created with the daemon=True flag, which means that it will be automatically terminated when the main process exits. The p2 process is created with the daemon=False flag, which means that it will not be automatically terminated when the main process exits. We then start both processes and print their PIDs to the console. Finally, we print the message "ending" to the console.

I then tried it with some SQL, asking what was wrong with the query:

SELECT user_id, first_name, last_name, class, COUNT(*) AS total_students FROM students GROUP BY class HAVING class IN ('JSS1')

The answer correctly suggested that the query is missing a WHERE clause, as the HAVING clause is only used to filter the results of a GROUP BY query, but it cannot be used to filter the rows that are selected before the GROUP BY operation is performed. There was more detailed explanation, and the suggested improvement was:

SELECT user_id, first_name, last_name, class, COUNT(*) AS total_students FROM students WHERE class = 'JSS1' GROUP BY class

Some commentators have suggested that Bard's programming abilities aren't real, but based on my afternoon of testing, it's a lot better than that. The Bard site says that "Bard is still an early experiment, and may sometimes provide inaccurate, misleading or false information while presenting it confidently. When it comes to coding, Bard may give you working code that doesn't produce the expected output, or provide you with code that is not optimal or incomplete."

I'd recommend you sign up for the experimental version and try it out - Bard may surprise you. The age of AI coding assistance is here and Bard is the latest member. Will it soon be the age of the AI coder?

bardicon 

More Information

Google Bard Website

Related Articles

The Turing Test Is Past

Bing+GPT: This Is Not A Search Engine

Chat GPT 4 - Still Not Telling The Whole Truth

Google's Large Language Model Takes Control

Open AI And Microsoft Exciting Times For AI 

The Unreasonable Effectiveness Of GPT-3

AI Helps Generate Buggy Code

The Robots Are Coming - AlphaCode Can Program!

The Unreasonable Effectiveness Of GPT-3

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Important Conference Results
17/04/2024

The SIGBOVIK conference has just finished and its proceedings can be downloaded, but only at your peril. You might never see computer science in the same way ever again.



Angular and Wiz To Merge
27/03/2024

Two web development frameworks used at Google are merging. One, Angular is open source and widely known, while the other, Wiz, is an internal web framework developed and used by Google for some o [ ... ]


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Wednesday, 02 August 2023 )