TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

6 pointsby bmarottaover 2 years ago
THIS IS A TRUE STORY. (The end could have been just another ChatGPT technical issue. It was pretty slow...)<p>me: write me a regex to check if a CSS color is transparent<p>ChatGPT: Here is a regex pattern to check if a CSS color value is transparent:<p><pre><code> &#x2F;^transparent$&#x2F;i This regex uses the ^ and $ anchors to match the entire string and ensure that the value only contains &quot;transparent&quot;. The i flag at the end makes the matching case-insensitive, so it will match transparent, Transparent, and TRANSPARENT. </code></pre> me: You forgot to check for rgba, hsla and all other colors formatting where alpha can be set to 0 (including hash)<p>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:<p><pre><code> &#x2F;^(rgba|hsla)\(0,\s*0%,\s*0%,\s*0\)$|^#?0000$&#x2F;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. </code></pre> me: What about the other formats that also accept alpha (like HWB and LAB) plus the named color transparent itself from your first answer?<p>ChatGPT: Here&#x27;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:<p><pre><code> &#x2F;^(rgba|hsla|hwb|lab)\(0,\s*0%,\s*0%,\s*0\)$|^transparent$|^#?0000$&#x2F;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. </code></pre> me: There are other allowed color formats. You should read the full css specs<p>ChatGPT: An error occurred. If this issue persists please contact us through our help center at help . openai . com.

1 comment

gtirloniover 2 years ago
Can you really &quot;teach&quot; it anything though prompts? If you want robust code, you&#x27;d have to train it with codebases that exhibit robustness characteristics you&#x27;re after.