Home > Article > Technology peripherals > ChatGPT’s powerful programming capabilities made me break out in a cold sweat!
Recently, several people gave me Amway ChatGPT, telling me, Lao Liu, go check it out. This product is so powerful that maybe all of us programmers will lose our jobs.
I just smiled slightly at first, how could it be possible? My previous view has always been that in my lifetime, AI will never be able to kill programmers.
But there are so many people selling Amway, I can’t help but register an account and take a look.
Unexpectedly, this product is not open to China. There are some strategies on the Internet. I find it troublesome, so I quickly call a good friend abroad and ask him to help register an account.
To try to get started, I decided to skip those simple questions and answers, such as:
How to reverse a string?
How to initiate an HTTP call?
Because this kind of thing is too childish for an AI that has read countless codes, and it is impossible to test how powerful it is.
One of the core abilities of a programmer is to obtain requirements and be able to make elegant designs. Let's test it on this point.
Let me ask a simple question first:
(Click to see the larger image)
As expected, it "recited" very well!
The last principle it says is: Try to use synthesis/aggregation instead of inheritance to achieve reuse. This is indeed an important design principle of object-oriented.
Can ChatGPT apply such a principle?
First ask if it can do design:
That’s really good, let’s start To zoom in, I happen to have a classic case on hand: salary payment, which is extracted from the classic book "Agile Software Development: Principles, Patterns and Practices".
The requirements of this case are as follows:
The system consists of a company database and employee-related data. The system needs to be updated on time Pay employees according to the rules
There are three types of employees
1. Hourly employees, who have a fixed pay per hour, and they submit their working hours every day Card, which records the date and hours worked. If you work more than 8 hours a day, you will be paid at 1.5 times. They are paid every Friday.
2. Monthly salary employees, their wages are fixed, and they are paid on the last working day of each month
3. Sales staff, there are They receive a fixed salary, but are paid a certain amount of commission based on their sales, and they submit sales receipts recording the date and quantity of the sale. They are paid every other Friday.
Employees can choose the payment method. They can mail the check to their designated postal address, save it in the finance department and withdraw it at any time, or request it to be deposited directly into their designated bank account.
After reading this requirement, the general design is as follows:
Employee as the base class , different types of employee classes inherit.
But this requirement will change. The customer requires that the employee type can be changed, for example from hourly employee to monthly salary employee, so the above design will not work.
At this time, we should make an abstraction, use a class PaymentClassification to express the payment classification, and then let the Employee class hold this instance. Simply put, use Composition replaces inheritance.
##This is equivalent to a trap, we programmers can Identification, abstraction, can this ChatGPT be used? I'm really a little curious.
Ask about the initial requirements first. ChatGPT’s answer is this:
(Click to see the larger image)Don’t tell me, it’s really good. It “understands” the requirements, extracts nouns from them to design classes, and designs the inheritance relationships of classes. Has reached the primary level of object-oriented design. The next step is to dig a hole for him: ##It’s amazing, this guy actually learned abstraction!Although the type it abstracts is called EmployeeType, which is not as precise as PaymentClassification, the general direction is the same: use EmployeeType to manage payment rules. When the employee type changes, the Employee class does not need to change.
To be honest, I was very surprised when I saw it give this result. It can be said that it can surpass quite a few programmers.
Next I asked it how to deal with
payment cycle:
This time its abstraction is even more powerful and it is given directly The precise name:
PaymentSchedule, as well as the relevant pseudocode!
It also specifically mentioned that when the payment cycle needs to be modified, just Just change the PaymentSchedule without modifying the original employee class.
Combination is better than inheritance, which is reflected again. This is almost the same as the example in the book:
Continue to ask
Payment methodprocessing method:
As expected, its design is still great:
In fact, the design of ChatGPT is very close to the final version in the book Plan:
After trying this, I feel a little disappointed and unwilling. This ChatGPT is really powerful, showing strong design capabilities, and the conversation process is very smooth .
Can artificial intelligence really understand requirements, learn abstraction, and design beautiful class structures? The core competencies of programmers have been replaced. Is the crisis of programmers really coming?
I asked it another question and asked it to draw the class:
Wait a minute, why is the class name here different from the previous one? How come a new concept appears: Union Member? During this conversation, I never told it this concept! Where did it know that?
The biggest possibility is that this guy didn't understand the needs I told it. It should have studied this case before, and it is still "reciting" what it has learned, and it has taken the initiative to treat the union members as well. I got it out, thus revealing the truth.
I closed the ChatGPT website, logged in again, and interacted with it again using the same content. This time the result was completely exposed.
Did you see that this time it did not abstract PaymentClassification/EmployeeType at all, it actually recommended process-oriented ideas , add a type attribute and use switch to solve the problem. This is much worse than the previous plan.
Finally, let’s talk about your feelings! ChatGPT is indeed very powerful. It should have learned a huge amount of data and has a lot of stuff in its belly, but it still has no real need for understanding. The answer it tells us is to refine and integrate existing knowledge.
If you throw it a completely new field problem, it will probably be confused. You can play with actual business problems.
So, ChatGPT is a good helper, but if you want to completely rely on it, you have to weigh it carefully. What it tells you may be elegant code or junk code.
The above is the detailed content of ChatGPT’s powerful programming capabilities made me break out in a cold sweat!. For more information, please follow other related articles on the PHP Chinese website!