r/learnprogramming • u/BugSavings7355 • 20d ago
Terrified of using comments out of fear of being accused of AI
So in my year 11 programming class, we are using flask and python to create some simple front-end and back-end web development to learn about how databases and stuff work, its not all too complicated.
Ive been trying to bump up my mark and add additional features because I find it fun, but I have a problem.
Whenever I'm learning how to do something new in coding I like leaving myself reminder comments and in this case Ive been leaving them for myself to help stay focused on the codes functionality.
I showed my teacher my assignment today and he seemed to like it, however he then went to the front of the class and went on a big rant about how AI is plagiarism and he doesn't want anyone using it, which makes sense and I haven't used AI on the assignment. But the timing for seeing my code (with comments which is apparently a sign of ai) and then going straight to talking to the class about it makes me worried that the comments might get me incorrectly flagged for AI or something else.
I have bad anxiety so maybe that's why I'm overthinking this so much but I really don't want them to think Ive been abusing AI for my whole assignment.
341
u/mooglinux 20d ago
Writing good code comments is essential to being a programmer, and code comments are for precisely that. Use them.
88
u/AntiCitizen6 20d ago
I have noticed this debate over using comments. I have had instructors tell me that comments shouldn't be found in a production environment. I have also had instructors say that comments are critical for proper code organization and readability. I personally use them wherever I can, but I am still learning.
As long as you can explain your code and why you did what you did, you will be fine.
46
u/Chocolat_Melon 20d ago
If your teacher thinks that you’re using AI because of leaving comments, then he’s a shit teacher
31
u/Twintornado 20d ago •
As a former teacher, if he said it's good, IT IS GOOD.
BUT it's highly possible that your code got him thinking about AI and how it should be used. Your writing probably had nothing to do with it; he may have just been thinking about other situations.
For example, your code might have been a good example of how to use comments properly, which then got him thinking about AI-generated code and comments in general.
That's it.
202
u/EbbMother5325 20d ago
Code without comments is trash.
15
u/canadian_viking 20d ago
Rather than getting all in your head about this, why not just ask your teacher if your code had anything to do with his AI rant?
14
u/ooter37 20d ago
AI comments are obvious. They often don't make sense, answer questions no one would ask, etc. It's fine to use comments when necessary. They should be used to explain why something is the way it is rather than how it works though. The code itself should be readable enough to understand how it works.
10
u/Sophia-210 20d ago
Comments are a normal part of programming, especially when you're learning. I leave notes in my code all the time to remind myself why I did something or what I need to work on next. That doesn't mean it's AI-generated.
just keep your original code and commit history if you have it. If you're worried, you could casually explain to your teacher that the comments are personal reminders you wrote while learning. Don't stop documenting your code just because you're worried about being accused of using AI. It's a good habit to develop early.
5
u/OtherwiseOne4107 20d ago
You have imagined a connection that isn't real.
5
u/binarycow 20d ago
Comments aren't a sign of AI.
Extremely long verbose comments with overly flowery prose is a sign of AI. Especially when it references things that are in a plan file that has since been discarded.
5
u/AlSweigart Author: ATBS 20d ago
You should be terrified of using comments: that's a sign of AI-generation.
But you should also be terrified of not using comments: that's a sign of AI-generation.
"AI" has become the new witchcraft: a non-falsiable accusation to level at the people you don't like.
It's good practice to include comments in your code.
The mature adult thing to do in your situation is to directly ask your teacher if they consider comments to be a good thing or not or a sign of AI generation or not. Reiterate that you don't use AI, but you're not sure that will be enough to avoid accusations. Ask for clear direction for the teacher. If they're a good teacher, they'll give you them. If they're a bad teacher, then there's nothing you can do or not do that will avoid accusations anyway. Either way, having a direct, honest conversation about it is the scary but correct thing to do.
4
u/MedicalScientist8576 20d ago
I understand. I learnt it doesn't matter really. What matters is if you can explain your code and how it works. That's when a teacher learns the difference.
4
u/MyNameIsRichardCS54 20d ago •
Have a quiet word with him after class. There's no point in being in a state about it when it can be cleared up with a friendly chat.
4
u/Ok-Pianist9692 20d ago
Please don't let AI paranoia ruin one of the oldest good practices in programming.
Comments existed long before ChatGPT. They're not proof of AI usage; they're proof that someone wants to leave context for their future self or the next developer.
One thing you'll learn as you grow: good comments explain WHY something is done, not simply WHAT the code is doing.
Keep writing them. And if your teacher asks, just walk them through your code. Your understanding is stronger evidence than the presence or absence of comments.
4
u/righN 20d ago
I don't remember where exactly did I hear or read this, but you should write code in a way that it comments itself. Meaning function names, class name, the way you write functions should be understandable to the human reading the code. Only if you exhausted all your ideas how to make your code more readable should you use comments.
Obviously, I assume this gets better as you progress, but just keep this in mind.
3
u/ehr1c 20d ago
Comments aren't inherently a sign of AI-generated code, there's a particular type/style of comment though that usually indicates to me that a human probably hasn't gone through and read this. Generally it's comments that are explaining what rather than why, or a "why" that's very easily inferred from simply reading the code that's been commented. They're also usually written in that same snappy style that LLMs like to generate all their text in.
As for commenting in general, there's absolutely nothing wrong with tons of comments when you're learning. If you're shipping production code you likely want to use them more sparingly to describe things that aren't immediately obvious from reading the code - first of all it's easy for comments to become out-of-date by accident when the code is updated and the comments aren't, and second of all it's simply more text that a human has to parse when reading the code.
3
u/Wartz 20d ago
The cool thing about writing your own good code is that someone who knows how to code will know its good code, and LLM assisted or not will appreciate good code with good comments.
2
u/bbrren 20d ago
You need the comments / u/todo's etc... Just do your thing.
2
u/flashman1986 20d ago
If your teacher says comments are a sign of AI, you have my permission to slap him in the face with a wet fish
2
u/Karyo_Ten 20d ago
AI comments are really shitty, paraphrasing function name or body for internal one-liners. Don't worry about it.
2
u/fa1re 20d ago
Comments are absolutely important, especially with AI generated code. Everyone should be writing comments (correctly ofc)
2
u/YoungAspie 19d ago
Perhaps the timing was just a coincidence.
Good code (with clear names and organisation) explains itself well most of the time and should only use comments sparingly, for things that are difficult to explain through the code itself. Examples include:
There are also widely-recognised situations that call for comments, such as license declarations and API documentation.
As a beginner, TODO comments are fine. You will eventually learn about issue trackers.
3
u/[deleted] 20d ago •
Some teachers are dumb, have always been, will always be. In the 1990s I and a friend were accused of cheating, while we simply had used both the wrong reference table in a physics exam (yeah, it was dumb, I know). You can do little about it. Now some idiots think they have superpowers to detect AI, but have no idea what a false positive means. You can explain, but if he's dumb he's dumb, no way out of this.
2
u/KiwasiGames 20d ago
Write your comments in gen alpha slang. It’s not something AI typically does. And it will mark them as your work.
Don’t even have to go over the top with it, just put in enough of your own voice to be convincing.
1
u/Tjgoodwiniv 20d ago
It's absolute madness for an instructor to penalize you for comments, especially as a beginner. Even further along, comments are useful for maintaining code.
If I were you, I'd probably ask the instructor about it with genuine curiosity. If it was about you, you'll likely know. If it wasn't, he'll set you at ease.
Not a dev. Didn't study it. But I dabble. As someone else mentioned, I'd focus on being able to explain what you did (and why) and maintain good version control so you can better show proof of work.
1
u/pravmax 20d ago
Comments should be used in moderation, anything you can understand from the code relatively fast does not need a comment. You will learn programming better if you get used to reading the code first, the comment second.
Also, it depends on the AI model and how it's tuned but to my experience it tends to bloat the comments into multiple strings and they are often hard to understand too. So if your comments are concise and placed in appropriate places it won't look like AI made them
1
u/eyecandy99 20d ago
maybe have a talk with the teacher and discuss if he has anything against code comments. if he seems like he does, just to pass the class maybe cut down on comments. but good comments are a good practice, you can still use them in your projects.
1
u/Wonderful-Habit-139 20d ago
AI generated comments are obvious. Although I’m not a huge fan of comments, if you write them yourself it’s going to be fine.
1
u/LabraD0rk 20d ago
Use comments, always! If your professor wants to watch you code, offer to explain what you did in an oral exam or live session.
1
u/MisakiAnimated 20d ago
Learn how AI writes comments and then don't do that.
Code without comments is truly horrible to read, knowing what each block of code does is heavenly to read, so keep commenting, just make sure its not robotic.
1
u/roger_ducky 20d ago
Write comments for yourself then remove all but the ones explaining why you did something surprising and/or tricky.
1
u/Corne777 20d ago
AI has a certain type of comment.
Like in python if you were hitting a sql database at the end it might close a cursor and close the connection. AI would but a comment above those saying “close the cursor and connection”. This comment provides no context. It just says what is already obvious.
You want to put comments like “this shit here is weird and it doesn’t work unless you code it like this. I know it’s stupid but don’t touch it”.
Comments are for future developers to give them warning or context of “why” things are the way they are. Not necessarily what the code is doing. Because what it’s doing should mostly be apparent.
But I’d say getting into the habit of commenting isn’t a bad thing even if the comments aren’t the most useful at the moment in your school assignments.
1
u/Zecin 20d ago
The real proof that you didn’t use AI is if you can explain it clearly and talk about design choices/tradeoffs. If they really want to know if you used AI they can just grill you about it.
No idea what they do in uni nowadays though, but I’d imagine it depends on the prof
1
u/TheSneederOfSeethe 20d ago
People really outing themselves as terrible programmers like that?
1
u/Dolapevich 20d ago
You do the right thing for your learning and let everyone else do their thing.
You are working on your learning, you should feel you are making progress and that your capabilities are expanding.
1
u/josluivivgar 20d ago
add flavor to your comments, your own inside jokes, etc. comments are a must imo, and while AI does overutilize them it's a good practice for both you (and the AI that sometimes writes things wrong or in a weird way taht make it unreadable, the comments help the developer fix it)
I've been in companies that hated comments and it was frustrating (specially since they were a ruby on rails shop and ruby on rails makes things... harder if you're not super into the ecosystem because it has a lot of idiomatic ways of doing things that are not very readable)
1
u/Quantum-Bot 20d ago
Programming teacher here. The fear of being mistaken for AI is getting so bad that students are actively making their submissions worse just to be more identifiable as human. It’s happening in English, and in programming too and it’s pretty silly if you ask me. If your teacher knows the first thing about AI, (which as a programming teacher it would be embarrassing if they didn’t) they will understand that AI auto-flaggers are unreliable.
Add the comments, if anything they will help you prove the work is yours because comment are the place in your code where your style is most identifiable. Everyone uses comments slightly differently just like everyone has a different writing voice. Knowing how and when to write helpful comments is an essential skill as a programmer.
1
u/BoOmAn_13 20d ago
You should keep good comments. I would choose to use the pydoc format, and comments should either why you need this, or the expected results. Alot of people say that your code should explain itself, so we don't need the what, just the why. One example is when I do database lookups without checking data types or validation, I have a comment to explain "data was checked and validated on register, assume valid when reading". If you want some syntax sugar also check out type annotations to help understand the io of a function at a glance.
Don't feel bad about using comments, we all have had a stage of no comments, all comments, bad comments, and then mildly okay comments. None of them are ever perfect. Your comments are for you, if they want "production code" to not have comments, just copy the code and cut them out. It's lame, but if it makes it them happy, let both of y'all get a win.
1
u/StewedAngelSkins 20d ago
presence of comments isn't a sign of AI per se, it's more like the common AI tools tend to phrase their comments in a certain easily-recognizable way. can i see an example of your code with comments? ill probably be able to tell you straight away if it sounds like AI.
1
u/iMagZz 20d ago
Most programming classes praise comments if they are written clear and has a purpose. PIP8 also says to so that. If you want to write comments, definitely write comments.
1
u/da_Aresinger 20d ago
Start using git (just locally is enough)
Commit your changes often, so the evolution of your code and comments is clearly visible. Every prototype and every bug you fix needs to be a commit.
Keep commenting. It's better to comment excessively and learn to cut back, than the other way round.
If your teacher tries to fail you based on comments, confront them and show them your git history.
1
u/Mason-B 20d ago
Obviously human written comments are a better sign its not AI to me. The LLMs have a very particular commenting style. Its also dead easy for people to just delete the comments they leave.
1
u/dysprog 20d ago
Writing comments to leave reminder notes to yourself is good practice, and something I did long before AI was a thing. Don't let your teacher scare you away from good practice.
In all possibility, it was just a coincidence. He had an AI rant on tap, for unrelated reasons. If he had an issue with you project he would have (or should have) said it directly.
I certainly understand getting stuck in your anxiety about connections that objectively make little sense. If you otherwise have a good relationship with your teacher, bring it up after class or during office hours.
But on comments for there future: there are a few conventional prefixes that help make them findable. The main ones are TODO and FIXME. The spaceless spelling makes them easily ctrl-f-able and allcaps make then jump out visually.
Prefixing a comment with TODO, calls out a bit of technical debt or an opportunity for future improvement. These aren't urgent. (Sometimes they stay in the code for decades and become obsolete.)
Examples:
#TODO: We ought to refactor the database logic out of this#TODO: This can handle an arbitrary number of tags if we blah-blah-blah, butthat will be a messy data migration. limiting it to 64 for now, which ought to beenough for anyone#TODO: If this test fails after the year 2132, your code isn't broken,you just need to update the calendar data.#TODO: After TICKET-1234 lands, this should be rewitten to use the new TagsSetContainer.A FIXME on the other hand, is for code that is actually sort of broken and needs to be fixed before the code goes out. A FIXME in production code should be alarming. Some IDEs or git hooks block code with FIXMEs from being committed.
Examples:
#FIXME: hard coded this to get the tests running, but it should read from the file#FIXME: This is O(X^3) and will crash on production data sizes#FIXME: this works but it's fugly and embarrassing. rewrite it after I get some sleep1
u/Positive_Passion4817 20d ago
Using a revision control system with excessive commits should protect you against any plaigarism accusations.
1
u/OSKyle 20d ago
Comments aren't proof of AI. Homogeneous, generic comments ("initialize the variable", "loop through the list") are what look generated. Yours sound like study notes — that's normal.
Practical moves:
# need this check because empty cart crashed checkout yesterdaybeats# check if cart is empty.Using AI would be the issue. Leaving yourself breadcrumbs while you learn Flask is just how people get better.
1
u/snaidamast 20d ago
To ensure that your comments are not taken for AI work, simply place a "Written by:" at the bottom of each comment.
It does make sense that your instructor does not want you to use AI since too many people use it as a crutch, which destroys their critical thinking skills.
1
u/mdsnbelle 20d ago
I make sure my comments "sound like me." I'm commenting TF out of something I've finally started to get a handle on after multiple iterations, and yeah, I'm not walking away from it without detailed notes about why today me made certain decisions.
But it's lots of "this is doing X because Y" and "<my initials, today's date> you will be tempted to change this (particularly weird piece of) code. Do not follow this urge. This works! It breaks ABC if it's not done this way!!! TRUST PAST ME!"
Or I add a comment with the Jira # if I want to document what led me to do something new that I might want to remember later. And that's where I'll put the link to the stack overflow pages I used to get through the process.
1
u/adumbCoder 20d ago
my personal comment rules:
Write a comment only for the non-obvious why that someone reading just the file would need: keep it to one or two short lines in Simplified Technical English, with no MR history, no speculation and no restating what the code does.
1
u/cesclaveria 20d ago
That is just dumb, keep using comments, specially if you are learning they would be less comments and more like notes and reminders to yourself.
There are some different philosophies on when comments should be used and how, I tend to prefer comments that give an insight on the why a section of code does what it does, the decisions behind it, since the how it does it should be clear enough from the code itself. But while learning using comments to remind yourself how a piece of code works seems perfectly reasonable.
1
u/JbREACT 20d ago
Your teacher is lost
1
u/PeterPook 20d ago
There is a world of difference between AI generated comments and developer written comments. As a teacher, I wouldn't worry. We can tell the difference.
Document your code properly because that demonstrates your workflow and understanding as well as helping you as you develop your code.
1
u/Cool_Homework_7411 19d ago
You should use comments when your code does something that isn't apparent with a glance. AI puts comments on every step it can and it looks like it is narrating the code, while comments should serve a much different purpose. Comments are your notes on the code, just like how a composer puts expression marks on his music sheet.
1
u/Shassk 19d ago
Write comments in a way stipid enough to never be mistaken for an AI. I knew a guy who'd comment every line in the code (unless it's a single bracket on a new line).
1
u/betarage 19d ago
Normally ai has a very stereotypical corporate way of writing comments. so its unlikely that people will think its ai
1
u/FIREishott 19d ago
Allegedly the newer models are writing less comments. Its mainly just wasted context for them, after all, unless the comment is truly useful to point out something nonobvious
1
u/Jwhodis 19d ago edited 19d ago
AI comments things that don't need to be commented, as long as you aren't commenting every line you're fine.
If there's a simple function called "safely_convert_int(value) -> int" then it's safe to assume that it converts the input to an integer and accounts for errors, doesn't really need a comment.
But if you have a function called "tick(delta: float) -> None" then it would probably be helpful to outline what it does (and title each section IN the function) because of the very general name.
Even if a function has a good name, if that function does a lot then it's generally good to outline what it does and title each section.
1
u/Available_Safe1818 19d ago
You should stop spazzing out over this. Talk to an adult that you know.
1
u/TheFumingatzor 19d ago
I'm not. I don't give 2 wet shits if somebody accuses me of using AI. That sounds like a their problem, not mine.
This comment probably was written by an AI too, I don't know.
1
u/Ormek_II 19d ago
Ask your teacher.
1
u/mandzeete 19d ago
You can keep the comments in your local branches and commit stuff without comments. Clone your branch and clean comments out of it, if your teacher does not like comments.
If a "branch" does not tell you anything then learn about how to use git.
In general, have your code to be self-explanatory. No mystery variables like "var1" or "string2" or "g". Think if your grandmother would know what the "string2" stands for. If not then give it an understandable name. Keep your methods simple not have one big method that does everything. That you'd have to use comments to not lost a track.
Use comments only when your code does something unorthodox/weird. Then add a short comment.
Usually skilled people will know when the comment was written by an AI and when it was written by a person. AI tries to comment everything. Even stuff that needs no comments. It writes whole essays to a comment. It describes the problem, what it did, what it DID NOT do, etc. Many unnecessary things being written down.
But year, learn to use git branches and present code where there are no comments in it. While keeping the "version" of the code with comments only for yourself.
1
u/Cutwail 19d ago
I comment stuff, finished my comp sci degree in 2010.
1
u/Ery1WangChungNextFri 18d ago
Just write something to clean comments before you push to production. Good luck troubleshooting that, f’ers!
The problem is some people are horrible commenters, and others have no sense of humor and are masochists.
1
u/IHaveTwoOfYou 17d ago
Leave the comments, if it works for you then it works
1
u/unreasonable_citron 17d ago
I think it’s important to remember that what’s written in a comment by AI reads very differently than anything I’ve ever seen/written myself (a human)
1
u/goodolbeej 17d ago
Brother, just communicate this to the teacher. “I’m going to add extra features, and I figure I should comment to make it clear what they do. Just letting you know because I worry about being accused of AI”.
I teach hs CS. I can almost always tell when it’s AI and not. Not prove, but I know.
If a student did this I’d applaud it.
Communication is the greater part of professionalism. Start now.
1
u/ZestyHelp 13d ago
LLM comments don't look like human comments. You shouldn't worry about that, it's pretty obvious when it's an LLM comment
1
u/TrackbackLinkBot 12d ago
Comments are a normal part of programming. Developers use them to explain logic, leave reminders, and make code easier to maintain. They aren't proof of AI use. Keep your work and any drafts as evidence of your process if your teacher has questions. Boot.dev also emphasizes learning through writing and practicing real code, where understanding what each line does matters more than how polished it looks.
1
u/HugoNikanor 20d ago
People accuse anything and everything for being AI generated these days. The code currently generated by AI is known to be rather verbose in its use of comments, but that is no reason for you to avoid them. What's next? Writing invalid code since the AI tends to write valid code?
P.S. about the usage of AI: it has its uses, but stay clear of it for now, since your goal currently is to learn the fundamentals of programming.
0
u/escape_deez_nuts 20d ago
like literally terrified?