Agreed! A useful comment would only be present to describe an edge case, a related business rule, a future change that might affect this code, virtually anything another engineer might need to be aware of, that is not the code they are looking at.
That was my intial reaction as well but then I thought, if the AI can't make sense of it then a human probably wouldn't either. So, I guess a tool like this can serve to check if code is actually readable. I think variables names play a big role in this (i.e. communicate intent).
It might be very interesting to write the "no value" comments automatically. It can help us focus on and emphasize the part that we think is missing from the autogenerated ones.
The problem I have with tools like this (same as github copilot) is that I need to go ahead and double check if the AI did the right thing. At that point I might as well right the comment.
The tools can reduce the time and mental energy spent writing boilerplate and provide consistent structure to code and comments. This allows me to operate at a higher level of abstraction instead of worrying about details. Often it’s faster and easier to edit incorrect autogenerated code than to write it from scratch, especially when you work with many languages with their own idioms. Reviewing code is part of the process whether I’m writing from scratch or using autosuggestions.
> often it’s faster and easier to edit incorrect autogenerated code than to write it from scratch, especially when you work with many languages with their own idioms.
Completely disagree. Once you get really fluent in a language it is so much faster to write something from scratch. Especially if you have certain patterns you follow.
Code review is different because that has a different goal.
I’m fluent in English and I find autocomplete helpful. More advanced tools like Writefull that can help paraphrase or structure larger blocks of text have a lot of potential. These next generation autocomplete tools already are and will be increasingly useful to experts.
>The tools can reduce the time and mental energy spent writing boilerplate
If you're writing enough boilerplate that you find it useful to have a little helper write boilerplate for you then you are writing way, way, way too much boilerplate.
If you have literally any boilerplate in comments then you probably have too much.
def get_temp(sorted_temps: list[float], el: float) -> int:
"""
Search through the sorted temperatures array to find the
index of the temperature that matches the element
:param sorted_temps: sorted list of temperatures
:param el: the target element
:return: the index of the matched element
Author: Richard Hendricks
"""
i = 0
while el != sorted_temps[i] and len(sorted_temps) > i):
i += 1
return i if i < len(sorted_temps) else -1;
Some problems I see:
1. the `return ...` line needs to be dedented, otherwise, if `el == sorted_temps[0]` then the return value is None
2. even if dedented, the docstring needs to report that get_temp() returns -1 if the index isn't found
3. there's an extra `)` in `> i):`, and the semi-colon is unneeded
4. the test for `len(sorted_temps) > i` must done before `el != sorted_temps[i]`,
The corrected version would be:
def get_temp(sorted_temps: list[float], el: float) -> int:
i = 0
while len(sorted_temps) > i and el != sorted_temps[i]:
i += 1
return i if i < len(sorted_temps) else -1
Furthermore, here are some alternatives:
5. I would expect the following to be faster, and more easily understood:
for i, temp in enumerate(sorted_temps):
if temp == el:
return i
return -1
5. Or since the type signature says it's supposed to be a list of floats:
13 comments
[ 3.0 ms ] story [ 35.2 ms ] threadThe comments generated are not just useless, they are harmful. They made it harder to recognize and act on actually meaningful comments.
Completely disagree. Once you get really fluent in a language it is so much faster to write something from scratch. Especially if you have certain patterns you follow.
Code review is different because that has a different goal.
If you're writing enough boilerplate that you find it useful to have a little helper write boilerplate for you then you are writing way, way, way too much boilerplate.
If you have literally any boilerplate in comments then you probably have too much.
Here's the code I see:
Some problems I see:1. the `return ...` line needs to be dedented, otherwise, if `el == sorted_temps[0]` then the return value is None
2. even if dedented, the docstring needs to report that get_temp() returns -1 if the index isn't found
3. there's an extra `)` in `> i):`, and the semi-colon is unneeded
4. the test for `len(sorted_temps) > i` must done before `el != sorted_temps[i]`,
The corrected version would be:
Furthermore, here are some alternatives:5. I would expect the following to be faster, and more easily understood:
5. Or since the type signature says it's supposed to be a list of floats: 6: Or, since the values are supposed to be a sorted list, perhaps a binary search: