r/learnprogramming • • 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.

108 Upvotes

125 comments sorted by

341

u/mooglinux 20d ago

Writing good code comments is essential to being a programmer, and code comments are for precisely that. Use them.

93

u/E3FxGaming 20d ago

I'd like to add that the only reason AI puts comments in code is that it has seen hundreds of thousands of files containing commented code during training. AI generalized that program source code consists of program instructions + comments.

There is no reason to stop commenting our code, just like the people did before modern AI was a thing.

13

u/ViralToValue 20d ago

Reminds me of how AI-generated writing has a lot of em-dashes, which were perfectly acceptable for people to use before. Not so much anymore

24

u/StewedAngelSkins 20d ago

the only reason AI puts comments in code is that it has seen hundreds of thousands of files containing commented code during training

im not convinced this is the only reason. claude often leaves comments that no human programmer would ever leave. for example, when refactoring it loves to leave lengthy descriptions of how the new code is different from the old code (which now no longer exists and so is completely irrelevant). stuff like this:

// value is now sourced from a read-through cache,
// not recomputed on each access. Seeding
// the cache is handled internally, not 
// at the end of this function.
let value = read_from_cache(index)

perhaps there were a few examples of this in its training set, but given that ive literally never seen it in human-written code it can't possibly be very common. my guess is it's a side-effect of some other training objective, probably related to reasoning, which incentivizes the model to effectively shove extra thinking tokens into the comments since they aren't constrained by the language grammar. ive actually seen similar behavior when you try to constrain a thinking model with something like a json schema; the model will often end up generating its reasoning inside string elements.

9

u/xarop_pa_toss 20d ago

Yeah I always find it bizarre that it will leave full paragraphs on a function call... Brother that's what the patch notes or change log are for, write that there!

4

u/StewedAngelSkins 20d ago edited 20d ago

it's weirdly difficult to get it to not do it too. normally style stuff like this will just get inferred from the existing code, or at worst i need an explicit note in the system prompt. that's what makes me think it's somehow more fundamentally tied to the training objective.

even beyond the style aspect i feel like these comments are a genuine detriment to model performance if you let them build up, because the thing will have a good portion of its available context taken up by comments describing obsolete code. even worse, these comments seem to steer the models away from solutions which superficially resemble the old solution. so like in my example above, if the best design involved reverting to explicitly seeding the cache the model would still avoid doing it because it's been "told" not to by the comment.

5

u/xarop_pa_toss 20d ago

That is absolutely by design. More context = more tokens = more money for them

1

u/You_CANnot_stop_me 19d ago

I've always thought it was just copying the notes I was leaving for myself in the code. It's pretty common at my work too, especially when you can tell a pair of programmers were essentially chatting with each other like that. I do end up finding still using them as "post-it note messages" so it could be training data...

That or its just generating text blindly, and doesn't care whether its within or without the codeblock.

6

u/skeptical-speculator 20d ago

'Comments' 'overexplaining' code might not be especially unusual in data pulled from places like stackoverflow or forums where someone is explaining the difference between two pieces of example code.

2

u/StewedAngelSkins 20d ago

That's possible, yeah

1

u/ConwayTech 18d ago

It's so strange. It could be a system prompt issue? Truly never seen this happen naturally

3

u/tknomanzr99 20d ago

Code comments are also entirely for humans, whether it be the engineer that wrote the code 6 months down the road, or someone entirely different. Meanwhile, ai can read and understand compiled bytecode. It's not the logic that ai struggles with, it's understanding how humans interact with machines in the first place.

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.

66

u/fiddle_n 20d ago

These two groups are just talking past each other.

Comments that explain how or what can often be useless. Comments that explain WHY are invaluable, especially if the why is not obvious to someone reading the code.

14

u/gyroda 20d ago

Yeah.

I've had people leave comments like "removed condition X" and I've had to tell them that the comment is useless. Not only is it a "what" instead of a "why", it's a comment to explain something that you've removed.

Now I can imagine a situation where this is useful (breaking a normal pattern/not doing something expected) but this wasn't it.

9

u/AFlyingGideon 20d ago

That kind of comment can be useful. Someone above mentioned comments describing "why"; this is describing "why not". It can save someone the trouble of following a previously failed path, or at least forewarns about difficulties on that path.

4

u/gyroda 20d ago

But, as I said, it wasn't a "why not" it was a "what not"

1

u/StewedAngelSkins 20d ago

AI does this shit fucking constantly. I think it must be a side-effect of the reasoning training or something because I don't think I've ever seen a human leave comments like this, unless it's genuinely confusing why some expected piece of logic is missing.

2

u/AlSweigart Author: ATBS 20d ago

And at the same time, I've had AI give me pages of code without a single comment. We're damned both ways.

2

u/istarian 20d ago

It may also be that that the comments didn't get updated when the code changed and are now a source of confusion.

But that's a process problem at some level.

1

u/NationalOperations 20d ago

That's true for any form of 'documentation'. The inverse is there's no comment on something complicated and is a source of confusion

1

u/ReddyKiloWit 19d ago

I'm surprised no manager ever asked me, as the repository admin, to add a trigger that compared changes to functions, etc. with changes to nearby comments, and post a flag that the comments should be double checked. But, no, they usually wanted to know how many lines changed and other generally useless things.

2

u/loophole64 20d ago

Comments that explain how or what are often extremely valuable for coworkers reading your code who might not have the same level of experience you do. They should be brief though.

66

u/lonelyroom-eklaghor 20d ago

comments shouldn't be found in a production environment

NO WONDER the legacy systems are having trouble shifting from COBOL

This is an advice only meant for the assembly compilers out there

19

u/micalm 20d ago

Or the instructor is a web developer who never figured out a proper build system that among other things like minifying would strips comments from the output markup.

1

u/HugoNikanor 20d ago

This is an advice only meant for the assembly compilers out there

What do you mean? That assembly generated by the compiler shouldn't have comments?

20

u/thatgirlzhao 20d ago

“Comments shouldn’t be found in a production environment” LOL OK. Really highlights the gap between academia and working professionals that’s existed for a while. Especially as someone who has survived mass layoffs at company’s, comments have been a lifesaver for transitioning ownership. Also, companies should have the option to set their own standards, yes there are general best practices, but the real answer is do whatever your company says you need to do.

2

u/Feeling_Photograph_5 19d ago

This. These teachers are idiots. 

4

u/StewedAngelSkins 20d ago

i think the most common advice these days is to use comments to explain why unintuitive decisions were made rather than to explain what something does.

I have had instructors tell me that comments shouldn't be found in a production environment

are you sure they didn't mean that commented out code shouldn't be left in production? even people who are really hardline "code should be self-documenting" types usually concede that public API functions should have a documentation comment...

2

u/nwillard 20d ago

Doesn't the Apollo 11 source code famously have a bunch of comments?

2

u/snaidamast 20d ago

Your instructor doesn't appear to be that knowledgeable as to how comments are handled by compilers and\or interpreters. They are either not compiled or they are ignored. An instructor saying that comments do not belong in production environment, obviously does not understand this.

Comments are a good way of commenting code that my be difficult to understand or to annotate as to why a block of code was written.

Good developers use a lot of comments in their work simply for the fact that if they need to come back to it in 6 months or so, they will remember why they did something.

2

u/loophole64 20d ago

"I have had instructors tell me that comments shouldn't be found in a production environment." Whoever told you that is a stone cold idiot. In general, don't trust career academics about how things are done in the business world. Not saying no teachers know how things work, but take that stuff with a big old rock of salt.

"I have also had instructors say that comments are critical for proper code organization and readability" This is also wrong, but not as egregious as the other guy. Comments are definitely not critical, or even helpful sometimes. Modern code languages have all kinds of organizational aspects built into them and tools that help you see that organization. Code can also be self documenting, with proper identifier naming and structure.

Comments should be used when they should be used. Use your brain to decide if they are helpful or just filler that is taking up space. Anyone who speaks in absolutes about this stuff probably doesn't have any practical experience.

2

u/ReddyKiloWit 19d ago

Having waded through a LOT of production code, I'm a big fan of comments. Too many is better than not enough.

That said, one developer's comment consisting only of a chess metaphor written in French was not at all enlightening.

1

u/gigastack 20d ago

Comments should be stripped out of minified front end code loaded on the client side. Comments are not really harmful for an interpreted language on the server side, with the possible exception of lambda or other serverless function where load time is critical. Comments will be stripped in compiled languages.

1

u/AikoG84 20d ago

They can pry my comments from my cold dead hands. I find it easier to read others code when it's commented, even just small comments.

I use it to keep myaelf organized and as "todo" tracking. The final comments are always more profeasional than my in progress comments. They also get cleaned up as I go in and clean up my general code as i'm working.

1

u/prof_hobart 20d ago

I've working in tech for about 40 years.

If your code is well written, you shouldn't need comments to explain what the code's doing (if anything it can be harmful - I've lost track of the amount of times people have struggled to spot a bug because they've believed the comment rather than reading the code).

What comments should be used for is when you need to explain why it's doing something.

1

u/VietOne 19d ago

Comments should have a reason why something was done a certain way. Because what's obvious to some isn't to others.

That's why it exists. You made a bug fix? Make sure to comment where the changes were made and why it was changed.

You decided to handle a process a little differently than a standard library, explain why.

You wrote a functional implementation with some gaps? Comment why. Because you probably did so due to something else making sure it doesn't come to your code. I might not like you didn't handle those cases, but at least I know WHY!!!

Comments aren't there to answer HOW you did it.

At some point in every developers career, you're going to look at someone else's code, and ask "Why did they do it this way?". At some point in every developers career, you will ask "Why did I do it this way?"

1

u/Round_Extension 17d ago

I have long been held to this in enterprise.

Comments are fine for local but always get removed before production UNLESS it in in the companies design and code quality docs e.g a strict template of doc strings assigned in an opinionated manner. Typically we make vscode extensions to make these templates extend to each class wherein the user would fill out the format. Although this is a common practice in university I could see it flagged as Ai.

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

-1

u/Seiak 20d ago

He's a shit teacher for his stance on AI too, setting his students up to fail. AI is an assistive tool and you'll be behind the curve if you don't use it. There's a reason why even places like CS50 have AI on their courses.

23

u/kat-tricks 20d ago

what do you need it in the classroom for? To learn how to ask someone else to do the work for you and then fix it? You get much more out of just learning to code yourself

-2

u/iamaiimpala 20d ago

You don't need it in the classroom but the teacher clearly isn't espousing a nuanced take on the subject.

6

u/StewedAngelSkins 20d ago

really depends on what he specifically said. "using ai [for your assignments] is plagiarism [because you're being asked to produce original work]" is i think perfectly justified, but it could just as easily be "using ai [in any context] is plagiarism [because i believe ai training is intrinsically an act of plagiarism]" which would be harder to defend.

4

u/EternalPhi 20d ago

It's not particularly hard to defend, it's just not all that relevant in a world where plagiarism isn't really a thing. People have been copy/pasting code for as long as there have been external repositories of code. It's just not a thing that carries any significance in this context.

1

u/StewedAngelSkins 20d ago

Is it common to consider computational analysis of a linguistic corpus to be a form of plagiarism? I feel like in an academic context failure to list the training data would be considered a reproducibility issue if anything, not plagiarism. And outside an academic context "plagiarism" isn't really a recognized concept, like you suggest.

1

u/kat-tricks 20d ago

maybe, all we know is the teacher made a point in a way that made OP feel insecure about their commenting style, which suggests that they're being careless. But we can't be sure, we don't have context and shouldnt condemn someone online over second hand info. Perhaps this is the motivation OP needed to change up their comment style!

31

u/Twintornado 20d ago • Bravo

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.

8

u/beatlemaniac007 20d ago

eh sometimes it's necessary but if you've worked in a large and evolving codebase you'll know that self commenting code is the ideal to aim for. Comments will start lying to you sooner or later.

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?

10

u/MrSpaceJuice 20d ago

Or ask him his stance on comments. These people are literally being paid to guide you. Ask them for guidance.

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.

6

u/ComeSwirlWithMe 20d ago

# I Used toast because I like toast.

toast = toasted

Not acceptable?

4

u/VietOne 20d ago

You've explained how every entry level SDE writes code. They all write overly commented code until they learn they don't need to.

1

u/ajwin 19d ago

Because they write what they want to do in prose and then convert it line by line into code?

-2

u/_heartbreakdancer_ 20d ago

This isn't true. AI comments are far better than human comments most of the time, just way too verbose or not kept up to date. But human comments were even more vague and more out of date usually. That was part of the argument against using comments all is that they naturally cause clutter and get messy.

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 • Bravo

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.

2

u/istarian 20d ago edited 20d ago

There is no such thing as "self-commenting code", only programs that are simple enough to easily understand.

Once you get past a certain amount of complexity, you need at least some comments to explain what the code is doing (or why it does that).

The trick is to avoid stating the obvious, but sometimes you are going to need a seond or third opinion on what is obvious/not obvious to someone else.

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:

  • Regular expression syntax is inherently complex.
  • Business logic.
  • Code uses a workaround because the obvious approach does not work.

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 • Bravo

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

seeing comments in code is a sign of AI

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.

  • Write simple and descriptive enough functions so they are obvious in their purpose.
  • Write comments for your ( or someone else ) future, what would you need to know in order to understand this in 1 year? Why are you doing this? The how should be obvious from the code.
  • If you need to prove anything, use OBS to record your screen, low res, low bitrate yet still readable, so you can show it if someone asks.
  • If working on a console, you can always use tmux/screen to keep a text record too.

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, but that will be a messy data migration. limiting it to 64 for now, which ought to be enough 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 sleep

1

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:

  • Keep the useful ones, make them yours. Prefer why over what: # need this check because empty cart crashed checkout yesterday beats # check if cart is empty.
  • Ask the teacher once, directly. "I comment while learning — is that a problem?" One clear answer kills the spiral. Bring a printed page if talking is hard.
  • Be ready to explain any line. If you can walk through the code without the comments, you're fine. That's the real anti-AI test most teachers use.
  • Don't strip every comment out of panic. Empty, mysterious code can look just as suspicious as over-commented code, and you'll hate debugging it later.

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

Terrified of using comments out of fear of being accused of AI

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?