DEV Community

Kevin Naidoo
Kevin Naidoo

Posted on • Edited on

56 3 3 3 2

Dangers of AI coding tools

I have written hundreds of thousands of lines of code over my 15 years; writing some types of code has become tedious and well frankly, just boring. File uploads, CRUD, forms 🥱.

This is why I use AI, it can do the scaffolding for me so that I can focus on more interesting stuff.

I don't however just blindly copy-and-paste, I review all the code generated and optimize or tweak where needed.

A simple hack

Earn your stripes first, it may be tempting to just ask AI but this is dangerous because you are relying on a tool that could give you wrong advice. Having little to no experience, you probably won't pick up discrepancies.

Here's an AI generated example:

     if ($request->hasFile('file')) {
            $file = $request->file('file');
            $fileName = Str::uuid() . '.' . $file->getClientOriginalExtension();

            // Store in public/storage/uploads/tinymce
            $path = $file->storeAs(
                config('tinymce.upload_path'),
                $fileName,
                'public'
            );

            return response()->json([
                'location' => Storage::url($path)
            ]);
        }
Enter fullscreen mode Exit fullscreen mode

This is a basic example, but a good reference to drive home my point. Many things are wrong here, but the most important is that there's no mime-type validation.

The code probably works just fine, it'll upload the file and return a success message. A junior dev might move on and assume everything is okay!

The problem comes in when a malicious user uploads a bad file that can be a virus or some kind of hack, now you have compromised your whole app and your users too!

A better approach would be to use Laravel's validator and apply some validation rule checks:

 $request->validate([
    'file' => 'required|file|image|mimes:jpeg,png,jpg,gif|max:5120'
 ]);
Enter fullscreen mode Exit fullscreen mode

Advice for junior developers

Should you use AI? Absolutely! Use AI to quickly look up information and even generate code where it makes sense, this is perfectly fine.

Never! Ever! just rely on AI to make architectural decisions for you, or blindly trust it either. Simply copying and pasting code without reviewing it first is just asking for trouble. Instead, deepen your understanding by reading, learning, and always striving towards mastery.

Understanding the logic behind the code you are writing is important because AI cannot think for itself or understand the full context in which that code will run. It's just a fancy algorithm that's predicting the next best sentence, paragraph, or body of code.

The best way to become good at anything is to just roll up your sleeves and put in the work, build projects on your own without AI first, and learn the fundamentals until they become second nature.

PS: If you looking for more in-depth WebDev and AI-related content, please consider visiting and following me on my blog at kevincoder.co.za. I would really appreciate your support 🙏.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (21)

Collapse
 
xwero profile image
david duymelinck

I agree, never add generated code as is.

Before AI we had tutorials where people didn't add good practices, because they want to show something working. And beginners just copy-pasted the code.

I think with AI that problem could get bigger, especially when AI generates larger and larger chunks of code. I think even for seasoned developers it is going to be harder to do code checking.
You could use different AI solutions for code generation and code review, and then spot check the code. Solutions like Devin are the same as one person that is in charge of writing the code and reviewing it. We know that causes blind spots.

Collapse
 
kwnaidoo profile image
Kevin Naidoo

Thanks for reading, yeah this is so true! I guess we have to be more vigilant in PRs to ensure this junk code doesn't creep in. Also, static analyzers and other related code scanners will become more important than ever.

Collapse
 
timexpeachtree profile image
Timex Peachtree

Yeas the code checking and best practices helps a lot, also I think making different AI models review that code can give little bit insights like having another pair of eyes 👀 reading over them.

Collapse
 
orlando_villa_86bd0db6d42 profile image
orlando villa

AI dev tools are just that... a tool!
Sorry world, magic is not real.

Collapse
 
motss profile image
Rong Sen Ng

AI coding tool is like an assistant. If you expect it to do everything for you you basically make yourself redundant because you know nothing at the end of the day. Not even when you're being replaced.

Collapse
 
vijay_sf_24f69e55a29344c9 profile image
Vijay sf

Agree on that 100% , everything we talk is processed to evolve AI. Good and bad, everything

Collapse
 
elbugz profile image
Greg Brown

AI is the new stackoverflow.... Sad.
I see time and time again young coders just blindly copy&pasting stuff generated.

We should look at AI as a "rubber ducky on steroids", it helps you out a great deal, but it is still just as susceptible to errors as we are if not more.
I time and time again have to review code and point out flaws. It is an ever going process of teaching my younger devs to take all the help with a grain of salt. Teach them to think critically at what AI or other devs suggest.

Cheers

Collapse
 
paalaleks profile image
Paal Aleksander Kaasa • Edited

I agree with most of what you say, but if you watch tutorial where the teacher write with ai , they have an enormous context file that they save everything ai need to know about the app it’s making.

So when you actively use the context file – normally written as .md file – the ai copilot will have a good idea about what it’s going towards. It’s good for human intelligence too, so we don’t forget where we’re heading and what’s already behind us 😊🤖

I’m not a fan of kanban lists and other check lists and I tend to forget about using it. But having a features lists , a todo lists, etc, inside cursor together with other ai context material, and keeping it up to date, is a total game changer for me. ✔️👍

Collapse
 
kwnaidoo profile image
Kevin Naidoo • Edited

Thanks for reading and engaging on this topic; awesome, glad that you have a good process going there. Sounds a bit like BDD(Behavior-driven development).

The only caveat is that LLMs don't read for meaning, and as your input token context grows, usually the quality of the generation drops. Now, a lot of these IDEs do use "chain of thought" prompts and Agents to get around this issue, but still, LLMs have no worldview so it'll always be a hit and a miss. Sometimes you'll get good results, other times not.

Collapse
 
paalaleks profile image
Paal Aleksander Kaasa

Could be a caveat, certainly. The main take away for me lately is that kanbans and todos has been outside of IDEs before cursor – that’s breaking ground – and "dead" documents, but now docs like these put to use much more than before . Before it was just an extra task updating these docs , but now you get so much more value for work documents inside IDEs.

Collapse
 
brense profile image
Rense Bakker

Generating code with AI is super dangerous. Coding with AI assistance is amazing though. You need to know what you expect it to write, so you know the AI is wrong when it writes something else. I just use it as a tool to type faster and give me suggestions. Take a look at codeium.com/windsurf, it's amazing!

Collapse
 
kwnaidoo profile image
Kevin Naidoo

Thanks. I briefly did play with "Windsurf" and others, but I didn't like it. Nothing wrong with this IDE. It worked great! Just my personal preference.

VScode has Tabnine, it's mature and doesn't get in my way but is good enough to help me remember object properties and things like that, often these IDE's will suggest code that is overengineered and I end up re-writing it anyway, so why not just write it myself.

Collapse
 
omnikron13 profile image
Joey Sabey

Very much how I've been treating AI; it's a fancy and nice-to-have completion engine.

Collapse
 
orangelckc profile image
KC

Agreed. The single most important advice for developers using AI assistants: DON'T ACCEPT ALL.

Collapse
 
riya_marketing_2025 profile image
Riya

Great advice! Use AI as a tool, but always review and understand the code to avoid potential risks.

Collapse
 
vampiredev profile image
My Lovely Friend

100% agree.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay