How To Use ChatGPT to Code: Part 1
This is a tipping point. All coders can either get creative or rest in shattered pieces.
I’ll keep everything as short as possible. Italics means ChatGPT output.
Bold means my input to the chat to keep things going.
The website is:
Question 1)
Source code of a cross-platform Avalonia FuncUI CRUD application using F#.NET
Answer: 1)
open Avalonia
open Avalonia.Controls
open Avalonia.Markup.Xaml
type MainWindow() =
inherit Window()
let mutable _items = ["Item 1"; "Item 2"; "Item 3"]
let mutable _selectedItem = ""
let listBox = new ListBox()
let textBox = new TextBox()
let addButton = new Button()
let deleteButton = new Button()
do
listBox.Items <- _items
listBox.SelectionChanged.Add(fun _ ->
_selectedItem <- listBox.SelectedItem.ToString()
textBox.Text <- _selectedItem)
addButton.Content <- "Add"
addButton.Click.Add(fun _ ->
_items <- _items @ [textBox.Text]
listBox.Items <- _items)
deleteButton.Content <- "Delete"
deleteButton.Click.Add(fun _ ->
_items <- _items |> List.filter (fun item -> item <> _selectedItem)
listBox.Items <- _items)
AvaloniaXamlLoader.Load(self)
type App() =
inherit Application()
override this.OnFrameworkInitializationCompleted() =
base.OnFrameworkInitializationCompleted()
let window = new MainWindow()
window.Show()
this.MainWindow <- window
[<STAThread; EntryPoint>]
let main argv =
App().Start(argv)
0
This code defines a MainWindow
class that contains a list box for displaying a list of items, a text box for adding or modifying items, and two buttons for adding and deleting items. The MainWindow
class also has a list of items and a selected item that are used to update the list box and text box.
The App
class is the entry point for the application and creates an instance of MainWindow
and displays it.
To use this code, you will need to create an Avalonia project and add the code to the appropriate files. You can find more information about creating Avalonia projects and using FuncUI in the Avalonia documentation: https://avaloniaui.net/docs/getting-started.
All F#.NET coders — how does getting replaced by automation feel like? And this is the beta, not the final version.
Continued at https://thomascherickal.hashnode.dev/how-to-code-with-chatgpt-part-2
Because neither Medium or HackerNoon has the code support that HashNode has.