# ChatGPT #Coding #AI #Programming #Technology #OpenAI #GPT-3 #GPT-4 #Python #PHP #WebDevelopment #SoftwareDevelopment
Cách sử dụng ChatGPT để viết mã: Những điều nó làm tốt và những điều nó không thể
Một trong những khám phá hấp dẫn về ChatGPT là nó có thể viết mã khá tốt. Lần đầu tiên tôi thử nghiệm điều này vào năm ngoái khi tôi yêu cầu nó viết một plugin WordPress mà vợ tôi có thể sử dụng trên trang web của mình. ChatGPT đã hoàn thành công việc tốt, nhưng đó là một dự án rất đơn giản.
Vậy, bạn có thể sử dụng ChatGPT để viết mã trong quá trình luyện tập mã hằng ngày của bạn như thế nào? Dưới đây là một tóm tắt nhanh chóng:
– ChatGPT có thể tạo ra cả mã hữu ích và mã không phù hợp. Để có kết quả tốt nhất, hãy cung cấp cho ChatGPT các câu hỏi rõ ràng và chi tiết.
– ChatGPT xuất sắc trong việc hỗ trợ các nhiệm vụ hoặc quy trình mã hóa cụ thể, thay vì xây dựng ứng dụng hoàn chỉnh từ đầu.
– Sử dụng ChatGPT để tìm kiếm và chọn thư viện mã hóa phù hợp cho mục đích cụ thể, và tham gia vào cuộc trao đổi tương tác để thu hẹp các lựa chọn.
– Hãy cẩn thận với việc sở hữu mã được tạo bởi AI và luôn xác minh tính đáng tin cậy của mã. Đừng mù quáng tin tưởng vào kết quả được tạo ra.
– Xem xét các tương tác với ChatGPT như một cuộc trò chuyện. Rèn luyện câu hỏi của bạn dựa trên phản hồi của AI để tiến gần hơn đến kết quả mong muốn.
Bây giờ, hãy khám phá ChatGPT theo cách sâu hơn nhiều.
Loại mã hóa nào mà ChatGPT làm tốt?
Có hai sự thật quan trọng về ChatGPT và mã hóa. Thứ nhất là AI có thể viết mã có ích. Thứ hai là nó có thể mất hướng hoàn toàn, rơi vào cái lỗ, đuổi theo chính mình, và tạo ra những rác không thể sử dụng.
Tôi đã nhận ra điều này bằng cách khó khăn. Sau khi tôi hoàn thành plugin WordPress, tôi quyết định xem xem ChatGPT có thể đi xa đến đâu.
Tôi viết ra một prompt rất cẩn thận cho một ứng dụng Mac, bao gồm các mô tả chi tiết của các yếu tố giao diện người dùng, tương tác, những thứ sẽ được cung cấp trong cài đặt, cách chúng sẽ hoạt động, và các vấn đề khác. Sau đó, tôi cung cấp prompt cho ChatGPT. ChatGPT đã phản hồi với một lũ văn bản và mã. Sau đó, nó dừng giữa mã. Khi tôi yêu cầu nó tiếp tục, nó vẫy ra thêm mã và văn bản. Tôi yêu cầu tiếp tục sau từng lần, và nó trả lại thêm mã hơn và hơn. Nhưng… không có cái nào có thể sử dụng được. Nó không nhận ra ở đâu mã nên đặt, cách xây dựng dự án, và — khi tôi nhìn kỹ vào mã đã sản xuất — nó để lại các hoạt động chính tôi yêu cầu, chỉ cho mô tả văn bản đơn giản nói rằng “logic chương trình được đặt ở đây”.
Sau một loạt các bài kiểm tra lặp đi lặp lại, tôi nhận ra rằng nếu bạn yêu cầu ChatGPT cung cấp ứng dụng hoàn chỉnh, nó sẽ thất bại. Một hệ quả của quan sát này là nếu bạn không biết gì về mã hóa và muốn ChatGPT xây dựng cho bạn một cái gì đó, nó sẽ thất bại.
Nơi ChatGPT thành công — và làm rất rõ ràng — là trong việc giúp người đã biết mã hóa xây dựng các quy trình cụ thể và hoàn thành các nhiệm vụ cụ thể. Đừng yêu cầu một ứng dụng chạy trên thanh menu. Nhưng nếu bạn yêu cầu ChatGPT một quy trình để đặt một menu trên thanh menu, sau đó dán nó vào dự án của bạn, công cụ sẽ làm khá tốt. Hãy nhớ rằng trong khi ChatGPT có vẻ sở hữu một lượng kiến thức cụ thể về lãnh vực (và đôi khi là thế), nó thiếu khôn ngoan. Do đó, công cụ có thể viết mã, nhưng sẽ không thể viết mã chứa những sắc thái cho các vấn đề cụ thể hoặc phức tạp cần sự kinh nghiệm sâu sắc để hiểu.
Sử dụng ChatGPT để trình diễn các phương pháp, viết thuật toán nhỏ, và tạo ra các tiểu hàm. Bạn có thể thậm chí nhờ ChatGPT giúp bạn phân chia một dự án lớn thành các phần, và sau đó bạn có thể yêu cầu nó giúp bạn viết mã những phần đó. Vì vậy, với điều đó trong đầu, hãy xem xét một số bước cụ thể để ChatGPT có thể giúp bạn viết mã.
Dành thời gian quyết định những gì bạn muốn yêu cầu ChatGPT – nhưng chưa hỏi nó bất cứ điều gì. Quyết định điều bạn muốn hàm hoặc quy trình của mình thực hiện, hoặc điều bạn muốn tìm hiểu để tích hợp vào mã của mình. Quyết định về các tham số bạn sẽ truyền vào mã của mình và những gì bạn muốn nhận ra. Và sau đó xem xét cách bạn sẽ mô tả nó.
Hãy tưởng tượng bạn đang trả tiền cho một lập trình viên con người để làm nhiệm vụ này. Bạn đang cung cấp đủ thông tin cho người đó để có thể làm việc trên nhiệm vụ của bạn không? Hoặc bạn có quá mơ hồ và người bạn đang trả tiền là người có thể hoặc hỏi câu hỏi hoặc giao nộp một cái gì đó hoàn toàn không liên quan đến điều bạn muốn không?
Dưới đây là một ví dụ. Giả sử tôi muốn có thể tóm tắt bất kỳ trang web nào. Tôi muốn cung cấp cho nó như bài viết này và nhận lại một bản tóm tắt ngắn đầy đủ và phù hợp. Làm đầu vào của tôi, tôi chỉ định một URL trang web. Làm đầu ra của tôi, đó là một khối văn bản với một bản tóm tắt. Tiếp tục với ví dụ ở trên, một cách cũ kỹ rất cũ của việc trích xuất dữ liệu trang web là tìm văn bản giữa các thẻ đoạn HTML.
Nhưng với sự bùng nổ của các công cụ AI, việc sử dụng một thư viện AI để thực hiện việc trích xuất thông tin và tóm tắt thông minh hơn. Một nơi mà ChatGPT xuất sắc (và cũng là một lĩnh vực bạn có thể dễ dàng xác minh để tránh mẫu hình hành vi tư duy quyền lực nhưng sai lầm của nó) là tìm thư viện và nguồn lực.
OpenAI (nhà sản xuất của ChatGPT) bán quyền truy cập API cho các công cụ GPT-3 và GPT-4 sẽ thực hiện chính xác những gì chúng ta muốn. Nhưng trong trường hợp của ví dụ này, hãy giả sử chúng ta không muốn trả phí giao dịch.
Vậy hãy xem xét cách tương tác với ChatGPT để tìm hiểu cách sử dụng một công cụ như vậy, miễn phí, trong một dự án chạy trên PHP. Tôi bắt đầu với một prompt được thiết kế để lấy thông tin về những thư viện sẽ cung cấp chức năng mà tôi muốn. Một thư viện (đối với những bạn đọc không phải là lập trình viên) là một cơ thể mã mà một lập trình viên có thể truy cập để làm nhiều công việc nặng nề cho một mục đích cụ thể. Một phần lớn của việc lập trình hiện đại là tìm ra và chọn lựa thư viện phù hợp, vì vậy đây là một điểm khởi đầu tốt. Trong trường hợp này, tôi đang xem xét các khối mã được viết bởi những người khác sẽ tóm tắt văn bản. Dưới đây là câu hỏi đầu tiên của tôi: Mô tả mười thư viện AI mã nguồn mở khác nhau (và ngôn ngữ họ hoạt động) mà tôi có thể sử dụng để tạo ra một bản tóm tắt về nội dung nền chính của bất kỳ trang web nào, bỏ qua bất kỳ quảng cáo hoặc vật liệu nhúng nào.
Prompt này đã mang lại cho tôi chính xác những gì tôi muốn, bao gồm cả việc đề cập đến những gì OpenAI cung cấp. Tôi nghĩ OpenAI sẽ hoạt động tốt ở đây, nhưng đối với dự án giả định này, tôi không muốn dành ngân sách cho các khoản phí API. Cuối cùng, tôi rút gọn câu hỏi đó: Có bất kỳ thư viện nào miễn phí không? ChatGPT cảnh báo với câu trả lời của mình. Dưới đây là những gì nó nói: “Vâng, tất cả mười thư viện AI này đều là mã nguồn mở và miễn phí để sử dụng. Tuy nhiên, một số trong số họ có giới hạn sử dụng hoặc đòi hỏi thanh toán để truy cập vào các tính năng hoặc nguồn lực bổ sung.” Vì vậy, dựa trên đó, tôi đã làm rõ câu hỏi của mình: Thư viện nào trong số các thư viện này không có giới hạn sử dụng và không yêu cầu bất kỳ chi phí hoặc giấy phép bổ sung nào?
Hãy chú ý cách đây rất nhiều cuộc trò chuyện thôi. Tôi không phải hỏi lại câu hỏi ban đầu. Tôi chỉ đang đi sâu vào cách tương tự như tôi có một chuyên gia ở ngay cạnh và đang tìm kiếm định rõ. Trong trường hợp này, ChatGPT đã đưa ra cho tôi tám lựa chọn thư viện, nhưng không có cái nào đề cập đến ngôn ngữ PHP mà tôi đã lên kế hoạch mã hóa. Vậy, đây là câu hỏi tiếp theo của tôi: Trong số 8 thư viện đó, tôi có thể sử dụng bất kỳ cái nào với PHP không? Nó trả lại ba thư viện, nhưng tôi không chắc chắn về mỗi thư viện làm gì. Vì vậy, một câu hỏi khác: Sự khác biệt giữa Sumy, Gensim, và NLTK là gì? Tôi vẫn chưa chắc lắm, vì vậy tôi làm rõ kế hoạch sử dụng của tôi và sau đó hỏi: Nếu tôi muốn tạo ra tóm tắt của các bài báo tin tức trên trang web, thư viện nào hoạt động tốt hơn? Câu trả lời tôi nhận được rõ ràng và hứa hẹn: “Sumy được thiết kế đặc biệt cho việc tóm tắt văn bản, đó là nhiệm vụ của việc tạo ra một bản tóm tắt chứa thông tin quan trọng nhất từ một đoạn văn bản.” Vì vậy, bây giờ là lúc…
![coding concept](https://queenmobile.xyz/wp-content/uploads/2024/10/Su-dung-ChatGPT-de-viet-code-Dieu-no-lam-tot.jpg)
One of the more intriguing discoveries about ChatGPT is that it can write pretty good code. I first tested this out last year when I asked it to write a WordPress plugin my wife could use on her website. ChatGPT did a fine job, but it was a very simple project.
How to use ChatGPT to write: Resumes | Excel formulas | Essays | Cover letters
So, how can you use ChatGPT to write code as part of your daily coding practice? Here’s a quick summary:
- ChatGPT can produce both useful and unusable code. For best results, provide clear and detailed prompts.
- ChatGPT excels in assisting with specific coding tasks or routines, rather than building complete applications from scratch.
- Use ChatGPT to find and choose the right coding libraries for specific purposes, and engage in an interactive discussion to narrow down options.
- Be cautious about the ownership of AI-generated code and always verify the code’s reliability. Don’t blindly trust the generated output.
- Treat interactions with ChatGPT as a conversation. Refine your questions based on the AI’s responses to get closer to the desired output.
Now, let’s explore ChatGPT in considerably more depth.
What types of coding can ChatGPT do well?
There are two important facts about ChatGPT and coding. The first is that the AI can, in fact, write useful code.
The second is that it can get completely lost, fall down a rabbit hole, chase its own tail, and produce unusable garbage.
Also: The best free AI courses
I found this out the hard way. After I finished the WordPress plugin, I decided to see how far ChatGPT could go.
I wrote out a very careful prompt for a Mac application, including detailed descriptions of user interface elements, interactions, what would be provided in settings, how they would work, and so on. Then, I fed the prompt to ChatGPT.
ChatGPT responded with a flood of text and code. Then, it stopped mid-code. When I asked it to continue, it vomited out even more code and text. I requested continue after continue, and it dumped out more and more code. But… none of it was usable. It didn’t identify where the code should go, how to construct the project, and — when I looked carefully at the code produced — it left out major operations I requested, leaving in simple text descriptions stating “program logic goes here”.
After a bunch of repeated tests, it became clear to me that if you ask ChatGPT to deliver a complete application, it will fail. A corollary to this observation is that if you know nothing about coding and want ChatGPT to build you something, it will fail.
Also: How ChatGPT scanned 170k lines of code in seconds and saved me hours of work
Where ChatGPT succeeds — and does so very well — is in helping someone who already knows how to code to build specific routines and get specific tasks done. Don’t ask for an app that runs on the menu bar. But if you ask ChatGPT for a routine to put a menu on the menu bar, and then paste that into your project, the tool will do quite well.
Also, keep in mind that while ChatGPT appears to have a tremendous amount of domain-specific knowledge (and it often does), it lacks wisdom. As such, the tool may be able to write code, but it won’t be able to write code containing the nuances for very specific or complex problems that require deep experience to understand.
Also: How to use ChatGPT to create an app
Use ChatGPT to demo techniques, write small algorithms, and produce subroutines. You can even get ChatGPT to help you break down a bigger project into chunks, and then you can ask it to help you code those chunks.
So, with that in mind, let’s look at some specific steps for how ChatGPT can help you write code.
How to use ChatGPT to write code
This first step is to decide what you are going to ask of ChatGPT — but not yet ask it anything. Decide what you want your function or routine to do, or what you want to learn about to incorporate into your code. Decide on the parameters you’re going to pass into your code and what you want to get out. And then look at how you’re going to describe it.
Also: How to write better ChatGPT prompts
Imagine you’re paying a human programmer to do this task. Are you giving that person enough information to be able to work on your assignment? Or are you too vague and the person you’re paying is more likely to either ask questions or turn in something entirely unrelated to what you want?
Here’s an example. Let’s say I want to be able to summarize any web page. I want to feed it something like this article and get back a short summary that’s well-considered and appropriate. As my input, I’ll specify a web page URL. As my output, it’s a block of text with a summary.
Continuing with the example above, a very old school way of extracting web page data was to find the text between HTML paragraph tags.
But with the rise of AI tools, it makes more sense to use an AI library to do an intelligent extract and summary. One of the places ChatGPT excels (and it’s also an area you can easily verify to avoid its authoritative-but-wrong behavior pattern) is finding libraries and resources.
Also: The most popular programming languages in 2024 (and what that even means)
OpenAI (the maker of ChatGPT) sells API access to the GPT-3 and GPT-4 engines that will do exactly what we want. But in the case of this example, let’s assume we don’t want to pay transaction fees.
So let’s look at interacting with ChatGPT to figure out how to use such a tool, for free, with a project that runs in PHP.
I started with a prompt that was designed to elicit information about what libraries would provide the functionality I wanted. A library (for those of you reading along who aren’t programmers) is a body of code a programmer can access that does a lot of the heavy lifting for a specific purpose. A big part of modern programming is finding and choosing the right libraries, so this is a good starting point.
In this case, I’m looking at blocks of code written by other people that will summarize text. Here’s my first prompt:
Describe ten different open source AI libraries (and the languages they work with) that I can use to generate a summary of the main core contents of any web page, ignoring any ads or embedded materials.
This prompt gave me exactly what I wanted, including a mention of OpenAI’s offerings. I think OpenAI would do great here, but for this hypothetical project, I don’t want to budget for API fees. So. I’ll narrow down the question:
Are any of these free?
ChatGPT hedged its bets with its answer. Here’s what it said: “Yes, all ten of these AI libraries are open source and free to use. However, some of them may have usage limits or require payment for access to additional features or resources.” So, based on that, I clarified my query:
Which of these libraries have no usage limits and don’t require any additional payment or licensing?
Notice how this is very much a conversation. I don’t have to re-ask the originating question. I’m just drilling down in the same way I might if I had an expert at hand and was seeking clarification. In this case, ChatGPT gave me eight library choices, but none of them mentioned the PHP language that I was planning to code in. So, here’s the next prompt:
Of those 8 libraries, can I use any with PHP?
It returned three libraries, but I wasn’t sure about what each did. So, another question:
What’s the difference between Sumy, Gensim, and NLTK?
I still wasn’t sure, so I clarified my use plan and then asked:
If I want to create summaries of web page news articles, which library would work better?
The answer I got was clear and promising: “Sumy is specifically designed for text summarization, which is the task of creating a summary that captures the most important information from a piece of text.” So, now it was time to see what was involved in using Sumy with PHP. I asked my last question for this part of the project:
Can you explain how to use Sumy from PHP?
Feel free to play along on your computer and paste these prompts into your instance of ChatGPT. Notice that, in step one, I decided what program module I was going to get help on. Then, in this step, I had a conversation with ChatGPT to decide what library to use and how to integrate it into my project.
Also: The best AI chatbots
That may not seem like programming, but I assure you it is. Programming isn’t just blasting lines of code onto a page. Programming is figuring out how to integrate all the various resources and systems together, and how to talk to all the various components of your solution. Here, ChatGPT helped me do that integration analysis.
By the way, I was curious whether Google’s Gemini AI (formerly Bard) could help in the same way. Gemini can’t actually write code, but it did give some extra insights into the planning aspect of programming over ChatGPT’s responses. So, don’t hesitate to use multiple tools to triangulate on answers you want. Here’s that story: Gemini vs. ChatGPT: Can Gemini help you code? Since I wrote that article, Google added some coding capabilities to Gemini, but they’re not all that great. You can read about it here: I tested Google Gemini’s new coding skills. It didn’t go well. And even more recently, I dug into Gemini Advanced. It’s still not passing many tests.
Also: How I test an AI chatbot’s coding ability – and you can too
Coding is next.
OK, let’s pause here. This article is entitled “How to use ChatGPT to write code.” And it will. But what we’re really doing is asking ChatGPT to write example code.
Also: The rise and fall in programming languages’ popularity since 2016 – and what it tells us
Let’s be clear: Unless you’re writing a very small function (like the line sorter/randomizer ChatGPT wrote for my wife), ChatGPT isn’t going to be able to write your final code. First, you’re going to have to maintain it. ChatGPT is terrible at modifying already-written code. Terrible, as in, it doesn’t do it. So, to get new code, you have to ask ChatGPT to generate something new. As I found previously, even if your prompt is virtually identical, ChatGPT may change what it gives you in very unexpected ways.
So, bottom line: ChatGPT can’t maintain your code, or even tweak it.
That limitation means you have to do it yourself. As we know, the first draft of a piece of code is rarely the final code. So, even if you were to expect ChatGPT to generate final code, it would really be a starting point, one where you need to take it to completion, integrate it into your bigger project, test it, refine it, debug it, and so on.
But that doesn’t mean the example code is worthless — far from it. Let’s take a look at a prompt I wrote based on the project I described earlier. Here’s the first part:
Wite a PHP function called summarize_article.
As input, summarize_article will be passed a URL to an article on a news-related site like ZDNET.com or Reuters.com.
I’m telling ChatGPT the programming language it should use. I’m also telling it the input but, while doing so, providing two sites as samples to help ChatGPT understand the style of article. Honestly, I’m not sure ChatGPT didn’t ignore that bit of guidance. Next, I’ll tell it how to do the bulk of the work:
Inside summarize_article, retrieve the contents of the web page at the URL provided. Using the library Sumy from within PHP and any other libraries necessary, extract the main body of the article, ignoring any ads or embedded materials, and summarize it to approximately 50 words. Make sure the summary consists of complete sentences. You can go above the 50 words to finish the last sentence, if necessary.
This is very similar to how I’d instruct an employee. I’d want that person to know that they weren’t only restricted to Sumy. If they needed another tool, I wanted them to use it.
Also: IBM will train you in AI fundamentals for free, and give you a skill credential – in 10 hours
I also specified an approximate number of words to create bounds for what I wanted as a summary. A later version of the routine might take that number as a parameter. I then ended by saying what I wanted as a result:
Once processing is complete, code summarize_article so it returns the summary in plain text.
The resulting code is pretty simple. ChatGPT did call on another library (Goose) to retrieve the article contents. It then passed that summary to Sumy with a 50-word limit and then returned the result. But once the basics are written, it’s a mere matter of programming to go back in and add tweaks, customize what’s passed to the two libraries, and delivering the results.
One interesting point of note. When I originally tried this test in early 2023, ChatGPT created a sample call to the routine it wrote, using a URL from after 2021. At that time, in March 2023, ChatGPT’s dataset only went to 2021. Now, the ChatGPT knowledge base extends to the end of December 2023. But my point is that ChatGPT made up a sample link that it couldn’t possibly know about:
https://www.reuters.com/business/retail-consumer/teslas-musk-says-fremont-california-factory-may-be-sold-chip-shortage-bites-2022-03-18/
I checked that URL against both Reuters’ site and the Wayback Machine, and it doesn’t exist. Never assume ChatGPT is accurate. Always double-check everything it gives you.
FAQs
Does ChatGPT replace programmers?
Not now — or, at least — not yet. ChatGPT programs at the level of a talented first-year programming student, but it’s lazy (like that first-year student). The tool might reduce the need for entry-level programmers, but at its current level, I think it will just make life easier for entry-level programmers (and even programmers with more experience) to write code and look up information. It’s definitely a time-saver, but there are few programming projects it can do on its own — at least now. In 2030? Who knows.
How do I get coding answers in ChatGPT?
Just ask it. You saw above how I used an interactive discussion dialog to narrow down the answers I wanted. When you’re working with ChatGPT, don’t expect one question to magically do all your work for you. But use ChatGPT as a helper and resource, and it will give you a lot of very helpful information.
Also: Want a programming job? Learn these three languages
Of course, test that information — because, as John Schulman, a co-founder of OpenAI, says, “Our biggest concern was around factuality, because the model likes to fabricate things.”
Is the code generated by ChatGPT guaranteed to be error-free?
Hell, no! But you also can’t trust the code human programmers write. I certainly don’t trust any code I write. Code comes out of the code-making process incredibly flawed. There are always bugs. Before you ship, you need to test, test, and test again. Then, alpha test with a few chosen victims. Then beta test with your wider user community.
Even after all that, there will be bugs. Just because an AI is playing at this coding thing doesn’t mean it can do bug-free code. Do not trust. Always verify. And you still won’t have it fully bug-free. Such is the nature of the universe.
What do I do if the code I get back is wrong?
Recall that I always recommend you think of the chatbot as a slightly uncooperative student or subordinate employee. What would you do if that person gave you back code that didn’t work? You’d send them back out with instructions to do it again and get it right. That’s about what you should do with ChatGPT (I’ve tested this with 4 and 4o). I simply say “That didn’t work. Please try again.”
Also: Google’s AI podcast tool transforms your text into stunningly lifelike audio – for free
The AI does just that. It often gives me back different variations on the same problem. I’ve repeated this four or five times on occasion until I’ve gotten a working answer. Sometimes, though, the AI runs out of ideas. Other times, the try-again answer is completely (and I do mean completely) unrelated to what you’ve requested. When it becomes apparent you’ve reached the edge of the AI’s ability to remain sane on the problem, you’ll have to buckle up and code it yourself. But 9 times out of 10, especially with basic coding or interface-writing challenges, the AI does the job successfully.
How detailed should my description of a programming issue be when asking ChatGPT?
Detailed. Look at it this way: the more you leave open for interpretation, the more the AI will go its own way. When I give prompts to ChatGPT to help me while programming, I imagine I’m assigning a programming task to one of my students or someone who works for me.
Also: 6 ways to write better ChatGPT prompts – and get the results you want faster
Did I give that person enough details to go off and create a first draft or will that person have to ask me a ton of additional questions? Worse, will that person have so little guidance that they’ll go off in entirely the wrong direction? Don’t be lazy here. ChatGPT can save you hours or even days programming (it has for me), but only if you give it useful instructions to begin with.
If I use ChatGPT to write my code, who owns it?
As it turns out, there’s not a lot of case law yet to definitively answer this question. The US, Canada, and the UK require something that’s copyrighted to have been created by human hands, so code generated by an AI tool may not be copyrightable. There are also issues of liability based on where the training code came from and how the resulting code is used.
ZDNET did a deep dive on this topic, spoke to legal experts, and produced the following three articles. If you’re concerned about this issue (and if you’re using AI to help with code, you should be), I recommend you give them a read.
What programming languages does ChatGPT know?
Most of them. I tested common modern languages, like PHP, Python, Java, Kotlin, Swift, C#, and more. But then I had the tool write code in obscure dark-age languages like COBOL, Fortran, Forth, LISP, ALGOL, RPG (the report program generator, not the role-playing game), and even IBM/360 assembly language.
As the icing on the cake, I gave it this prompt:
Write a sequence that displays ‘Hello, world’ in ascii blinking lights on the front panel of a PDP 8/e
The PDP 8/e was my very first computer, and ChatGPT actually gave me instructions for toggling in a program using front-panel switches. I was impressed, gleeful, and ever so slightly afraid.
Can ChatGPT help me with data analysis and visualization tasks?
Yes, and a lot of it can be done without code. Check out my entire article on this topic: The moment I realized ChatGPT Plus was a game-changer for my business.
I also did a piece on generated charts and tables: How to use ChatGPT to make charts and tables
But here’s where it gets fun. In the article above, I asked ChatGPT Plus “Make a bar chart of the top five cities in the world by population,” and it did. But do you want code? Try asking:
Make a bar chart of the top five cities in the world by population in Swift. Pull the population data from online. Be sure to include any necessary libraries.
By adding “in Swift,” you’re specifying the programming language. By specifying where the data comes from and forcing ChatGPT Plus to include libraries, it knows to bring in the other resources the program needs. That’s why, fundamentally, programming with an AI’s help requires you to know things about programming. But if you do, it’s cool. Because three sentences can get you a nice chunk of annotated code. Cool, huh?
How does ChatGPT handle the differences between dialects and implementations of a given programming language?
We don’t have exact details on this issue from OpenAI, but our understanding of how ChatGPT is trained can shed some light on this question. Keep in mind that dialects and implementations of programming languages (and their little quirks) change much more rapidly than the full language itself. This reality makes it harder for ChatGPT (and many programming professionals) to keep up.
Also: How I used ChatGPT to write a custom JavaScript bookmarklet
As such, I’d work off these two assumptions:
- The more recent the dialectic change, the less likely ChatGPT knows about it, and
- The more popular a language overall, the more training data it likely has learned from, and therefore the more accurate it will be.
What’s the bottom line? ChatGPT can be a very helpful tool. Just don’t ascribe superpowers to it. Yet.
You can follow my day-to-day project updates on social media. Be sure to follow me on Twitter at @DavidGewirtz, on Facebook at Facebook.com/DavidGewirtz, on Instagram at Instagram.com/DavidGewirtz, and on YouTube at YouTube.com/DavidGewirtzTV.
[ad_2]