7 practical ways ChatGPT and artificial intelligence can help software engineers to become more productive
Disclaimer: This post was not created using ChatGPT.
Table of contents
Record-breaking start of the new AI
ChatGPT is a new AI-powered chatbot that was launched as a prototype on November 30, 2022. Immediately after its launch the chatbot attracted an incredible number of users due to its ability to provide answers to questions from a wide variety of domains. In this post we will look into practical applications of the new chatbot for software engineers and talk about AI’s weak points.
Practical applications
1. Quickly get information on a wide range of technical topics
Compared to Google Search results, ChatGPT really shines when you need to get general and brief information about technology, algorithms, software, etc. Instead of providing you with millions of pages of links, which is exactly what search engines like Google do, the chatbot provides ready to use answers on one page. Also, unlike search engines that show ads in search results, the chatbot does not show any ads at least for now.
Let’s look at a few examples.
Getting help with AWS lambda
Let’s pretend that I received a task to write a AWS lambda function that processes data coming from AWS SQS message queue service. I have never worked with AWS lambda. So first, I will ask the chatbot to explain what AWS lambda is.
Query:
What is AWS lambda?
Response:
Amazon Web Services (AWS) Lambda is a serverless compute service that runs your code in response to events and automatically manages the underlying compute resources for you. With AWS Lambda, you can run code for virtually any type of application or backend service, all with zero administration.
AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second. You pay only for the compute time that you consume - there is no charge when your code is not running. This makes it an attractive option for building cloud-based applications as it can help to reduce costs and complexity.
AWS Lambda supports a variety of programming languages, including C#, Go, Java, Node.js, PowerShell, Python, and Ruby. You can use Lambda to build a variety of applications, including web and mobile backends, data processing pipelines, and serverless applications.
Okay, this gives me some idea about what AWS lambda is. Now I want to find out how to trigger the AWS lambda function from SQS. So I ask the chatbot my next question.
Query:
How to trigger AWS lambda function from SQS?
Response:
You can trigger an AWS Lambda function using an Amazon Simple Queue Service (SQS) queue as the event source. When you set up an SQS queue as an event source for a function, you specify the queue and the batch size that you want to use. Then, when new messages arrive in the queue, AWS Lambda reads them in batches and invokes your function with the batch as input.
To set up an SQS queue as an event source for an AWS Lambda function, you can follow these steps:
1. Open the AWS Lambda console and select the function that you want to add the event source to.
2. In the designer view, under the "Add Triggers" section, select "SQS" from the dropdown menu.
3. In the "Configure triggers" page, choose the existing SQS queue that you want to use as the event source. You can also create a new queue from this page.
4. Specify the batch size that you want to use. This is the number of messages that AWS Lambda will read from the queue and pass to your function in a single batch.
5. Click "Add" to create the trigger.
That's it! Now, whenever new messages arrive in the SQS queue, AWS Lambda will automatically invoke your function with the batch of messages as input. You can then process the messages as needed in your function code.
This makes sense, but I would like to automate my configuration using a CloudFormation template. So I will ask the chatbot to help me with this.
Query:
How can I do this using a CloudFormation template?
Response:
You can use an AWS CloudFormation template to create an Amazon Simple Queue Service (SQS) queue and set it up as an event source for an AWS Lambda function.
Here is an example of a CloudFormation template that creates an SQS queue, a Lambda function, and an event source mapping that associates the queue with the function:
---
Resources:
MyQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: my-queue
MyFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: my-function
Runtime: python3.8
Code:
ZipFile: |
def handler(event, context):
print(event)
Handler: index.handler
MyEventSourceMapping:
Type: AWS::Lambda::EventSourceMapping
Properties:
EventSourceArn: !Ref MyQueue
FunctionName: !Ref MyFunction
BatchSize: 10
---
This template creates an SQS queue named "my-queue", a Lambda function named "my-function" written in Python, and an event source mapping that associates the queue with the function. The event source mapping also specifies a batch size of 10 messages.
To create the resources defined in this template, you can use the AWS CloudFormation `create-stack` or `update-stack` command. For example:
---
`aws cloudformation create-stack --stack-name my-stack --template-body file://template.json`
---
This will create a new CloudFormation stack named "my-stack" and create the SQS queue, Lambda function, and event source mapping defined in the template.
Perfect, this is exactly what I was looking for! Now I have a template and empty function that I can use to start working!
Implementing a single sign-on feature for ASP.NET web application
After a quick and successful implementation and deployment of the lambda function, my career is going up and I received... drumroll please... a well deserved promotion. Nope. Instead of a promotion, I was assigned to work on another task: implement a single sign-on for our ASP.NET application. I will ask the chatbot to help me with this.
Query:
How does single sign-on work?
Response:
Single sign-on (SSO) is a method of authentication that allows a user to access multiple applications with a single set of login credentials. With SSO, a user logs in once to a central authentication server and is then able to access all of the applications that they are authorized to use, without having to authenticate separately for each application.
Here's how SSO works:
1. The user attempts to access an application that is configured for SSO.
2. The application redirects the user to the SSO login page.
3. The user enters their login credentials (e.g., username and password) on the SSO login page.
4. The SSO authentication server validates the user's credentials and, if they are correct, generates a signed token.
5. The signed token is sent back to the user's browser, along with a list of the applications that the user is authorized to access.
6. The user's browser sends the signed token to each of the authorized applications, along with a request to access the application.
7. Each application verifies the signed token and, if it is valid, grants the user access to the application.
With SSO, users only need to remember a single set of login credentials, and they can access all of their authorized applications without having to authenticate separately for each one. This can make it easier for users to access the applications they need and can also help to improve security by reducing the number of passwords that users need to remember.
Okay, now I need to understand how to implement it in my application. Another question to the AI.
Query:
How to implement single sign-on in ASP.NET application?
Response:
To implement single sign-on (SSO) in an ASP.NET application, you will need to use a third-party SSO solution or build your own SSO server. Here are the general steps to implement SSO in an ASP.NET application:
1. Choose an SSO solution or build your own SSO server. There are many different SSO solutions available, including commercial products and open-source options. You can also build your own SSO server using ASP.NET and a library such as OAuth or OpenID Connect.
2. Configure your ASP.NET application to use the SSO solution. This will typically involve adding a reference to the SSO library, setting up the SSO server as an identity provider, and modifying your application's authentication and authorization code to use the SSO solution.
3. Set up the SSO server. This will involve creating a database to store user accounts and application permissions, configuring the SSO server to use the database, and setting up the SSO server to handle login requests from your application.
4. Test the SSO implementation. Make sure that the SSO server is working correctly and that your application is able to authenticate and authorize users using the SSO solution.
Here is an example of how you might modify an ASP.NET application to use an SSO server built with OAuth:
---
// Add a reference to the OAuth library
using OAuth;
// Modify the application's authentication code to use the SSO server
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
string token = Request.Headers["Authorization"];
if (string.IsNullOrEmpty(token))
{
return;
}
// Validate the token with the SSO server
TokenInfo tokenInfo = OAuthManager.ValidateToken(token);
if (tokenInfo == null)
{
// Token is invalid
return;
}
// Token is valid - create a new identity and set it as the current user
GenericIdentity identity = new GenericIdentity(tokenInfo.Username, "SSO");
GenericPrincipal principal = new GenericPrincipal(identity, null);
Context.User = principal;
}
---
This code adds a reference to the OAuth library and modifies the application's `Application_AuthenticateRequest` method to validate the authorization token sent by the client with the SSO server. If the token is valid, it creates a new identity and sets it as the current user for the application.
There are many more details involved in implementing SSO in an ASP.NET application, and the exact steps will depend on the SSO solution you are using. You may need to consult the documentation for your SSO solution or search online for additional guidance.
Okay. This is enough to get me started.
Understanding HTTP/3 protocol
Now, I have another technical question. I heard about a new HTTP/3 protocol and would like to understand how it works and what are the benefits. Let’s ask the AI for help.
Query:
How does HTTP/3 protocol work?
Response:
HTTP/3 is the third major version of the Hypertext Transfer Protocol (HTTP), a protocol used to transfer data over the internet. It is based on the earlier HTTP/2 protocol, but it uses a different underlying transport layer: instead of using TCP as the transport, HTTP/3 uses the newer QUIC (Quick UDP Internet Connections) protocol.
QUIC is a multiplexed and secure transport protocol that runs over UDP (User Datagram Protocol). It provides many of the same benefits as TCP, such as reliability, congestion control, and flow control, but it also has some additional features that can improve performance. For example, QUIC allows for faster connection establishment and improved congestion control by using forward error correction and retransmission mechanisms.
Like HTTP/2, HTTP/3 uses multiplexing to allow multiple requests and responses to be in flight at the same time, reducing the need for connection overhead. It also supports header compression and server push, which can improve the efficiency of HTTP traffic.
Overall, HTTP/3 is designed to improve the performance and security of the HTTP protocol, particularly over lossy and high-latency networks. It is still a relatively new protocol, and support for it is not yet widespread, but it is expected to become more commonly used in the future.
Okay. This is good enough for this moment. I can get to this topic later when I actually need to work with this.
Looking up available frameworks for Samsung Smart TV
Now, imagine that our company received a request to create an application for Samsung Smart TV and no one has experience creating such applications. I was invited to an impromptu meeting to discuss how to build an application for TVs and did not have much time to prepare. I need to quickly understand which frameworks and programming languages are available for these devices. Let’s ask the AI.
Query:
Which programming languages and technologies can be used to create applications for Samsung Smart TVs?
Response:
To create applications for Samsung Smart TVs, you can use the following programming languages and technologies:
- Tizen: Tizen is an open source operating system that is used on a wide range of devices, including Samsung Smart TVs. Tizen provides a flexible and powerful platform for creating applications. It supports the following programming languages: C, C++, and JavaScript.
- Samsung Smart TV SDK: The Samsung Smart TV SDK is a toolkit that allows developers to create applications for Samsung Smart TVs using HTML5, CSS3, and JavaScript. The SDK includes an emulator and a set of libraries and tools that make it easy to develop and test applications on a personal computer.
- Other technologies: In addition to Tizen and the Samsung Smart TV SDK, you can also use other technologies to create applications for Samsung Smart TVs. For example, you can use web technologies such as HTML5, CSS3, and JavaScript to create web-based applications that run on the TV's web browser. You can also use other programming languages and frameworks, such as Python, Java, or C#, to create applications that run on the TV.
It's worth noting that the specific technologies and programming languages that you can use to create applications for Samsung Smart TVs may vary depending on the model and version of the TV. It's always a good idea to check the documentation and developer resources provided by Samsung to determine which technologies are supported on a particular TV model.
Okay. This is very brief but gives me a quick overview of technologies that are available.
Figuring out differences between Rust and C
Now, imagine that I am building an embedded application. I heard about a relatively new programming language Rust and want to understand how it is different from C. Let’s see what is the difference between Rust and C.
Query:
What is the difference between Rust and C?
Response:
Rust and C are both programming languages that are commonly used for systems programming. However, they have a number of differences in terms of their design and features. Here are some of the main differences between Rust and C:
- Memory safety: One of the main differences between Rust and C is that Rust is designed to be a memory-safe language, while C is not. In C, it is the responsibility of the programmer to manually manage memory and avoid common pitfalls such as buffer overflows and null pointer dereferences. In Rust, the compiler enforces memory safety by tracking the ownership and lifetimes of variables at compile time. This can help prevent many types of memory-related bugs.
- Concurrency: Rust also has a number of features that make it easier to write concurrent and parallel code. For example, Rust has a lightweight threading model and a borrowing and ownership system that makes it easier to write concurrent code without the need for locks or other synchronization primitives. In contrast, C does not have any built-in support for concurrency, so concurrent programming in C can be more difficult and error-prone.
- Syntax: Rust and C have similar syntax, but there are some notable differences. For example, Rust uses snake case (e.g., `my_function()`) for function and variable names, while C uses camel case (e.g., `myFunction()`). Rust also has a number of additional syntax elements, such as pattern matching and anonymous functions (called "closures"), that are not present in C.
- Compatibility: Another difference between Rust and C is that C has a much longer history and is more widely used, so it has a larger ecosystem and is more widely supported on different platforms. As a result, it can be easier to integrate C code with other systems and libraries. In contrast, Rust is a newer language and has a smaller ecosystem, although it is growing rapidly.
Overall, Rust and C are both powerful programming languages that are well-suited for different types of tasks. Rust is particularly good for projects that require memory safety, concurrency, and high performance, while C is more suitable for projects that need maximum compatibility and portability.
Okay. From this response, it is clear that it makes sense to learn more about Rust programming language since the new application can benefit from it.
2. Get answers to coding questions
Explaining regular expressions
While doing a security code review and reading some very old code created by engineers that are no longer with a company I ran into a regular expression. It is the end of the day, I am getting tired and I would not mind getting some help with understanding the purpose of this expression. Let’s see if the chatbot can help with this.
Query:
Explain .NET regular expression: ^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*
Response:
The regular expression `^[\w!#$%&'*+\-/=?\^_`{|}~]+(.[\w!#$%&'*+-/=?^_`{|}~]+)*` is a pattern used to match and validate email addresses. Here is an explanation of how it works:
- `^`: This character signifies the start of the string.
- `[\w!#$%&'*+\-/=?\^_`{|}~]+`: This pattern matches one or more characters that are either alphanumeric (i.e.,` \w`) or any of the special characters listed inside the square brackets (i.e.,` !#$%&'*+-/=?^_`{|}~`). These characters are allowed in the local part of an email address (i.e., the part before the `@` symbol).
- `(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*`: This pattern matches zero or more instances of a period (i.e.,` .`) followed by one or more characters that are either alphanumeric or any of the special characters listed inside the square brackets. These characters are allowed in the domain part of an email address (i.e., the part after the` @` symbol).
- `$`: This character signifies the end of the string.
Together, this regular expression will match and validate email addresses that have the following general form: `local-part@domain`. The local part and the domain can contain any combination of alphanumeric characters and the special characters listed in the pattern. The domain must contain at least one period (e.g., `example.com`), and the local part must be at least one character long.
For example, the following email addresses would all be considered valid by this regular expression: `user@example.com`, `user123@example.com`, `user.name@example.com`. On the other hand, the following email addresses would be considered invalid: `@example.com`, `user@`, `user@.com`.
It's worth noting that this regular expression is intended to be used with the .NET framework's regular expression engine. The syntax and behavior of regular expressions can vary slightly between different programming languages and regular expression engines, so it's always a good idea to test and verify the behavior of a regular expression before using it in a production environment.
Okay this is helpful. I can save my brain power and time for more important tasks.
Finding a bug in a code
Here is another example. As I was writing a C# function to extract product information from an HTML page, I made a mistake. Let’s see if the AI can help to identify it.
Query:
Find and fix a bug in a function:
private static string GetProductTitle(IHtmlElement document)
{
var titleElement = document
.SelectNodes("//span[@id=\"title\"]")
.FirstOrDefault();
var title = titleElement.TextContent.Trim();
return title;
}
Response:
One possible bug in the function `GetProductTitle` is that it may throw a `NullReferenceException` if the `titleElement` variable is `null`. This can happen if the `SelectNodes` method returns an empty list, or if the `document` parameter is `null`.
To fix this bug, you can add a null check to ensure that `titleElement` is not `null` before accessing its `TextContent` property:
---
private static string GetProductTitle(IHtmlElement document)
{
var titleElement = document
.SelectNodes("//span[@id=\"title\"]")
.FirstOrDefault();
if (titleElement != null)
{
var title = titleElement.TextContent.Trim();
return title;
}
else
{
return string.Empty;
}
}
---
Alternatively, you can use the null-coalescing operator `??` to return an empty string if `titleElement` is `null`:
---
private static string GetProductTitle(IHtmlElement document)
{
var titleElement = document
.SelectNodes("//span[@id=\"title\"]")
.FirstOrDefault();
var title = titleElement?.TextContent.Trim() ?? string.Empty;
return title;
}
---
It's also a good idea to add a null check for the `document` parameter to ensure that it is not `null` before calling the `SelectNodes` method:
---
private static string GetProductTitle(IHtmlElement document)
{
if (document == null)
{
return string.Empty;
}
var titleElement = document
.SelectNodes("//span[@id=\"title\"]")
.FirstOrDefault();
var title = titleElement?.TextContent.Trim() ?? string.Empty;
return title;
}
---
This will ensure that the function handles `null` input gracefully and does not throw a `NullReferenceException`.
It found the problem. The code will fail if the document does not contain the element. It is worth pointing out that the AI indicated a few potential problems with this code and such feedback can be very helpful for junior developers.
Now I want to implement lazy loading in a .NET application. Let’s ask the AI to explain how to do this.
Query:
Explain how to implement lazy loading using .NET Entity Framework and show a few examples.
Response:
Lazy loading is a technique in which data is loaded on demand, or when it is needed, rather than being loaded upfront.
To implement lazy loading in the .NET Entity Framework, you will need to enable lazy loading by setting the `LazyLoadingEnabled` property of your `DbContext` to `true`. You can then use the `virtual` keyword to mark navigation properties on your entity classes as lazy-loadable.
Here's an example of how you might implement lazy loading using the .NET Entity Framework:
---
public class MyDbContext : DbContext
{
public MyDbContext()
{
this.Configuration.LazyLoadingEnabled = true;
}
public DbSet<Employee> Employees { get; set; }
}
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
// This navigation property will be lazy-loaded
public virtual ICollection<Order> Orders { get; set; }
}
public class Order
{
public int Id { get; set; }
public string Description { get; set; }
public int EmployeeId { get; set; }
// This navigation property will be lazy-loaded
public virtual Employee Employee { get; set; }
}
---
To load the orders for an employee, you can use the following code:
---
using (var context = new MyDbContext())
{
// Load an employee and their orders
var employee = context.Employees
.Include(e => e.Orders)
.FirstOrDefault(e => e.Id == 1);
// The orders will be lazy-loaded when they are accessed
foreach (var order in employee.Orders)
{
Console.WriteLine(order.Description);
}
}
---
Alternatively, you can use the `Load` method to explicitly load a lazy-loadable navigation property:
---
using (var context = new MyDbContext())
{
// Load an employee without their orders
var employee = context.Employees
.FirstOrDefault(e => e.Id == 1);
// Load the orders for the employee
context.Entry(employee)
.Collection(e => e.Orders)
.Load();
// The orders will now be available
foreach (var order in employee.Orders)
{
Console.WriteLine(order.Description);
}
}
---
Again, the chatbot gave a clear and brief answer.
The chatbot can also help to format code. Here is an example of formatting a simple select statement:
Query:
format this code:
select Order.Number, sum(OrderDetail.Price * OrderDetail.Quantity) as OrderTotal from Order join OrderDetail on Order.OrderID = OrderDetail.OrderID where Order.Date > '2022-12-01' group by Order.Number
Response:
Here is the formatted version of the code:
---
SELECT Order.Number,
SUM(OrderDetail.Price * OrderDetail.Quantity) AS OrderTotal
FROM Order
JOIN OrderDetail
ON Order.OrderID = OrderDetail.OrderID
WHERE Order.Date > '2022-12-01'
GROUP BY Order.Number
---
3. Explain complex technical concepts using simple terms
As a software engineer, I often need to answer technical questions in a way that people without a strong background in the informational technology field can understand. The chatbot helps me with this by providing ready-to-use answers that can be then tweaked depending on the level of a particular person that is asking a question.
Here are a few examples.
Comparing Apple AirTags with GPS trackers
Let’s ask the chatbot to explain how Apple AirTags work and how they compare to GPS trackers.
Query:
Explain how Apple AirTags work
Response:
Apple AirTags are small, circular Bluetooth trackers that allow you to locate and track the location of items to which they are attached. They are designed to work with the "Find My" app on an iPhone, iPad, or iPod touch.
Here's how AirTags work:
1. Attach an AirTag to an item that you want to track, such as a backpack or a keychain.
2. Open the "Find My" app on your iPhone, iPad, or iPod touch, and select the AirTag from the list of devices.
3. The AirTag will begin sending its location to the "Find My" app, which will display its location on a map.
4. If the AirTag is within range of any of your Apple devices (such as an iPhone or iPad), it will communicate directly with those devices over Bluetooth. This allows you to track the location of the AirTag in real-time, even if it is not in range of a Wi-Fi or cellular network.
5. If the AirTag is not within range of any of your Apple devices, it will use the location of nearby Apple devices (with their owners' permission) to determine its location. This location data is anonymous and encrypted, and it is not shared with anyone other than you.
6. You can set up notifications in the "Find My" app to alert you when an AirTag arrives at or leaves a location, such as your home or office.
7. You can also use the "Find My" app to place an AirTag into Lost Mode. This will cause the AirTag to emit a sound when it comes within range of an iPhone, iPad, or iPod touch that is signed in to iCloud and has the "Find My" app open. This can help you locate a lost item more easily.
I hope this helps! Let me know if you have any other questions.
Query:
Compare Apple AirTag and GPS tracker
Response:
Apple AirTags and GPS trackers are both devices that can be used to locate and track the position of an object or person. However, there are some key differences between the two:
1. Range: GPS trackers use satellite signals to determine their location, which means they can be used anywhere on the planet with an unobstructed view of the sky. In contrast, AirTags rely on Bluetooth to communicate with nearby devices, which means they have a limited range (typically around 100 meters or 330 feet).
2. Accuracy: GPS trackers are generally more accurate than AirTags, since they use satellite signals to determine their location rather than relying on Bluetooth communication with other devices. However, GPS accuracy can be affected by factors such as atmospheric conditions and the presence of tall buildings or other obstructions.
3. Battery life: AirTags have a replaceable battery that is designed to last for up to a year, depending on usage. In contrast, many GPS trackers have a built-in, rechargeable battery that may need to be charged more frequently.
4. Compatibility: AirTags are designed to work with the "Find My" app on Apple devices such as the iPhone, iPad, and iPod touch. GPS trackers, on the other hand, can often be used with a wider range of devices, including Android phones and tablets as well as laptops and desktop computers.
5. Cost: GPS trackers can vary significantly in price, depending on the features and durability of the device. AirTags, on the other hand, are priced at a premium, with a single AirTag costing $29.
Overall, both Apple AirTags and GPS trackers can be useful tools for tracking the location of an object or person. However, the choice between the two will depend on your specific needs and preferences, as well as your budget.
Figuring out how Google Search works
Now let’s ask the chatbot to explain how Google Search works.
Query:
Explain how Google search works.
Response:
Google search works by using automated programs called "web crawlers" to discover publicly available web pages and to index the content of those pages. When you enter a search query into Google, the search engine uses algorithms to match the keywords in your query to relevant pages in its index.
Here's a more detailed look at how Google search works:
1. Crawling: Google uses web crawlers to discover new pages and to update its index with the content of those pages. The crawlers follow links from page to page, and they visit billions of web pages every day.
2. Indexing: As the crawlers discover new pages, they extract the content of those pages and add it to Google's index. The index is a massive database of all the words and phrases that appear on the web, along with information about the pages where those words and phrases appear.
3. Ranking: When you enter a search query into Google, the search engine uses algorithms to rank the pages in its index based on how relevant they are to your query. The algorithms consider factors such as the relevance of the content on the page, the quality of the website, and the number and quality of external links pointing to the page.
4. Serving results: Once the algorithms have ranked the pages in the index, they return the top results to you, along with a list of sponsored results (if applicable). The results are displayed in a search engine results page (SERP), which includes the page title, a snippet of text from the page, and the URL of the page.
I hope this helps! Let me know if you have any other questions.
Explaining Google Search to a 7-year-old
We can even dumb down answers to make them easy to be understood by elementary-grade children.
Query:
Explain how Google search works to 7 year old.
Response:
Sure, here's a simplified explanation of how Google search works that might be easier for a 7-year-old to understand:
When you use Google to search for something on the internet, you're asking Google to help you find websites that might have information about what you're looking for. To do this, Google uses special programs called "robots" or "spiders" that crawl the internet and look at all the websites they can find. These robots read the words on each website and save them in a big database.
Then, when you search for something on Google, it looks at all the websites in its database and tries to find the ones that are most related to what you're searching for. It does this by looking at the words you typed in and trying to match them to the words it found on the websites in its database.
Finally, Google shows you a list of websites that it thinks are the most helpful. It puts the websites it thinks are the best at the top of the list, and the ones it thinks are less helpful at the bottom. You can click on any of the websites in the list to visit them and learn more.
I hope this helps! Is there anything else you'd like to know about how Google search works?
4. Extract data from text
The chatbot will help you with extracting data from text without writing a code.
Here is an example of extracting information about best selling products from Amazon in JSON format. https://www.amazon.com/Best-Sellers-Books/zgbs/books
Query:
Extract all available information in JSON format:
#1
Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones
Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones
James Clear
4.8 out of 5 stars 90,893
Hardcover
$11.98
24 pts
#2
Spare
Spare
Prince Harry The Duke of Sussex
Hardcover
$22.40
#3
Little Blue Truck's Christmas: A Christmas Holiday Book for Kids
Little Blue Truck's Christmas: A Christmas Holiday Book for Kids
Alice Schertle
4.8 out of 5 stars 15,560
Board book
$2.99
6 pts
#4
It Starts with Us: A Novel (It Ends with Us)
It Starts with Us: A Novel (It Ends with Us)
Colleen Hoover
4.5 out of 5 stars 64,497
Paperback
$10.98
22 pts
SpareThe House in the Pines: A NovelSam: A NovelNew Releases
in BooksIt Ends with Us: A Novel (1)It Starts with Us: A Novel (It Ends with Us)VerityBest Sellers in ${listName} for 2022
in Books
...
Response:
Here is the information extracted in JSON format:
[
{
"title": "Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones",
"author": "James Clear",
"rating": "4.8 out of 5 stars 90,893",
"format": "Hardcover",
"price": "$11.98",
"points": "24 pts"
},
{
"title": "Spare",
"author": "Prince Harry The Duke of Sussex",
"format": "Hardcover",
"price": "$22.40"
},
{
"title": "Little Blue Truck's Christmas: A Christmas Holiday Book for Kids",
"author": "Alice Schertle",
"rating": "4.8 out of 5 stars 15,560",
"format": "Board book",
"price": "$2.99",
"points": "6 pts"
},
...
Here is another example that shows how to extract actor names and their roles into a markdown table: Query:
Extract names and roles:
Cast
Macaulay Culkin as Kevin McCallister, a rambunctious eight-year-old with a penchant for creating harmful inventions
Joe Pesci as Harry Lyme, a short and hot-headed thief who targets the McCallisters' home with Marv
Daniel Stern as Marv Murchins, a tall and dim-witted thief who targets the McCallisters' home with Harry
John Heard as Peter McCallister, Kevin's father
Roberts Blossom as Old Man Marley, Kevin's elderly neighbor
Catherine O'Hara as Kate McCallister, Kevin's mother
Angela Goethals as Linnie McCallister, Kevin's older sister
Devin Ratray as Buzz McCallister, Kevin's oldest brother who often gets him into trouble
Gerry Bamman as Uncle Frank McCallister, Kevin’s paternal uncle and Peter's rude, cruel, cantankerous, cheap, and selfish older brother
Hillary Wolf as Megan McCallister, Kevin's oldest sister who seems to be the friendliest of his siblings.
John Candy as Gus Polinski, a polka musician who helps Kate
Larry Hankin as Officer Balzak
Michael C. Maronna as Jeff McCallister, Kevin's older brother
Kristin Minter as Heather McCallister, Kevin's oldest cousin
Daiana Campeanu as Sondra McCallister, Kevin's older cousin and the daughter of Frank
Jedidiah Cohen as Rod McCallister, Kevin's older cousin and the son of Frank
Kieran Culkin as Fuller McCallister, Kevin's youngest cousin and the son of Frank
Senta Moses as Tracy McCallister, Kevin's older cousin and the daughter of Frank
Anna Slotky as Brook McCallister, Kevin's younger cousin and the daughter of Frank
Terrie Snell as Aunt Leslie McCallister, Kevin's aunt and Uncle Frank's wife
Jeffrey Wiseman as Mitch Murphy, an eight-year-old neighbor of the McCallisters whom Heather mistakes for Kevin during the headcount
Virginia Smith as Georgette McCallister, Kevin's aunt, wife of Uncle Rob, and mother of Heather and Steffan
D. Danny Warhol (credited as Dan Charles Zukoski) as "Pizza Boy" (Pizza Delivery Boy)
Matt Doherty as Steffan McCallister, Kevin's older cousin
Ralph Foody as Gangster #1 (Johnny), a character in the film Angels with Filthy Souls
Michael Guido as Gangster #2 (Snakes), a character in the film Angels with Filthy Souls
Ray Toler as Uncle Rob McCallister, Kevin's uncle, younger brother of Peter and Uncle Frank, and father of Heather and Steffan
Billie Bird as Woman in Airport, Irene, who sells Kate her ticket to Dallas
Bill Erwin as Man in Airport, Ed, Irene's husband who agrees with Irene's ticket sale
Gerry Becker as Officer #1
Alan Wilder as Scranton Ticket Agent
Hope Davis as French Ticket Agent
Kenneth Hudson Campbell as a man in a Santa Claus suit whom Kevin meets
Jim Ortlieb as Herb, the drugstore clerk
| Actor Name | Character Name | Role |
|--|--|--|
Response:
Here is the list of names and roles extracted from the text:
Actor Name | Character Name | Role |
---|---|---|
Macaulay Culkin | Kevin McCallister | a rambunctious eight-year-old with a penchant for creating harmful inventions |
Joe Pesci | Harry Lyme | a short and hot-headed thief who targets the McCallisters' home with Marv |
Daniel Stern | Marv Murchins | a tall and dim-witted thief who targets the McCallisters' home with Harry |
John Heard | Peter McCallister | Kevin's father |
Roberts Blossom | Old Man Marley | Kevin's elderly neighbor |
Catherine O'Hara | Kate McCallister | Kevin's mother |
Angela Goethals | Linnie McCallister | Kevin's older sister |
Devin Ratray | Buzz McCallister | Kevin's oldest brother who often gets him into trouble |
Gerry Bamman | Uncle Frank McCallister | Kevin’s paternal uncle and Peter's rude, cruel, cantankerous, cheap, and selfish older brother |
Hillary Wolf | Megan McCallister | Kevin's oldest sister who seems to be the friendliest of his siblings. |
John Candy | Gus Polinski | a polka musician who helps Kate |
Larry Hankin | Officer Balzak | |
Michael C. Maronna | Jeff McCallister | Kevin's older brother |
Kristin Minter | Heather McCallister | Kevin's oldest cousin |
Daiana Campeanu | Sondra McCallister | Kevin's older cousin and the daughter of Frank |
Jedidiah Cohen | Rod McCallister | Kevin's older cousin and the son of Frank |
Kieran Culkin | Fuller McCallister | Kevin's youngest cousin and the son of Frank |
Senta Moses | Tracy McCallister | Kevin's older cousin and the daughter of Frank |
Anna Slotky | Brook McCallister | Kevin's younger cousin and the daughter of Frank |
Terrie Snell | Aunt Leslie McCallister | Kevin's aunt and Uncle Frank's wife |
5. Summarize text
The chatbot can be used to summarize the text. As an example, let’s ask it to summarize the history of the Python programming language from Wikipedia.
Query:
Summarize text:
Early history
In February 1991, Van Rossum published the code (labeled version 0.9.0) to alt.sources.[11][12] Already present at this stage in development were classes with inheritance, exception handling, functions, and the core datatypes of list, dict, str and so on. Also in this initial release was a module system borrowed from Modula-3; Van Rossum describes the module as "one of Python's major programming units".[1] Python's exception model also resembles Modula-3's, with the addition of an else clause.[3] In 1994 comp.lang.python, the primary discussion forum for Python, was formed, marking a milestone in the growth of Python's userbase.[1]
Version 1
Python reached version 1.0 in January 1994. The major new features included in this release were the functional programming tools lambda, map, filter and reduce. Van Rossum stated that "Python acquired lambda, reduce(), filter() and map(), courtesy of a Lisp hacker who missed them and submitted working patches".[13]
The last version released while Van Rossum was at CWI was Python 1.2. In 1995, Van Rossum continued his work on Python at the Corporation for National Research Initiatives (CNRI) in Reston, Virginia from where he released several versions.
By version 1.4, Python had acquired several new features. Notable among these are the Modula-3 inspired keyword arguments (which are also similar to Common Lisp's keyword arguments) and built-in support for complex numbers. Also included is a basic form of data hiding by name mangling, though this is easily bypassed.[14]
During Van Rossum's stay at CNRI, he launched the Computer Programming for Everybody (CP4E) initiative, intending to make programming more accessible to more people, with a basic "literacy" in programming languages, similar to the basic English literacy and mathematics skills required by most employers. Python served a central role in this: because of its focus on clean syntax, it was already suitable, and CP4E's goals bore similarities to its predecessor, ABC. The project was funded by DARPA.[15] As of 2007, the CP4E project is inactive, and while Python attempts to be easily learnable and not too arcane in its syntax and semantics, outreach to non-programmers is not an active concern.[16]
BeOpen
In 2000, the Python core development team moved to BeOpen.com[17] to form the BeOpen PythonLabs team, under the direction of early Google alum Domenic Merenda.[18][19] CNRI requested that a version 1.6 be released, summarizing Python's development up to the point at which the development team left CNRI. Consequently, the release schedules for 1.6 and 2.0 had a significant amount of overlap.[8] Python 2.0 was the only release from BeOpen.com. After Python 2.0 was released by BeOpen.com, Guido van Rossum and the other PythonLabs developers joined Digital Creations.
The Python 1.6 release included a new CNRI license that was substantially longer than the CWI license that had been used for earlier releases. The new license included a clause stating that the license was governed by the laws of the State of Virginia. The Free Software Foundation argued that the choice-of-law clause was incompatible with the GNU General Public License. BeOpen, CNRI and the FSF negotiated a change to Python's free software license that would make it GPL-compatible. Python 1.6.1 is essentially the same as Python 1.6, with a few minor bug fixes, and with the new GPL-compatible license.[20]
Version 2
Python 2.0, released October 2000,[8] introduced list comprehensions, a feature borrowed from the functional programming languages SETL and Haskell. Python's syntax for this construct is very similar to Haskell's, apart from Haskell's preference for punctuation characters and Python's preference for alphabetic keywords. Python 2.0 also introduced a garbage collector capable of collecting reference cycles.[8]
Python 2.1 was close to Python 1.6.1, as well as Python 2.0. Its license was renamed Python Software Foundation License. All code, documentation and specifications added, from the time of Python 2.1's alpha release on, is owned by the Python Software Foundation (PSF), a non-profit organization formed in 2001, modeled after the Apache Software Foundation.[20] The release included a change to the language specification to support nested scopes, like other statically scoped languages.[21] (The feature was turned off by default, and not required, until Python 2.2.)
Python 2.2 was released in December 2001;[22] a major innovation was the unification of Python's types (types written in C) and classes (types written in Python) into one hierarchy. This single unification made Python's object model purely and consistently object oriented.[23] Also added were generators which were inspired by Icon.[24]
A green snake with reared head and outstretched tongue
A falling weight labelled "16 ton"
A highly abstracted symbol suggestive of the head ends of two snakes in a double helix viewed head-on, curved clockwise toward the viewer: a blue snake comes in from behind to the left, with head folding back on its body at the top, and a yellow snake comes in from behind to the right and its head folds back on its body at the bottom; the overall silhouette of the symbol forms a rough plus sign, and the eye locations are suggestive of a yin and yang.
Historic Python logos used on Windows (left) and the Macintosh (centre), and the logo used since version 2.5 (right).
Python 2.5 was released in September 2006 [25] and introduced the with statement, which encloses a code block within a context manager (for example, acquiring a lock before the block of code is run and releasing the lock afterwards, or opening a file and then closing it), allowing Resource Acquisition Is Initialization (RAII)-like behavior and replacing a common try/finally idiom.[26]
Python 2.6 was released to coincide with Python 3.0, and included some features from that release, as well as a "warnings" mode that highlighted the use of features that were removed in Python 3.0.[27][10] Similarly, Python 2.7 coincided with and included features from Python 3.1,[28] which was released on June 26, 2009. Parallel 2.x and 3.x releases then ceased, and Python 2.7 was the last release in the 2.x series.[29] In November 2014, it was announced that Python 2.7 would be supported until 2020, but users were encouraged to move to Python 3 as soon as possible.[30] Python 2.7 support ended on January 1, 2020, along with code freeze of 2.7 development branch. A final release, 2.7.18, occurred on April 20, 2020, and included fixes for critical bugs and release blockers.[31] This marked the end-of-life of Python 2.[32]
Version 3
Python 3.0 (also called "Python 3000" or "Py3K") was released on December 3, 2008.[9] It was designed to rectify fundamental design flaws in the language – the changes required could not be implemented while retaining full backwards compatibility with the 2.x series, which necessitated a new major version number. The guiding principle of Python 3 was: "reduce feature duplication by removing old ways of doing things".[33]
Python 3.0 was developed with the same philosophy as in prior versions. However, as Python had accumulated new and redundant ways to program the same task, Python 3.0 had an emphasis on removing duplicative constructs and modules, in keeping with the Zen of Python: "There should be one— and preferably only one —obvious way to do it".
Nonetheless, Python 3.0 remained a multi-paradigm language. Coders could still follow object-oriented, structured, and functional programming paradigms, among others, but within such broad choices, the details were intended to be more obvious in Python 3.0 than they were in Python 2.x.
Compatibility
Python 3.0 broke backward compatibility, and much Python 2 code does not run unmodified on Python 3.[34] Python's dynamic typing combined with the plans to change the semantics of certain methods of dictionaries, for example, made perfect mechanical translation from Python 2.x to Python 3.0 very difficult. A tool called "2to3" does the parts of translation that can be done automatically. At this, 2to3 appeared to be fairly successful, though an early review noted that there were aspects of translation that such a tool would never be able to handle.[35] Prior to the roll-out of Python 3, projects requiring compatibility with both the 2.x and 3.x series were recommended to have one source (for the 2.x series), and produce releases for the Python 3.x platform using 2to3. Edits to the Python 3.x code were discouraged for so long as the code needed to run on Python 2.x.[10] This is no longer recommended; as of 2012 the preferred approach was to create a single code base that can run under both Python 2 and 3 using compatibility modules.[36]
Response:
Python is a programming language created by Guido van Rossum in the early 1990s. It was first released in January 1994 and has had several updates since then. Some notable features added in later releases include lambda, map, filter and reduce, support for complex numbers, and keyword arguments. Python's development team has moved around over the years, starting at the Corporation for National Research Initiatives (CNRI), then moving to BeOpen.com, and finally to Digital Creations. There have been some issues with the licensing of Python, with the Free Software Foundation arguing that it was incompatible with the GNU General Public License, but this was eventually resolved. Python 2.0 introduced list comprehensions and a garbage collector, and Python 2.1 added a new license and Unicode support. Python 3.0, released in December 2008, introduced many backwards-incompatible changes, but also added a number of new features such as easier handling of exceptions and the inclusion of a new library for asynchronous programming.
Not bad at all!
6. Generate text for mockups and prototypes
Are you still using lorem ipsum generators for creating test content for mockups and prototypes? We can do better than that now! Let’s use AI to create a text for a mockup of a website that sells products for pets.
Query:
Generate 200 words for a mockup of website that sells products for pets
Response:
Welcome to Pet Paradise, the ultimate online destination for all of your pet needs! We offer a wide variety of products for cats, dogs, and small animals, as well as a selection of high-quality food and treats.
Our mission is to provide the best possible products and shopping experience for pet owners. We understand the special bond between humans and their pets, and strive to make every interaction with Pet Paradise a positive one.
In our cat section, you'll find everything from scratching posts and litter boxes to toys and grooming supplies. For dogs, we have a range of collars, leashes, and toys, as well as carriers and crates for travel. Our small animal section includes products for rabbits, hamsters, and other small pets, including cages, bedding, and toys.
In addition to our wide selection of products, we also offer a range of services for your convenience. Our online store is available 24/7, making it easy to shop for your pets at any time of day. We also offer fast and reliable shipping to anywhere in the country.
For those in the local area, we have a brick and mortar store where you can come and browse our products in person. Our knowledgeable staff is always happy to help you find the perfect products for your furry friends.
Thank you for choosing Pet Paradise for all of your pet needs. We hope to see you soon!
Now, let’s generate a few names for this prototype.
Query:
Create 20 names for an online web application for selling products for pets
Response:
PetPals
Furrific
Pawsome
CritterCorner
FurryFriends
PetLand
CritterCo
PetSpot
FurryFiesta
PetCentral
FurrificFinds
PawsitivelyPerfect
CritterCove
FurryFriendly
PetPlus
CritterCentral
FurryFinds
PetSpotlight
CritterCountry
FurryFrenzy
Looks good! I am sure our sales and marketing team will love these names.
7. Unwind after work and take care of your physical and mental health
When you get tired, take a break and take good care of yourself. Ask the chatbot to entertain you with a joke about software engineers.
Query:
Tell me a joke about software engineers
Response:
Why did the software engineer get fired?
Because he kept writing code that was "buggy" and his boss thought he was a pest!
Or create a workout routine.
Query:
Create a workout routine for a 30 year old man. The workout can be scheduled 5 days a week. Each session should take 90 minutes.
Response:
Monday:
- Warm up: 5-10 minutes of light cardio (walking, jogging, biking)
- Strength training:
- 3 sets of 8-12 reps of bench press, using a moderate weight
- 3 sets of 8-12 reps of bent over rows, using a moderate weight
- 3 sets of 8-12 reps of bicep curls, using moderate weight
- 3 sets of 8-12 reps of tricep dips, using bodyweight
- 3 sets of 8-12 reps of squats, using a moderate weight
- 3 sets of 8-12 reps of lunges, using a moderate weight
- 3 sets of 8-12 reps of calf raises, using a moderate weight
- Cool down: 5-10 minutes of stretching
Tuesday:
- Warm up: 5-10 minutes of light cardio (walking, jogging, biking)
- Cardio intervals:
- 20 seconds of high intensity (sprinting, jumping jacks, mountain climbers) followed by 40 seconds of low intensity (walking, jogging in place) for a total of 20 minutes
- Cool down: 5-10 minutes of stretching
Wednesday:
- Rest day
Thursday:
- Warm up: 5-10 minutes of light cardio (walking, jogging, biking)
- Strength training:
- 3 sets of 8-12 reps of push ups, using bodyweight
- 3 sets of 8-12 reps of pull ups, using bodyweight or assisted machine
- 3 sets of 8-12 reps of shoulder press, using a moderate weight
- 3 sets of 8-12 reps of lateral raises, using a moderate weight
- 3 sets of 8-12 reps of leg press, using a moderate weight
- 3 sets of 8-12 reps of glute bridges, using a moderate weight
- 3 sets of 8-12 reps of ab crunches, using bodyweight
- Cool down: 5-10 minutes of stretching
Friday:
- Warm up: 5-10 minutes of light cardio (walking, jogging, biking)
- Cardio endurance: 30 minutes of steady state cardio (jogging, cycling, swimming) at a moderate pace
- Cool down: 5-10 minutes of stretching
Saturday:
- Rest day
Sunday:
- Warm up: 5-10 minutes of light cardio (walking, jogging, biking)
- Yoga or Pilates: 60 minutes of yoga or Pilates to improve flexibility and balance
- Cool down: 5-10 minutes of stretching
A word of caution
It is very easy to start relying on the new chatbot for getting answers to all your questions quickly without annoying ads. However, the new AI is far from perfect. The most dangerous thing about it is not that it can take over the world. It can’t. At least not yet. The danger is that it confidently provides answers to many questions but these answers are not always correct. This problem has been acknowledged by OpenAI, the company that created the chatbot. Because of this problem Stack Overflow, the most popular Q&A website for professional software engineers banned answers generated by the chatbot. Here is an example of an answer provided by the ChatGPT that is not correct. I am asking the AI to explain the difference between XML and JSON.
Query:
What is the difference between XML and JSON?
Response:
XML (eXtensible Markup Language) and JSON (JavaScript Object Notation) are both data formats that are used to store and exchange information. However, they have some key differences that you should be aware of:
1. Syntax: XML uses a set of predefined tags to mark up data, while JSON uses key-value pairs to represent data.
2. Structure: XML uses a tree-like structure to represent data, with each element having a parent, children, and siblings. JSON uses a more flexible structure that allows for complex data structures like lists and dictionaries.
3. Size: JSON is generally smaller and simpler than XML, which makes it faster to read and write.
4. Use cases: XML is often used in combination with other technologies, such as XSLT (a language for transforming XML data), while JSON is used more often as a standalone data format.
Overall, both XML and JSON are widely used and have their own strengths and weaknesses. It's important to choose the right format for your specific needs.
The answer looks convincing. Notice how AI highlights JSON’s more flexible structure that supports lists and dictionaries. Now, look at what happens when we ask about the difference between JSON and YAML.
Query:
What is the difference between JSON and YAML?
Response:
JSON (JavaScript Object Notation) and YAML (YAML Ain't Markup Language) are both data serialization formats that are used to represent structured data. However, there are some key differences between the two:
1. Syntax: JSON uses a set of key-value pairs to represent data, while YAML uses a more flexible syntax that allows for complex data structures like lists and dictionaries.
2. Structure: JSON uses a rigid structure that requires data to be in a specific format, while YAML is more flexible and can represent data in a variety of ways.
3. Readability: YAML is generally easier to read and write than JSON, as it uses indentation to denote structure instead of curly braces.
4. Use cases: JSON is used more widely than YAML, and is supported by a larger number of programming languages and tools. However, YAML is often preferred for configuration files, as it is easier to read and write than JSON.
Overall, both JSON and YAML are useful formats for representing structured data, and the choice between them will depend on your specific needs.
Now, in point # 1, the AI is trying to convince us that YAML is the one that supports lists and dictionaries. In reality, all of the mentioned technologies support lists and dictionaries.
So, when the stakes are high and using a wrong AI-generated answer may get you into trouble, do not rely on the new chatbot. Do your own research and find credible sources of information.
Conclusion
As we saw in this post, when used with caution, the AI can be a good assistant to a software engineer. It gives answers without ads and without a million links to click through. And the good news is that Google already noticed all this and got scared. And this can only mean one thing: Google will have to improve their search results which will make things even better for all users regardless of answers that they are looking for.