Which AI is current...
 
Notifications
Clear all

Which AI is currently best for writing clean Python code?

6 Posts
7 Users
0 Reactions
127 Views
0
Topic starter

Ive been trying to clean up this massive script I wrote for my backyard greenhouse automation system—its basically just a giant pile of nested loops and global variables right now and its honestly embarrassing to look at. I need to get this refactored before I show it to my brother next Saturday because hes a real dev and will probably laugh at my spaghetti.

Ive been looking into my options and keep seeing people swear by Claude 3.5 Sonnet for logic, while others say GitHub Copilot is still the king because it lives right in VS Code. I tried Copilot for a bit but it kept suggesting really outdated ways to handle dictionaries and the variable naming was kind of nonsensical. On the other hand, Claude seems to get the architecture better but Im worried about the workflow of copying and pasting code back and forth all day.

Here is what I am looking for:

  • Budget: max $20 a month (dont want to break the bank on a hobby)
  • Use case: heavy refactoring and making things PEP8 compliant
  • Preference: something that actually understands context across 3-4 different files
  • Language: strictly Python 3.11+

Is there something better than just sticking with the big names? Maybe something like Cursor or a specific plugin that handles refactoring better? I just want the code to be readable and efficient without having to manually fix every third line the AI spits out...


6 Answers
10

Caught this thread today... are you using any specific hardware libraries like RPi.GPIO or is it just standard logic? If you want to stay under $20, Cursor AI Code Editor Pro Plan is basically the industry standard right now. It uses Anthropic Claude 3.5 Sonnet but actually understands your whole folder structure.

  • use the codebase indexing feature for context
  • refactor one module at a time Just be careful letting it delete those global variables too fast... might want to keep a backup before you start.


10

^ This. Also, be careful with massive refactors. I would suggest Sourcegraph Cody AI Coding Assistant because it indexes local files safely so it wont mess up logic. Make sure to double check those loops.


3

Like someone mentioned, many tools unfortunately fail with complex logic and PEP8 standards. Are you using type hints throughout, and what is the total line count for those files you need refactored?


3

^ This. Also, unfortunately everyone is just suggesting the same three shiny apps but they are not as good as they used to be, tbh. I have had issues with context drift in Cursor lately and it gets really frustrating when you are trying to clean up logic. If you actually want clean Python 3.11+ code without the AI hallucinating imports every five minutes, you should look at Aider AI Coding Assistant. Its a terminal tool that works with your existing editor. You can point it at your files and tell it to refactor for PEP8 and it actually checks its work against your git history. Pair it with Anthropic Claude 3.5 Sonnet API credits and you will probably spend way less than $20 a month if you are only working on it on weekends. For the formatting side, dont waste AI tokens on it. Just install Ruff Linter and Formatter. Its the industry standard now and fixes 99% of those messy bits instantly. Its kinda disappointing to see people paying for big subscriptions when a few CLI tools do it better. Just make sure you commit your code before letting any AI touch your nested loops...


2

@Reply #4 - good point! honestly i have seen so many people nuke their own projects by trusting a refactor tool too much. i remember back in the day trying to modernize some legacy automation scripts for a workshop project and the tool i used just completely ignored my global state... spent like twelve hours just trying to get my sensors to talk to each other again. it was a huge headache and i definitely learned that context is everything when you are dealing with hardware. before you pick a path tho, i gotta ask... are you looking for something that just cleans up the pep8 style and naming, or do you actually want the ai to suggest a more modular architecture? also, how deep are these nested loops... are we talking about 3-4 levels or is it something more intense that might need a complete rethink for efficiency?


1

honestly i have spent years wrestling with spaghetti code just like yours so i totally get the anxiety. in my experience the biggest mistake people make is letting the ai rewrite huge chunks of logic all at once without a safety net. the best ai for this right now is definitely an ide-integrated tool that can index your entire folder. you really need something that can see your whole project structure or youll end up with broken imports, ngl. ive tried many setups lately and the main thing to watch out for is when an ai gets lazy and skips code with a comment like keep existing logic here. thats a huge red flag where bugs creep in. just be careful with those global variables tho... even the smartest models lose track of scope once things get complex. stick to a setup that handles multi file context and youll be fine.


Share: