When you ask a Dev to test their own code
We have to go deeper.
It should have the numbers change in the middle like a digital clock but look like the numbers on a clock.
Checked one of mine:
# get path to the download directory
Oh, ok.
The code directly below:
function getPathToUploadDirectory() { return config.tmp_path }
My comments are just the code that didn’t work but I don’t want to delete yet because I might make it work except I never will be cause I already rewrote it so it does.
My old senior used to do this before he got laid off and now I’m charge of code that’s littered with old commented out code and no way to know why it was commented out.
“Don’t delete this, might need it later - JP”
When versioning and feature flags are too hard: just use git and hope for the best
Are you me
Well I hate you all.
Sorry, I just get anxious that I’m suddenly gonna need that code
someone else’s code would have the wrong values.
Made a comment
Removed by mod
I know some folks are joking about and dunking on this, but in modern times, I have justification. Call me lazy, but I have found myself writing out these comments and then letting the AI take over to at least give me a sketch of an implementation. Works reasonably well and saves me a lot of time and effort. Mostly I don’t bother to remove them, though I usually edit them a bit.
On the other hand, there are factions within my colleagues who steadfastly insist that commenting is unnecessary and to some degree even potentially harmful, and that if you feel the need to comment your code, it means your code should be improved so that it’s obvious what it is doing without the need for comments.
At least docblocking a summary above every method is always good. You can automatically generate documentation this way.
And your colleagues are probably correct with respect to this sort of «what it does» commenting. That can be counterproductive because if the code changes and the comment isn’t updated accordingly, it can be ambiguous. Better have the code be the singular source of truth. However, «why it does it» comments are another story and usually accepted by most as helpful.
I’ll add that you should have a comment anytime you are using some sort of algorithm to explain what it is and the expected result when it’s not intuitive or a complex math operation that isn’t immediately clear. Ex// I’m using Newton’s Method to approximate a solution to speed up the inverse square root
if the code changes and the comment isn’t updated accordingly, it can be ambiguous.
People always site this as a reason comments are bad. In 30+ years as a developer I have seen (and participated in) a lot of failed software projects, but not once has a mismatch between comments and code been the actual cause of the failure. Moreover, the same logic could be applied to the names of methods and variables (“if the code changes and the method and variable names aren’t updated accordingly, it can be ambiguous”) but nobody ever suggests getting rid of that. At the end of the day, comments are useful for imparting information about the code to future developers (or yourself) that is too complicated to be adequately communicated by a method name.
I didn’t say the source of failure. I said a source of ambiguity. And having also been in the industry for decades, I have encountered it many times, where a junior programmer or somebody new to a project read some documentation and assumed a behavior which in fact did not match the current implementation. So you may have been fortunate, but your experience is certainly not ubiquitous.
With respect to variable names, I’d suggest those too should absolutely be updated too if the name is given in a way that adds ambiguity.
I’m not saying comments are bad; rather that bad comments are bad, and sometimes worse than no comment.
Would you mind sharing a bit more about the workflow you’re describing? I’m on a “ask people how they’re using AI to help them dev” kick.
Sounds like you’re using an agent integrated with your IDE, would you be willing to give specifics? And you’re talking about writing some comments that describe some code you haven’t yet written, letting the AI take a stab at writing the code based on your comments, and then working from there? Did I get that right?
Happy for literally any elaboration you feel like giving :)
I use VS Code and GitHub Co-pilot and develop in a variety of different languages and frameworks. I’ve got lots of experience with some, but I’m less knowledgeable on others.
So, having the AI assist with languages I am very familiar with is basically a way to save time and preserve my mental energy. For languages and frameworks I’m less experienced with, it speeds things up because I’m not having to constantly search how-tos and forums for guidance. And for languages/frameworks I have limited or no experience with, it can be a helpful learning tool that speeds up how long it takes to get ramped up.
With this set-up, if I start writing a line of code and then pause for a moment, co-pilot kicks in and tries to autocomplete that line, sometimes even suggests the entire block of code. It’s really good at recognizing simple patterns and common boilerplate stuff. It’s less good at figuring out more complex stuff, though.
However, I find that if I start out by writing a comment that explains what I’m trying to accomplish, and to some degree how to accomplish it before I start writing one of those more complex blocks/lines, the AI has a much higher success rate in returning helpful, functioning code. So, basically yes, I write the comment to describe code I haven’t written, and I’ll let the AI take over from there.
This works for code, raw database queries, configuration files, and even for writing tests. I’m not an expert at building out Docker configurations for local development or configuring auto-deployment on whatever random system is being used for a project, but I can often get those things up and running just by describing in comments what I need and what I’m trying to accomplish.
The VS Code co-pilot extension also has some context menu items that let you ask questions and/or ask for suggestions, which comes in handy for some things, but for me, typing out my intentions in comments and then letting the auto-complete kick in as I’m starting a line of code is faster, more efficient, and seems to work better.
Granted, co-pilot also likes to try to auto-complete comments, so that’s sometimes funny just to read what it “thinks” I’m trying to do. And most of the time, I do remove my comments that were specifically to guide co-pilot on what I wanted it to do if they’re super redundant. And, at the end of the day, not everything co-pilot suggests is production-worthy, functional, nor does what I actually described. In fact, a lot of it is not, so you should expect to go back and fine tune things at a minimum. It’s just that overall, it’s good enough that even with all the supervision and revisions I have to make, it’s still a net positive, for now.
I know I’m probably doing it wrong but this is how I feel whenever I write unit tests
Will each level of smaller clocks get one additional hour?
Self-explainable, when you aren’t writing spaghetti Perl scripts.
//forgive my sins, it took me 2 hours to nail down this arcane spell. if anyone touches this they will know my wrath
=(/&)((//((%=)(&)%)(&()Then it breaks years after you’ve left and someone has no choice but to touch it
Or breaks a year later and your have to figure out what the fuck you made. The worst thing in the world is when you leave it for the next guy, and you end up being the next guy.
Yeah…. I’ve definitely been the next guy on a couple bad regexes that I wrote
* Gets the user **/ fun getUser() { return this.user; }```
I’m sorry, I don’t think I understand what’s happening here…
Let me find the sequence diagram…
You need the requirements doc from marketing. Then it will all totally make sense for sure. No cap.
Okay now I get the joke.
I hate these kind of people.By the way, your ``` both need to be on their own, separate line
It renders correctly in my client (Sync), what are you using? I’ll edit it anyway.
It renders correctly on the web as well for me.
But the ``` being on their own line is how to write it properly, as stated this website among many others.
This way, you can put the intended programming language on the same line as the first ```, ensuring proper colour coding!
Ex.
echo "Hello $name\n";
echo "Hello $name\n";
Yep, I know, but my code isn’t in a real language.
You can also not do it, it was just an additional comment!
Thanks for your code review. :-D
the church of uncle bob would like to speak to you about the sins of commenting.
*furiously waves book around*
A true Klingon never uses comments.
Glory to you and your house!