Settings

Theme

Teaching ChatGPT how to write robust code (it is just another lazy developer)

6 points by bmarotta 3 years ago · 1 comment · 2 min read


THIS IS A TRUE STORY. (The end could have been just another ChatGPT technical issue. It was pretty slow...)

me: write me a regex to check if a CSS color is transparent

ChatGPT: Here is a regex pattern to check if a CSS color value is transparent:

         /^transparent$/i

         This regex uses the ^ and $ anchors to match the entire string and ensure that the value only contains "transparent". The i flag at the end makes the matching case-insensitive, so it will match transparent, Transparent, and TRANSPARENT.

me: You forgot to check for rgba, hsla and all other colors formatting where alpha can be set to 0 (including hash)

ChatGPT: Here is a more comprehensive regex pattern to check if a CSS color value is transparent, including formats such as rgba, hsla, and hash colors with an alpha value of 0:

         /^(rgba|hsla)\(0,\s*0%,\s*0%,\s*0\)$|^#?0000$/i

         This pattern matches the following formats:

             rgba(0, 0%, 0%, 0)
             hsla(0, 0%, 0%, 0)
             #0000
             #000000

         The i flag at the end makes the matching case-insensitive, so it will match rgba(0, 0%, 0%, 0), RGBA(0, 0%, 0%, 0), hsla(0, 0%, 0%, 0), etc.

me: What about the other formats that also accept alpha (like HWB and LAB) plus the named color transparent itself from your first answer?

ChatGPT: Here's a regex pattern that matches all the CSS color values that can be transparent, including rgba, hsla, named color transparent, and the other color formats that can have an alpha value of 0:

         /^(rgba|hsla|hwb|lab)\(0,\s*0%,\s*0%,\s*0\)$|^transparent$|^#?0000$/i

         This pattern matches the following formats:

             rgba(0, 0%, 0%, 0)
             hsla(0, 0%, 0%, 0)
             hwb(0, 0%, 0%, 0)
             lab(0, 0%, 0%, 0)
             transparent
             #0000
             #000000

         The i flag at the end makes the matching case-insensitive, so it will match rgba(0, 0%, 0%, 0), RGBA(0, 0%, 0%, 0), transparent, etc.

me: There are other allowed color formats. You should read the full css specs

ChatGPT: An error occurred. If this issue persists please contact us through our help center at help . openai . com.

gtirloni 3 years ago

Can you really "teach" it anything though prompts? If you want robust code, you'd have to train it with codebases that exhibit robustness characteristics you're after.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection