The current title doesn’t fully capture the depth of this idea, and I can’t think of any existing application that offers what is being proposed.
At present, when using GPT-4o with canvas
in coding mode, you interact with a single canvas displaying code and a separate prompt window for conversational changes. While this setup works, many changes would be far more effective with the addition of a second canvas dedicated to a declarative outline of the code.
In essence, writing code often begins with a simple, declarative prompt. As the code evolves, the prompt grows richer, effectively acting as a progressively detailed outline. This new way would introduce a declarative outline in a second canvas that could then serve as a living blueprint for both developing and maintaining the code.
The workflow could be as follows: users modify the declarative outline, and ChatGPT updates the corresponding code in the other canvas. If errors arise, they are reported back to ChatGPT in the conversation, which adjusts both the code and the outline accordingly.
By the end of the process, not only would you have functional code, but also a clear declarative outline that doubles as documentation. This outline could even be used as a self-contained prompt to recreate the code, streamlining the development process while providing a built-in reference for future use.
A potential future enhancement could work with modular code, for example, an object-oriented design with classes. This would allow each component to be maintained in its own canvas, effectively overcoming the size limitations of a single canvas. These limitations often necessitate abandoning the use of canvas entirely for larger projects.
Additionally, since much code is hierarchical in nature, ChatGPT can often infer code concepts accurately when certain parts are replaced with descriptive comments, such as:
class XYZ(A, B, C):
# Implementation goes here
This approach enables the handling of more complex code structures while maintaining clarity and modularity.
While I mostly program, this pattern of placing an outline between the prompting and created result can be used for more than just coding.
- Writing a book
- Creating a picture with DALL*E
- Composing a song (haven’t done this yet)
For a recent small prototype code used this prompt to create the outline
Create a detailed declarative outline that can be used as a prompt to recreate the code and also serve as user documentation.
This created the following which when used as prompt for GPT-4o created a working page very similar to the original but with some differences and errors but fairly close considering the level of detail.
Outline
Declarative Outline for Code Creation and Documentation
Overview
This application demonstrates an event-driven architecture where a Model validates all inputs and handles state changes, while multiple Views interact with the Model through a central Message Bus. Each View displays errors and updates dynamically based on feedback from the Model. This design is suitable for scenarios requiring decoupled components with centralized validation.
Components
1. Model
The Model serves as the single source of truth. It:
- Holds three key pieces of data:
primaryValue
: A number that represents the main value of the system.min
: The minimum allowable value forprimaryValue
.max
: The maximum allowable value forprimaryValue
.
- Performs all data validation:
- Ensures
primaryValue
is within the range[min, max]
. - Validates that
min
is less thanmax
.
- Ensures
- Emits events for success and failure through the Message Bus:
primaryValueChanged
: Broadcast whenprimaryValue
is successfully updated.rangeUpdated
: Broadcast whenmin
andmax
are successfully updated.error
: Broadcast when validation fails (indicating the source of the error and a descriptive message).
2. Message Bus
The Message Bus is implemented using the EventTarget
API to:
- Facilitate communication between the Model and Views.
- Allow any component to dispatch and listen for events.
3. Views
Each View is a self-contained UI component responsible for displaying data, receiving user input, and reacting to events from the Model.
a. View A: Up/Down Control
- Displays:
- A title:
"Up/Down Control"
- Two buttons:
"+"
and"-"
for incrementing and decrementingprimaryValue
. - The current value of
primaryValue
as text. - An error message area.
- A title:
- Behavior:
- Dispatches
requestPrimaryValueChange
when buttons are clicked. - Updates its value display on
primaryValueChanged
. - Displays error messages on
error
(if the source isprimaryValue
).
- Dispatches
b. View B: Keyboard Input
- Displays:
- A title:
"Keyboard Input"
- A text input field for entering
primaryValue
. - An error message area.
- A title:
- Behavior:
- Dispatches
requestPrimaryValueChange
with the entered value. - Updates its input value on
primaryValueChanged
. - Displays error messages on
error
(if the source isprimaryValue
).
- Dispatches
c. View C: Horizontal Slider
- Displays:
- A title:
"Horizontal Slider"
- A slider input (
<input type="range">
) for modifyingprimaryValue
. - The current value of
primaryValue
as text.
- A title:
- Behavior:
- Dispatches
requestPrimaryValueChange
with the slider’s value. - Updates its slider position and value display on
primaryValueChanged
.
- Dispatches
d. Limit View
- Displays:
- A title:
"Set Range"
- Two input fields for
min
andmax
. - A button labeled
"Set"
for submitting the range. - The current range
[min, max]
as text. - An error message area.
- A title:
- Behavior:
- Dispatches
requestRangeChange
with the newmin
andmax
. - Updates the displayed range on
rangeUpdated
. - Displays error messages on
error
(if the source isrange
).
- Dispatches
Events
Dispatched by Views
-
requestPrimaryValueChange
:- Payload:
value
: The newprimaryValue
or the amount to increment/decrement.operation
(optional):"increment"
for relative changes, otherwise absolute.
- Purpose: Request the Model to validate and update
primaryValue
.
- Payload:
-
requestRangeChange
:- Payload:
min
: The new minimum value.max
: The new maximum value.
- Purpose: Request the Model to validate and update the range.
- Payload:
Dispatched by the Model
-
primaryValueChanged
:- Payload:
value
: The successfully updatedprimaryValue
.
- Purpose: Notify Views to update their displays.
- Payload:
-
rangeUpdated
:- Payload:
min
: The updated minimum value.max
: The updated maximum value.
- Purpose: Notify Views to update the displayed range.
- Payload:
-
error
:- Payload:
source
: The source of the error ("primaryValue"
or"range"
).message
: A descriptive error message.
- Purpose: Notify Views to display appropriate error messages.
- Payload:
UI Behavior and Error Handling
-
Validation Delegation:
- Views pass all input to the Model without validation.
- The Model validates the input and sends success or error feedback.
-
Dynamic Updates:
- On success:
- All Views update their displays based on
primaryValueChanged
orrangeUpdated
.
- All Views update their displays based on
- On failure:
- The View that initiated the change displays the error message from the
error
event.
- The View that initiated the change displays the error message from the
- On success:
Usage Example
Setting a Range
- User enters
min = 10
andmax = 5
in the Limit View. - Limit View dispatches
requestRangeChange
with{ min: 10, max: 5 }
. - The Model validates and emits an
error
with:source: "range"
message: "Invalid range. Min must be less than Max."
- Limit View displays the error message.
Updating Primary Value
- User clicks
+
in View A. - View A dispatches
requestPrimaryValueChange
with{ value: 1, operation: "increment" }
. - The Model adds
1
to the currentprimaryValue
(if valid) and emits:primaryValueChanged
with the new value.
- All Views update their displays to reflect the new value.
Extensibility
-
Adding New Views:
- Create a new View component that listens for
primaryValueChanged
,rangeUpdated
, anderror
. - Dispatch events as needed (e.g.,
requestPrimaryValueChange
orrequestRangeChange
).
- Create a new View component that listens for
-
Extending Validation:
- Modify the
Model
to include additional validation rules. - Use the
error
event to notify Views of new validation errors.
- Modify the
This declarative outline can serve as both a prompt for recreating the code and user documentation for understanding how the system works. Let me know if you’d like further refinements or additions!