While the previous wave of image-generating models had artists anxious and began to protest against Copyrights infringement by models such as Stable Diffusion, the ChatGPT revolution has created a sense of crisis in all industries.
Programmers, in particular, are shivering. They have lost their jobs and become “code review specialists”.
But is ChatGPT’s ability to change code really as powerful as you think?
Maybe it is that strong!
With ChatGPT, you don’t need to search through a mountain of documentation to find a valuable answer. You just need to ask a single question to return a highly likely correct answer, and there are many examples of everything from dependent library updates to MacOS support.
ChatGPT, one can handle two, boss says save money.
Understand version updates to programming languages
“Version matching” is definitely the most hair-dropping issue for programmers, and it takes a lot of effort to debug and fix every time you encounter tensorflow incompatibilities, mutual exclusion of various dependent library versions, and language version features.
Most people don’t pay attention to what changes are made in each version update, but ChatGPT writes them down.
If your boss asks you to migrate all your websites from the very outdated version of PHP 7.4 to the latest version of PHP 8, that might be a headache.
PHP, the web programming language that WordPress and many other web management tools rely on, involves a lot of plugins, some of which are not compatible with PHP 8, and you’ll need to find and fix the code if you want your updated website to work successfully.
The usual solution process, which involves searching for the problem on PHP.net and then looking up some comments on StackExchange to determine exactly how to fix it, is messy and time-consuming.
You can now type the details of a problem directly into ChatGPT and get a quick solution, with some demo code included in the answer.
Q: When I was working with PHP, the extract function returned a fatal error without passing in an array. The code worked fine in PHP 7.4, but had errors in PHP 8. What’s changed about PHP 8’s extract?
I’m having trouble with the PHP extract function giving a fatal error when not passed an array. In PHP 7.4, I’m having trouble with the PHP extract function giving a fatal error when not passed an array. I did not get the error, but I seem to in PHP 8. Did extract change for PHP 8?
ChatGPT replies: In PHP8, the behavior of the extract () function has become more stringent. In previous versions of PHP, the extract () function would simply return false if no array was passed in; But in PHP 8, if no array is passed, a fatal error is thrown. This change was made to improve the robustness of the function and to prevent potential errors caused by accidental input.
You can check if the variable passed to the function is an array by using is_array () and then call extract ()
You can also use the array_key_exists () function to check if the variable passed in is an array.
Or use… Operator to deconstruct an array into multiple variables.
It turns out that bugs can be fixed in minutes based on ChatGPT’s answers, in large part because of knowing where to look for answers, and because ChatGPT shows how functions behave differently in different versions of PHP.
Q: What PHP functions might break when migrating code from PHP 7.4 to PHP 8?
What PHP functions are likely to break when moving from PHP 7.4 to PHP 8? What PHP functions are likely to break when moving from PHP 7.4 to PHP 8?
ChatGPT replies: Some functions and features may not work or behave differently when migrating from PHP 7.4 to PHP 8. Here are some of the major changes that could cause problems:
As mentioned in the previous answer, the extract () function throws a fatal error if an array is not passed in;
foreach, array_keys (), and current () were removed in PHP 8.0;
The create_function () function was removed in PHP 8.0. Anonymous functions are recommended.
list () construction, which, when used with foreach, now returns keys and values as separate variables instead of a single array;
The __autoload () function has been removed in PHP 8.0;
The $php_errormsg variable was removed in PHP 8.0;
Some deprecations functions have been deprecated, including create_function (), each (), __autoload () and (), and $php_errormsg
These are just a few examples of changes that can be problematic when migrating from PHP 7.4 to PHP 8, and it’s a good idea to thoroughly test your code and applications before upgrading to make sure everything works as expected.
In this answer, ChatGPT also says “as mentioned in the previous answer”, which is both surprising and alarming.
In the code being modified, create_function was often used by the original (long-gone) developer, and I didn’t know it was deprecated at the time, but based on the list of changes provided by ChatGPT, it was just a matter of searching the code to find what needed to be updated and rewritten.
Then, continue asking ChatGPT to show you a way to replace the function.
Q: What is a good way to rewrite code in PHP using create_function? Give me an example of using create_function.
What’s a good way to rewrite code using create_function in PHP? Can you give me an example using create_function, and then one using the currently proper mechanism?
create_function is a deprecated function in PHP for creating anonymous functions. This function is no longer officially recommended and was removed in PHP 8.0. You can now create anonymous functions (also known as closures) using the function keyword.
Here’s an example:
Here is the equivalent code using anonymous functions:
In addition, variables can be passed into a closure using the use keyword:
The answer is clear enough that you can rewrite the code quickly after reading the explanation.
MacOS technical support
Let’s say you have some questions about Optimize Storage on the Mac, you can ask ChatGPT directly to narrow down the search.
Q: When using the MacOS feature to Optimize Mac Storage, does the Time Machine take an incomplete backup because some files are only represented as stubs on the local machine?
If you use the MacOS feature Optimize Mac Storage, will Time Machine make incomplete backups because some files are only represented as stubs on the local machine?
ChatGPT replies: The “Optimize Mac storage” feature in MacOS uses iCloud to offload little-used files from the Mac to the cloud, while keeping a “stub” file on the local machine to represent the original. This saves space on the Mac’s hard drive.
When Time Machine is set up for backup, all files will be backed up, including those that have been uninstalled using Optimized Mac Storage, but replaced with stub files to replace the original files.
This also means that if you are restoring your Mac from a Time Machine backup and the “Optimize Mac Storage” feature is enabled, then any uninstalled files will not be included in the restore and will need to be downloaded from iCloud again.
It is important to note that if a large number of files are uninstalled, then a Time Machine backup may take up more space than if you did not use optimized Mac storage because backup stub files take up less space.
In short, if you use the “Optimize Mac storage” feature, Time Machine will make incomplete backups because it will only back up stub files, not the original files that have been unloaded to the cloud.
ChatGPT’s answer above is correct.
summarize
ChatGPT does save time on development and bug resolution.
Typically, programmers write code that requires constant debugging and a lot of Web searching to find clues from search results, including reading discussions and reviews.
Of course, the whole search process can provide a lot more information than you’ll ever get from a chatbot, and there are plenty of hidden tricks to be found in the comments section.
But when you’re in a hurry or on a critical deadline and a lot of searching is a stupid way to solve programming problems, ChatGPT has proven to be very effective.
With ChatGPT, as with any model, you have to be aware that the AI doesn’t always get the answer right, and you’ll most likely get it completely wrong, but it’s a very good tool.
But where on earth did ChatGPT get this information? Has anyone ever written an article on extract or create_function? Is someone’s knowledge being used as the source material for an answer?
As things stand now, at least for Google writers, there was once a chance that search engines would drive traffic to articles in return for sharing information, but chatbots like ChatGPT have monopolized access to information directly, and users of course get more productivity. Does anyone lose the sense of accomplishment at work?
Q: When you answer a question, do you take knowledge contributed by others, and do you derive work product from original human resources?
ChatGPT, when you answer a question, are you taking knowledge others have contributed and are you taking work and credit away from the original human sources?
ChatGPT’s answer: As an AI language model created by OpenAI, I have no personal views or ideas. But I can tell you that the information used to generate the response is based on the data I’ve been trained on, including huge amounts of text from the Internet.
This passage was written by many different people and sources, and I have no ability to credit a particular individual for the information I provide. My goal is to provide useful and accurate information to help users find the answers they are looking for.
It’s important to remember that my responses are generated based on patterns in the data I’ve been trained in and may not always be completely accurate or up to date.