Also on LinkedIn here: https://www.linkedin.com/pulse/why-ai-going-replace-developers-any-time-soon-ron-parker-om0kc/
I have been working with JavaScript and PHP as a developer for well over 20 years. I have been working with A.I. (Artificial Intelligence) for a little under 2 years. Like you, I keep seeing all these stories about how A.I. is going to replace that worker and this job and transform productivity in the world. I am particularly taken by the claims by the Devin and Nvidia CEOs about how A.I. is going to make Developers obsolete.
As a 40+ year Developer (yes, I began writing programs in the 1970s) who has wholeheartedly embraced A.I. as a coding assistant, I’m simply not that sure what we do is going away any time soon. The proponents of this dark future always seem to point to their A.I. being able to create complicated games and generate sophisticated applications to do this thing or that thing. But I rarely see real world business examples, or the nuts and bolts of actually “developing” a working, real world solution.
I’ve been intending for the longest to provide an example of how I interact with A.I., but I’m usually so busy trying to solve the next problem that I rarely get that chance. I decided today to stop and offer an illustration.
I am, in fact working on an A.I. application that runs within the Drupal framework in PHP and Javascript. I had a simple task I needed code for: How to keep a collapsible element on a form open between submissions.
The element is called “Advanced Options”, and below you see examples of it opened and collapsed. All I wanted to do was make sure that it stayed in the same state between form submissions.
My full conversation on the subject with the A.I. is here: https://s3.us-west-2.amazonaws.com/docs.scbbs.com/docs/test/advancedOptionsOpen.pdf
I used OpenAI’s ChatGPT gpt-4o model which redacts the uploaded images when it exports the chat.
This is a summary of the entire chat, created by Google gemini-1.5-pro A.I.:
Advanced Options Toggle State
To preserve the state of the "Advanced Options" section between form submissions, you can store its open/closed state in a hidden field and update that value on each submission. Here's how to modify your code to keep the section either open or closed based on the user's last interaction:
- Add a Hidden Field for State Tracking: Include a hidden field to store the open/closed state of the "Advanced Options" section.
- Update State Based on User Interaction: Use JavaScript to toggle the hidden field value based on whether the section is open or closed.
- Set the Default Open State on Form Rebuild: Use the hidden field's value to set the default open state when rebuilding the form.
Here's an example of how to do this:
Step 1: Add a Hidden Field
Add a hidden field to store the state in your form definition:
PHP
// Hidden field to store the open/closed state.
$form['advanced_options_open'] = [
'#type' => 'hidden',
'#default_value' => $form_state->getValue('advanced_options_open') ?? FALSE,
];
Step 2: Use JavaScript to Toggle the State
Add JavaScript to set the hidden field's value when the user opens or closes the "Advanced Options" section. Attach this script to your form:
PHP
$form['#attached']['library'][] = 'core/drupal.ajax';
$form['#attached']['library'][] = 'yourmodule/custom_toggle_script'; // Add your custom JS file
In your custom JavaScript file (custom_toggle_script.js):
JavaScript
(function ($, Drupal) {
Drupal.behaviors.toggleAdvancedOptions = {
attach: function (context, settings) {
$('#edit-advanced-options', context).once('toggleAdvancedOptions').on('click', function () {
const isOpen = $(this).attr('open') === 'open';
$('#edit-advanced-options-open').val(isOpen ? 1 : 0); // Set hidden field based on open state
});
}
};
})(jQuery, Drupal);
Step 3: Set the Default Open State on Form Build
In your form definition, set the #open property based on the hidden field value:
PHP
$form['advanced_options']['#open'] = (bool) $form_state->getValue('advanced_options_open', FALSE);
Full Example with Changes Integrated
Here's how your modified code would look:
PHP
// Create a collapsible fieldset for advanced options
$form['advanced_options'] = [
'#type' => 'details',
'#title' => $this->t('Advanced Options'),
'#open' => (bool) $form_state->getValue('advanced_options_open', FALSE), // Set open state
];
// Hidden field to track open/closed state
$form['advanced_options_open'] = [
'#type' => 'hidden',
'#default_value' => $form_state->getValue('advanced_options_open') ?? FALSE,
];
// Rest of your form definition remains unchanged
// Attach custom JavaScript to handle toggle state
$form['#attached']['library'][] = 'solrai/solrai.styles';
$form['#attached']['library'][] = 'yourmodule/custom_toggle_script'; // Attach the custom JavaScript
By implementing this change, the form will keep the "Advanced Options" section open or closed based on the user's last action. Each time the form is submitted, the hidden field updates with the current state, allowing you to control the open state on form rebuilds.
Simple enough, right? But this simple coding project which should have taken less than an hour to complete took upwards of 6 hours. Why? Two reasons:
- A.I. is not human. It does not possess intuition or human experience or any real understanding of what it is doing and/or saying.
- I was lazily depending upon the A.I. to do all the work without having to think much about it.
Now, if A.I. is going to actually replace developers in a simple assignment like this, this particular model and example sure doesn’t prove it. It made some pretty egregious errors (or, more like oversights), of which it should have been keenly aware. For example:
- While it immediately give me the JS (Javascript) code I needed to track the state of the Advanced Options toggle, it did not mention that I needed to define custom_toggle_settings.js in libraries.yml, a standard for declaring JS scripts in Drupal. (page 2)
- It outright declared, incorrectly, how the JS should be attached to the form. You will see that I asked it early on what was the correct format to use (page 3) as I have done this many times and suspected the code it was giving me was incorrect. I tested it myself, and of course, it was incorrect. (page 17)
- It did not realize that the JS code could not recognize the form field used because that field was declared “hidden”. You can argue that I should have known that, but I didn’t -- because I expected the A.I. to tell me if that was the case. Especially since most of the 6 hours spent was caused by this one oversight. (pages 46, 47, 48)
- I had to suggest to it to declare the Advanced Options (advanced_options_open) element in submitForm to preserve the state between submits. It should have known that. (page 25)
There were a few other little things, but the point is that these “little” things I listed above took the observation, testing and initiative (based upon experience) of a human Developer to make sure the A.I. developed the code correctly.
My question to all the CEOs pushing A.I. to replace Developers, Writers, Animators, Graphic Artists, Legal Assistants, Copy Writers, etc… When the A.I. is in control of the entire process, who is going to debug the A.I. when it’s wrong?
This may seem like a silly question, but it will be the most important one to ask when you are leveraging the future of your business on this technology.