10 ms·
I don't know if I'm doing something wrong, but every time I ask gemini 2.5 for code it outputs SO MANY comments. An exaggerated amount of comments. Sections com
by ranyume 1y ago
I don't know if I'm doing something wrong, but every time I ask gemini 2.5 for code it outputs SO MANY comments. An exaggerated amount of comments. Sections comments, step comments, block comments, inline comments, all the gang.
- GaggiX 1y agoYou can ask to not use comments or use less comments, you can put this in the system prompt too.
- ChadMoran 1y agoI've tried this, aggressively and it still does it for me. I gave up.
- ziml77 1y agoI tried this as well. I'm interfacing with Gemini 2.5 using Cursor and I have rules to to limit the comments. It still ends up over-commenting.
- shawabawa3 1y agoI have a feeling this may be a cursor issue, perhaps cursors system prompt asks for comments? Asking in the aistudio UI for code and ending the prompt with "no code comments" has always worked for me
- ChadMoran 1y agohttps://github.com/x1xhlol/system-prompts-and-models-of-ai-tools/blob/main/Cursor%20Prompts/cursor%20agent.txt https://github.com/x1xhlol/system-prompts-and-models-of-ai-t...
- koakuma-chan 1y agoHave you tried threats?
- throwup238 1y agoIt strips the comments from the code or else it gets the hose again.
- ChadMoran 1y agoI did not, but I'm curious if this would actually work.
- blensor 1y agoMaybe too many comments could be a good metric to check if someone just yolo accepted the result or if they actually checked if it's correct. I don't have problems with getting lot's of comments in the output, I am just deleting it while reading what it did
- tough 1y agoanother great tell of code reviewers yolo'ing it is that LLM's usually put the full filename path on the output, so if you see a file with the filename / path on the first line, thats prob a llm output
- cchance 1y agoAnd comments are bad? I mean you could tell it to not comment the code or to self-document with naming instead of inline comments, its a LLM it does what you tell it to
- deleted 1y ago[deleted]
- tucnak 1y agoAsk it to do less of it, problem solved, no? With tools like Cursor it's become really easy to fit the models to the shoe, or the shoe to the foot.
- Scene_Cast2 1y agoIt also does super defensive coding. Not that it's a bad thing in general, but I write a lot of prototype code.
- prpl 1y agoProduction quality code is defensive. Probably trained on a lot of google code.
- montebicyclelo 1y agoDoes the code consist of many large try except blocks that catch "Exception", which Gemini seems to like doing, (I thought it was a bad practice to catch the generic Exception in Python)
- hnuser123456 1y agoCatching the generic exception is a nice middleground between not catching exceptions at all (and letting your script crash), and catching every conceivable exception individually and deciding exactly how to handle each one. Depends on how reliable you need your code to be.
- montebicyclelo 1y agoHmm, for my use case just allowing the lines to fail would have been better, (which I told the model)
- Tainnor 1y agoDepends on what you mean by "defensive". Anticipating error and non-happy-path cases and handling them is definitely good. Also fault tolerance, i.e. allowing parts of the application to fail without bringing down everything. But I've heard "defensive code" used for the kind of code where almost every method validates its input parameters, wraps everything in a try-catch, returns nonsensical default values in failure scenarios, etc. This is a complete waste because the caller won't know what to do with the failed validations or thrown errors, and it's just unnecessary bloat that obfuscates the business logic. Validation, error handling and so on should be done in specific parts of the codebase (bonus points if you can encode the successful validation or the presence/absence of errors in the type system).
- Benjammer 1y agoI've found that heavily commented code can be better for the LLM to read later, so it pulls in explanatory comments into context at the same time as reading code, similar to pulling in @docs, so maybe it's doing that on purpose?
- koakuma-chan 1y agoNo, it's just bad. I've been writing a lot of Python code past two days with Gemini 2.5 Pro Preview, and all of its code was like: ```python def whatever(): --- SECTION ONE OF THE CODE --- ... --- SECTION TWO OF THE CODE --- try: [some "dangerous" code] except Exception as e: logging.error(f"Failed to save files to {output_path}: {e}") # Decide whether to raise the error or just warn # raise IOError(f"Failed to save files to {output_path}: {e}") ``` (it adds commented out code like that all the time, "just in case") It's terrible. I'm back to Claude Code.
- brandall10 1y agoIt's certainly annoying, but you can try following up with "can you please remove superfluous comments? In particular, if a comment doesn't add anything to the understanding of the code, it doesn't deserve to be there".
- diggan 1y agoI'm having the same issue, and no matter what I prompt (even stuff like "Don't add any comments at all to anything, at any time") it still tries to add these typical junior-dev comments where it's just re-iterating what the code on the next line does.
- tough 1y agoyou can have a script that drops them all
- shawabawa3 1y agoYou don't need a follow up Just end your prompt with "no code comments"
- guestbest 1y agoWhat kind of problems are you putting in where that is the solution? Just curious.
- dyauspitr 1y agoJust ask it for fewer comments, it’s not rocket science.
- Maxatar 1y agoTell it not to write so many comments then. You have a great deal of flexibility in dictating the coding style and can even include that style in your system prompt or upload a coding style document and have Gemini use it.
- Trasmatta 1y agoEvery time I ask an LLM to not write comments, it still litters it with comments. Is Gemini better about that?
- dheera 1y agoI usually ask ChatGPT to "comment the shit out of this" for everything it writes. I find it vastly helps future LLM conversations pick up all of the context and why various pieces of code are there. If it is ingesting data, there should also be a sample of the data in a comment.
- sitkack 1y agoLLMs are extremely poor at following negative instructions, tell them what to do, not what not to do.
- diggan 1y agoOk, so saying "Implement feature X" leads to a ton of comments. How do you rewrite that comment to not include "don't write comments" while making the output not containing comments? "Write only source code, no plain text with special characters in the beginning of the line" or what are you suggesting here in practical terms?
- FireBeyond 1y ago"Implement feature X, and as you do, insert only minimal and absolutely necessary comments that explain why something is being done, not what is being done."
- taf2 1y agoI really liked the Gemini 2.5 pro model when it was first released - the upload code folder was very nice (but they removed it). The annoying things I find with the model is it does a really bad job of formatting the code it generates... I know I can use a code formatting tool and I do when i use gemini output but otherwise I find grok much easier to work with and yields better results.
- throwup238 1y ago> I really liked the Gemini 2.5 pro model when it was first released - the upload code folder was very nice (but they removed it). Removed from where? I use the attach code folder feature every day from the Gemini web app (with a script that clones a local repo that deletes .git and anything matching a gitignore pattern).
- taf2 1y agoMaybe I got stuck with a bad experiment that removed it but it has been gone for me for a few weeks so I just stopped using it
- throwup238 1y agoIt just got removed from the Add menu for me too. Now I have to click "Import Code" and then the "Upload Folder" button in the dialog. Maybe you got this roll out much earlier than I did?
- puika 1y agoI have the same issue plus unnecessary refactorings (that break functionality). it doesn't matter if I write a whole paragraph in the chat or the prompt explaining I don't want it to change anything else apart from what is required to fulfill my very specific request. It will just go rogue and massacre the entirety of the file.
- bugglebeetle 1y agoThis is generally controllable with prompting. I usually include something like, “be excessively cautious and conservative in refactoring, only implementing the desired changes” to avoid.
- fkyoureadthedoc 1y agoWhere/how do you use it? I've only tried this model through GitHub Copilot in VS Code and I haven't experienced much changing of random things.
- diggan 1y agoI've used it via Google's own AI studio and via my own library/program using the API and finally via Aider. All of them lead to the same outcome, large chunks of changes to a lot of unrelated things ("helpful" refactors that I didn't ask for) and tons of unnecessary comments everywhere (like those comments you ask junior devs to stop making). No amount of prompting seems to address either problems.
- dherikb 1y agoI have the exactly same issue using it with Aider.
- mgw 1y agoThis has also been my biggest gripe with Gemini 2.5 Pro. While it is fantastic at one-shotting major new features, when wanting to make smaller iterative changes, it always does big refactors at the same time. I haven't found a way to change that behavior through changes in my prompts. Claude 3.7 Sonnet is much more restrained and does smaller changes.
- energy123 1y agoIt probably increases scores in the RL training since it's a kind of locally specific reasoning that would reduce bugs. Which means if you try to force it to stop, the code quality will drop.
- bugglebeetle 1y agoIt’s annoying, but I’ve done extensive work with this model and leaving the comments in for the first few iterations produced better outcomes. I expect this is baked into the RL they’re doing, but because of the context size, it’s not really an issue. You can just ask it to strip out in the final pass.
- lukeschlather 1y agoI usually remove the comments by hand. It's actually pretty helpful, it ensures I've reviewed every piece of code carefully, especially since most of the comments are literally just restating the next line, and "does this comment add any information?" is a really helpful question to make sure I understand the code.
- tasuki 1y agoSame! It eases my code review. In the rare occasions I don't want to do that, I ask the LLM to provide the code without comments.
- mrinterweb 1y agoIf you don't want so many comments, have you tried asking the AI for fewer comments. Seems like something a little prompt engineering could solve.
- asadm 1y agoyou need to do a 2nd step as a post-process to erase the comments. Models use comments to think, asking to remove will affect code quality.
- merksittich 1y agoMy favourites are comments such as: from openai import DefaultHttpxClient # Import the httpx client
- benbristow 1y agoYou can ask it to remove the comments afterwards, and it'll do a decent job of it, but yeah, it's a pain.
- sureIy 1y agoMy custom default Claude prompt asks it to never explain code unless specifically asked to. Also to produce modern and compact code. It's a beauty to see. You ask for code and you get code, nothing else.
- Workaccount2 1y agoI have a strong sense that the comments are for the model more than the user. It's effectively more thinking in context.
- stavros 1y agoIt definitely dumped its CoT into a huge comment just now when I asked it to add some function calls.
- HenriNext 1y agoSame experience. Especially the "step" comments about the performed changes are super annoying. Here is my prompt-rule to prevent them: "5. You must never output any comments about the progress or type of changes of your refactoring or generation. Example: you must NOT add comments like: 'Added dependency' or 'Changed to new style' or worst of all 'Keeping existing implementation'."
- kurtis_reed 1y ago> all the gang What does that mean?
- dankwizard 1y agoThis comment has been removed and replaced with a quote: "Sometimes the big fish isn't only the fish"
- Semaphor 1y ago2.5 was the most impressive model I use, but I agree about the comments. And when refactoring some code it wrote before, it just adds more comments, it becomes like archaeological history (disclaimer: I don’t use it for work, but to see what it can do, so I try to intervene as little as possible, and get it to refactor what it thinks it should)
- Hikikomori 1y agoSo many comments, more verbose code and will refactor stuff on its own. Still better than chatgpt, but I just want a small amount of code that does what I asked for so I can read through it quickly.
- freddydumont 1y agoThat’s been my experience as well. It’s especially jarring when asking for a refactor as it will leave a bunch of WIP-style comments highlighting the difference with the previous approach.
- AuthConnectFail 1y agoyou can ask it to remove, it does p good job at it
- upcoming-sesame 1y agoI noticed the same. Even if I explicitly tell it not to add new comments, it just can't help it
- chr15m 1y agoMany of the comments don't even describe the code itself, but the change that was made to it. So instead of: x = 1 // set X to 1 You get: x = 1 // added this to set x to 1 And sometimes: // x = 1 // removed this These comments age really fast. They should be in a git commit not a comment. As somebody who prefers code to self-describe what it is doing I find this behaviour a bit frustrating and I can't seem to context-prompt it away.
- n_ary 1y agoMay be these comments are actually originating from training annotated data? If I were to add code annotations for training data, I would sort of expect such comments which makes not much value for me but for the model, gives more contextual understanding…
- muzani 1y agoIt's trained on the Google style I guess. Google code always feels excessively commented, to the point where I delete comments from Google samples so I can read the code.
- renewiltord 1y agoIt's effectively CoT for the model. Just run again after saying "Remove all comments".
- hispanus 1y agoI have had the same experience: overly commented code by default