Remix.run Logo
triyambakam 7 hours ago

This is the take when you haven't really tried driving these tools with much practice

nickjj 28 minutes ago | parent [-]

I don't think it's that

Here's an example from Gemini with some Lua code:

    label = key:gsub("on%-", ""):gsub("%-", " "):gsub("(%a)([%w_']*)", function(f, r) 
      return f:upper() .. r:lower() 
    end)

    if label:find("Click") then
      label = label:gsub("(%a+)%s+(%a+)", "%2 %1")
    elseif label:find("Scroll") then
      label = label:gsub("(%a+)%s+(%a+)", "%2 %1")
    end
I don't know Lua too well (which is why I used AI) but I know programming well enough to know this logic is ridiculous.

It was to help convert "on-click-right" into "Right Click".

The first bit of code to extract out the words is really convoluted and hard to reason about.

Then look at the code in each condition. It's identical. That's already really bad.

Finally, "Click" and "Scroll" are the only 2 conditions that can ever happen and the AI knew this because I explained this in an earlier prompt. So really all of that code isn't necessary at all. None of it.

What I ended up doing was creating a simple map and looked up the key which had an associated value to it. No conditions or swapping logic needed and way easier to maintain. No AI used, I just looked at the Lua docs on how to create a map in Lua.

This is what the above code translated to:

    local on_event_map = {
      ["on-click"] = "Left Click",
      ["on-click-right"] = "Right Click",
      ["on-click-middle"] = "Middle Click",
      ["on-click-backward"] = "Backward Click",
      ["on-click-forward"] = "Forward Click",
      ["on-scroll-up"] = "Scroll Up",
      ["on-scroll-down"] = "Scroll Down",
    }

    label = on_event_map[key]
IMO the above is a lot clearer on what's happening and super easy to modify if another thing were added later, even if the key's format were different.

Now imagine this. Imagine coding a whole app or a non-trivial script where the first section of code was used. You'd have thousands upon thousands of lines of gross, brittle code that's a nightmare to follow and maintain.