Using generative A.I. to code

Below is an example of where generative A.I. can be used to develop code for something. This is a scenario where the A.I. trains the programmer to create something. This is an example where A.I. can used to create value for both individuals (help get better at programming, inspire creativity), and society (produce something of value to others).

In this example we use generative A.I. to create a shell script that produces, and appends to, a basic html page. This blog provides feedback from the experience completing the task and aims to inspire others to “get creative”. The resulting code is intellectual property and not shared, nor is it important to the point of this blog.

NOTE – this should not be undertaken by someone novice or new to programming. It is not safe for you to run any kind of code without the requisite knowledge to review & debug code. This is where the human comes in, you are to debug (examine and correct) the output from the A.I. – this reamins mandatory.

Question 1 to A.I.

Write me some simple html code that presents a table of three columns where the left most column is sortable alphabetically. Make the code snippet easy to incorporate into a shell script that allows the user to enter the values for columns A, B and C. Shell script is to prompt the user to enter a value. Column A is to be the item name, column B is to be a hyperlink and column B is to be a short description of the item. Each time the shell script loads it prompt for new input that appends the HTML file that displays the table.

A.I. Answer

To achieve this, we’ll create a simple HTML table with JavaScript to handle the sorting of the first column. We’ll also write a shell script to prompt the user for input and append the new rows to the HTML file. Below is the HTML and JavaScript code for the sortable table, followed by the shell script.

Step 1 Conclusion:

The A.I. successfully created the code with logic. However, it did not quite get the append function right. The appended HTML code broke the page so a follow-up question is required.

Question 2 to A.I.

How to allow for a script to continuously append columns to a html table whilst preserving the closing html code.

A.I. Answer

To continuously append rows to an HTML table while preserving the closing HTML tags, we need to modify the script to ensure that it adds new rows right before the closing tags of the table and HTML document.

Here’s how you can modify the shell script to achieve this

Step 2 Conclusion

Brilliant, after a clarification question that described the issue observed, the A.I. provided some updated code and guidance on how to fix the problem. With some further tweaks and debugging the problem was resolved.

Question 3 to A.I.

For aesthetics, how can I summarise a hyperlink so that in HTML it just displays the domain part (before the forward slash)?

A.I. Answer

To display only the domain part of a hyperlink in HTML, we can use a combination of shell scripting to process the input and generate the appropriate HTML. Here’s a streamlined solution that extracts the domain from the full URL and appends the processed data to the HTML file.

Final Conclusion

In summary, there were many errors in the code the A.I. provided. You need to have the necessary programming skills and background to be able to make sense of the code and perform corrections. In programming terms this is called debugging which is generally a next stage phase of programming once you have created the initial code and defined the base-logic.

Creating the initial code and base-logic i.e. “starting from zero” is both difficult and time intensive. Especially if you have programming background, but do not regularly code. It is like having to re-learn a foreign language for example, it helps if you can talk to someone in your native tongue who can talk back to you in the other language, and help steer you so you can make sense of it.

Here is where generative A.I. is powerful, it can provide programming language back to the question describing what you need it to do. In this scenario, you are getting generative A.I. to train you and help you understand the code it produces.

You might be able to work out develop what you need purely relying on your own programming background and knowledge, Google search, or even buying a textbook… but it could take 10 times as long and for that reason you might never bother. 

Summary of the benefits of “Using Generative A.I. to code”:

This could inspire you to “get creative”It could be genuine fun going through a process like this

Be warned! Debugging is still painful but like all learning (or-relearning) processes, you should feel richer for the experience.

SAP Global AI Ethics Policy:

SAP believes that Artificial Intelligence has the potential to unlock boundless potential for businesses, governments, and society. However, AI may also create economic, political, and societal challenges, depending upon how it is used and implemented.

Our brand-new SAP Global AI Ethics Policy therefore governs the development, deployment, use, and sale of AI systems at SAP, by defining clear rules of ethics that are aligned with SAP’s established guiding principles for AI and its core organizational values.

The policy covers essential elements which are vital to build trust in AI solutions, such as transparency and explainability, human agency and oversight, addressing bias and discrimination as well as civic society.

Read more: Global AI Ethics Policy 

 

​ Below is an example of where generative A.I. can be used to develop code for something. This is a scenario where the A.I. trains the programmer to create something. This is an example where A.I. can used to create value for both individuals (help get better at programming, inspire creativity), and society (produce something of value to others).In this example we use generative A.I. to create a shell script that produces, and appends to, a basic html page. This blog provides feedback from the experience completing the task and aims to inspire others to “get creative”. The resulting code is intellectual property and not shared, nor is it important to the point of this blog.NOTE – this should not be undertaken by someone novice or new to programming. It is not safe for you to run any kind of code without the requisite knowledge to review & debug code. This is where the human comes in, you are to debug (examine and correct) the output from the A.I. – this reamins mandatory.Question 1 to A.I.Write me some simple html code that presents a table of three columns where the left most column is sortable alphabetically. Make the code snippet easy to incorporate into a shell script that allows the user to enter the values for columns A, B and C. Shell script is to prompt the user to enter a value. Column A is to be the item name, column B is to be a hyperlink and column B is to be a short description of the item. Each time the shell script loads it prompt for new input that appends the HTML file that displays the table.A.I. AnswerTo achieve this, we’ll create a simple HTML table with JavaScript to handle the sorting of the first column. We’ll also write a shell script to prompt the user for input and append the new rows to the HTML file. Below is the HTML and JavaScript code for the sortable table, followed by the shell script.Step 1 Conclusion:The A.I. successfully created the code with logic. However, it did not quite get the append function right. The appended HTML code broke the page so a follow-up question is required.Question 2 to A.I.How to allow for a script to continuously append columns to a html table whilst preserving the closing html code.A.I. AnswerTo continuously append rows to an HTML table while preserving the closing HTML tags, we need to modify the script to ensure that it adds new rows right before the closing tags of the table and HTML document.Here’s how you can modify the shell script to achieve thisStep 2 ConclusionBrilliant, after a clarification question that described the issue observed, the A.I. provided some updated code and guidance on how to fix the problem. With some further tweaks and debugging the problem was resolved.Question 3 to A.I.For aesthetics, how can I summarise a hyperlink so that in HTML it just displays the domain part (before the forward slash)?A.I. AnswerTo display only the domain part of a hyperlink in HTML, we can use a combination of shell scripting to process the input and generate the appropriate HTML. Here’s a streamlined solution that extracts the domain from the full URL and appends the processed data to the HTML file.Final ConclusionIn summary, there were many errors in the code the A.I. provided. You need to have the necessary programming skills and background to be able to make sense of the code and perform corrections. In programming terms this is called debugging which is generally a next stage phase of programming once you have created the initial code and defined the base-logic.Creating the initial code and base-logic i.e. “starting from zero” is both difficult and time intensive. Especially if you have programming background, but do not regularly code. It is like having to re-learn a foreign language for example, it helps if you can talk to someone in your native tongue who can talk back to you in the other language, and help steer you so you can make sense of it.Here is where generative A.I. is powerful, it can provide programming language back to the question describing what you need it to do. In this scenario, you are getting generative A.I. to train you and help you understand the code it produces. You might be able to work out develop what you need purely relying on your own programming background and knowledge, Google search, or even buying a textbook… but it could take 10 times as long and for that reason you might never bother. Summary of the benefits of “Using Generative A.I. to code”:This could inspire you to “get creative”It could be genuine fun going through a process like thisBe warned! Debugging is still painful but like all learning (or-relearning) processes, you should feel richer for the experience.SAP Global AI Ethics Policy:SAP believes that Artificial Intelligence has the potential to unlock boundless potential for businesses, governments, and society. However, AI may also create economic, political, and societal challenges, depending upon how it is used and implemented.Our brand-new SAP Global AI Ethics Policy therefore governs the development, deployment, use, and sale of AI systems at SAP, by defining clear rules of ethics that are aligned with SAP’s established guiding principles for AI and its core organizational values.The policy covers essential elements which are vital to build trust in AI solutions, such as transparency and explainability, human agency and oversight, addressing bias and discrimination as well as civic society.Read more: Global AI Ethics Policy    Read More Technology Blogs by SAP articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author

+ There are no comments

Add yours