by cjfd · 3y ago · 0 comments
Probably the worst thing about this one is the pydoc. An not just pydoc. Pydoc, javadoc, doxygen. It is all useless garbage that litters the code with useless comments explaining that the get_height method "gets the height" while at the same time nobody is actually explaining anything remotely useful in comments.
Sure, we can discuss whether all poiktsw make sense but it seems excessive to dismiss them entirely just because you dislike mandatory method docstrings.
So besides the useless comments I also have that experience described in the previous paragraph.
And to top it all off, another 'nice' experience with style guides was being forced to used the long discredited 'hungarian notation' which at the time was already long past its expiry date with not really anyone competent believing it to be a good thing.
Maybe my bad experiences are not typical but I have had so many bad experiences with style guides that I am now at the stage where I consider anyone enforcing a style guide to be my personal enemy and most likely a despicable person.
There probably are ways to encourage good comments but enforcing somebody write A comment, ANY comment in specific places at the point when theyre eager to merge is pretty much a recipe for shitty comments.
Also, the requirement to have documentation comments is just one rule out of hundreds, so why focus on that one?
Just as with comments I think you should assume the reader is a somewhat competent human beeing. Explain what needs to be explained, and make a *conscious* decision about it. For most public functions I agree that this usually involves a docstring, but not always.
Why focus on that one? Because it turns out that rule will force me to have 50% of the text that I see in a file be these useless comments.
def get_height(): # noqa
…
Is just as annoying as useless documentation.># BAD COMMENT: Now go through the b array and make sure whenever i occurs
># the next element is i+1
In practice style guides will usually advise against the kind of comment you're blaming them for.
Does get_height() include the optional border width or not? What does it return while the item is hidden? Does it return an int or float? Can it return a string value like "auto" or a null value? Under what circumstances should its value not be relied upon, e.g. while an animation is active? Why was it written as a function rather than a property? And so forth.
Requiring a comment is helpful in reminding the author to explain why this code was even separated out as a separate function in the first place, and all of the potential gotchas around it.
(also use numericalunits if you have so many dimensions that they're easily mixed up)
class Rectangle: ...
def get_height() -> Micrometer:
....
Now we clearly need to sufficiently document this method by saying "gets the height of the Rectangle in Micrometers".And yes, this is the garbage kind of answer that one gets whenever one brings up the point that I brought up. Honestly, I am already fondly hoping you will never be a colleague of mine.
This kind of 'documentation' has to be the worst and most disgusting kind of cargo culting ever invented in programming.
Personally, I’d agree with your example. But does this apply to all other situations? Often documentation comments can be very useful
Even for e.g. get_height, does it make a DB call? Is it expensive and shouldn't be called in a tight loop? Can it ever return 0?
I worked on a team like this who regularly wrote function names well into the 160-200 character range. It was useless.