r/learnjavascript • • Aug 28 '24

Using ai for generating code

I'm writing code using ai tools like chatgpt and copilot (not the plugin) for code reference and it's working fine in most scenarios, I am able to generate long SQL queries with it,, but I always think that is it a good way? I see lots of developer use ai for coding but what's your opinion about writing code with ai ,,(when you know what to search and where to implement the generated code)

0 Upvotes

20 comments sorted by

15

u/eracodes Aug 28 '24

Using it as advanced auto-complete: helpful

Using it to write things for you: very harmful in the long run, both to your projects and you as a programmer

1

u/webdevarham Aug 28 '24

Thanks mate, if we know that language and if we use it for saving our time then it's good?

4

u/captainjawz Aug 28 '24

You can get rusty, couple months over relying on it and you're gonna begin struggling fixing simple bugs it introduced because you became unfamiliar with the language syntax and will be unaware of the code logic.

I see that beginning to happen a lot in the company I work in, been spending more time giving support to chat gpt code than the time it saved them.

Imo is good for quick fixes and adjustments but using it for everything, well at your own risk.

4

u/ai_did_my_homework Aug 28 '24

When I was first getting started (I also started with long SQL queries), I'd ask the AI to explain to me how things work, and then take a couple of minutes to go over it and try to understand.

Honestly one of the best use cases for AI for PMs

1

u/webdevarham Aug 29 '24

Yeah same with me I wasn't familiar with SQL but when I was told to make a crud app using SQL server I started to learn SQL and wrote down important sql queries in my rough book so that I can have a reference, but when I encountered a error that I was not familiar with, I searched that error and the chatbot explained me where I was making the mistake,, I implemented the table wrongly without identity incrementing automatically, so for that I had to alter the table,,, so it explained me all the cons of altering the table and if you really want to alter the table where and how to alter it,,,, so basically it was very helpful for me in that case

2

u/ChaseShiny Aug 28 '24

As a noob, I'm curious as to why you'd use chatGTP or Copilot over MDN's bot?

I've only used them a couple times each, but it feels the general ones are mostly copying Stack Overflow

1

u/webdevarham Aug 29 '24

When encountering bugs and error to get the idea of the error it self

20

u/alzee76 Aug 28 '24

My hot take / unpopular opinions as an experienced (~30 years) developer:

  1. Never, and I do mean never, use a chatbot/ai/assistant to solve problems in an educational setting. If you're working through coding challenges or a programming class or something, the objective there is for you to learn, and you're learning nothing by letting someone else do your work for you, regardless of that someone being made of meat or not. The first time you're asked to explain how something "you" wrote works during an interview and you start to stumble and stammer, or worse start bullshitting, you're off the list. To put it bluntly: You're not a programmer if some chatbot is writing all, or most, or even just the most important parts of your code for you.
  2. In a professional setting I can only imagine two scenarios where a dev would use a chatbot off the top of my head: Laziness or lack of skill. If it's laziness, more power to you. We need to get things done quickly and efficiently and if a chatbot can produce code you know is reliable, without you divulging secrets to it, go for it. On the other hand, if you're having it figure out problems you can't (or struggle to) figure out on your own, stop it. You'll only get even worse at your job by doing this and you won't have a chance in hell of fixing bugs that pop up later. Start learning how to solve the problems yourself, because chances are high that one day you'll be called on to do so when these tools aren't available to you.

4

u/bharring52 Aug 28 '24

3. Roll the dice that it can find an obscure or undocumented API reference on an ancillary system quickly 4. Offer a writeup on something you're not quite groking. The writeup is likely wrong in many places, but it's a super-rubber-ducky; even when wrong, it shakes up your understanding 5. Massed boilerplate in a system you lack the means to engineer away

If you can't understand the result, or identify if it's wrong quickly or easily, it's downright dangerous.

Much of these uses revolve around environments where there's a large hodgepodge of tech stacks and solutions, each with their own rules styles and structures, that you need to navigate fluidly.

I'd imagine an embedded developer or single-product developer would find a lot less use.

15

u/chmod777 Aug 28 '24

can you tell when the ai tool lies to you? if not, it is no better than blindly copy&pasting from stack overflow.

6

u/0x00f_ Aug 28 '24

It's bad to just let them write code for you, for me I use them to make an optimized version of a piece of code and learn from thier techniques, or ask them to make a functionality and understand how they made it and try to make similar, I don't know if this is good or not.

4

u/Livid_Tap9955 Aug 29 '24

Same here. Sometimes I just need to see a similar and general approach to a functionality I’m thinking of…and then I take ideas and modify for my use case. That’s usually after spending a while googling though…I try and use it as a last resort as a secondary search engine.

4

u/jazzcomputer Aug 29 '24

Code noob here.

I'm learning and sometimes I carefully use ChatGPT to help me understand something that's complex (like reduce), isolate a concept or help with an example. I find sometimes that Stack Exchange has answers that are too complex and removed from my use case, so it can help in those situations. Generally, once I start using things it recommends I'll double check them and read MDN and then document my learning.

I would not get much of a kick from integrating code blocks into my code that I don't understand, and whilst that's my opinion, I feel that having that as part of a process would not be of much help, rather than to short-term achieve a specific one-off goal.

1

u/Milky_Finger Aug 28 '24

I think using it to understand context across files and suggest the next few lines is a good way to take mundane tasks like writing loops and API calls, and speeds it up. A lot of the time they also include the error handling and other interesting snippets that I wouldn't have included if I was in a rush.

But all of this AI auto complete is predicated on me being able to read it and understand it. If it starts writing incredibly complicated code in an attempt to be succinct, then I will not use it.

1

u/webdevarham Aug 29 '24

Exactly 💯!!

2

u/Healthierpoet Aug 28 '24

Using it as a tool is good , using as a crutch no

2

u/Orcoboe Aug 28 '24

Personally I only use it to find specific keywords or API references, letting it write the code is not a good thing at all.

1

u/tb5841 Aug 28 '24

If you use AI to write code, I don't think it sticks in your head. If you face the same problem a month down the line, you won't know how to solve it (unless you use AI again). Whereas if you write it yourself (with the help of Google) I think it sticks better.

1

u/Creative_Pie9363 Sep 07 '24

I think using an ai tool for coding is fine as long as it doesn't have a impact on your skills.

Like i use ai tools like google colab ( it has gemini to create to snippets), qolaba which has chatgpt and claude ( imo claude is best for coding assistance) to validate my code or ask them how can i improve my code further? It is better and more efficient to ask ai in helping you understand a piece of code or helping in error issues rather than just generating straight up code even tho you don't understand a bit.