Knowing how to code, and having a lot of experience and an "intuitive" sense of what is a good idea and what is a bad idea, also puts you in a position to question the advice the AI gives you. Just now I was asking Claude to help me with an issue with a React component and it told me to add useEffect with a timer. I am not a React expert, but that immediately felt like a code smell to me, so I followed up:
> is it weird or an anti-pattern to use a timer like this?
The response:
> Yes, using a timer like this is generally considered an anti-pattern in React for several reasons: It introduces non-deterministic behavior (timing-dependent code), It's a workaround rather than addressing the root cause, It can be brittle and lead to race conditions.
I'm sure all those things are true. This is a classic example of the problem with people using AI programming tools but lacking a real understanding of what they're doing. They don't know enough to question the advice they're getting, let alone properly review the code its generating.
The other day, in a Rails app, Claude generated a bunch of code that spawned various threads to accomplish certain things I needed to do asynchronously. Maybe these days, in Ruby 3 and Rails 8, this is safe. But I remember that back in the Rails 2 days, going off and spawning new threads was not a good idea. Plus, I have a back-end async job processor already set up. Again, I questioned the approach. The revised code I got back was a lot simpler, and once I'd reviewed and tested it, I (mostly) used it as-is.
that's the thing if your inquisitive and have an interest in learning things then you can still go far with AI coding. can you explain why this code works?
is this the best way to do it or are there other solutions? what are the pros and cons?
are there security problems with this? how could I make this code more secure?
what are some things I should look out for with AI coding(meta question)?
what does this error mean?
just talking back and forth with the AI on the phone you can get a high level understanding of a topic pretty quickly and way more in depth and personalized than a tutorial on the internet.
> is it weird or an anti-pattern to use a timer like this?
The response:
> Yes, using a timer like this is generally considered an anti-pattern in React for several reasons: It introduces non-deterministic behavior (timing-dependent code), It's a workaround rather than addressing the root cause, It can be brittle and lead to race conditions.
I'm sure all those things are true. This is a classic example of the problem with people using AI programming tools but lacking a real understanding of what they're doing. They don't know enough to question the advice they're getting, let alone properly review the code its generating.
The other day, in a Rails app, Claude generated a bunch of code that spawned various threads to accomplish certain things I needed to do asynchronously. Maybe these days, in Ruby 3 and Rails 8, this is safe. But I remember that back in the Rails 2 days, going off and spawning new threads was not a good idea. Plus, I have a back-end async job processor already set up. Again, I questioned the approach. The revised code I got back was a lot simpler, and once I'd reviewed and tested it, I (mostly) used it as-is.