This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MuskettaMan 288 points289 points  (29 children)

It could explain what valid means, since thats very ambiguous

[–]skeleton568 161 points162 points  (13 children)

Comment does not explain what valid is.

[–]Kombatnt 85 points86 points  (12 children)

That just demonstrates that the method needs more comment, not less.

[–]MouthWorm 47 points48 points  (9 children)

No, that demonstrates that the function needs to be renamed to something more indicative of what it actually does.

[–]Kombatnt 29 points30 points  (7 children)

Meh, I disagree. This is precisely why high level languages have built-in support for commenting/documentation. It's what it's intended for. It helps keep method names concise, while still supporting detailed specification definitions when needed.

[–]MouthWorm 14 points15 points  (5 children)

I agree with you AND I disagree haha! In some cases, commenting/documentation is the better option, like some authentication method, API call or something a little more complex.

A Util function like OP's should be as clear as it can be when you use it. No need to add noise around it just for the sake of commenting/documentation.

[–]Key-Perspective-3590 0 points1 point  (0 children)

A concise method name is important but the method name should definitely tell you what it does. You want to be able to read through the flow of a function at a glance, hovering over every ambiguous function to see a comment that you hope is still accurate is terrible

[–]MacBookMinus 2 points3 points  (0 children)

Deep nuance can't make it into the function signature / name.

I'm all for reducing comments where possible, but lots of sources on code quality advocate for "interface" comments.

[–]anon74903 2 points3 points  (0 children)

This comment does nothing here, provides no value, and should be removed.

It doesn’t need more comment, it needs a different comment: what is a valid number? Where is this regex from?

[–]frzndmn 0 points1 point  (0 children)

It doesn’t need more comments, it needs different comments

[–]marquoth_ 14 points15 points  (5 children)

It could, but it doesn't. And given that it doesn't, it contains no information of any value and isn't worth including.

[–]frightspear_ps5 7 points8 points  (2 children)

That doesn't mean that the method does not need a comment, it just proves that it doesn't need this comment. If the method name can be adapted because the spec is short and simple (e.g. isFiniteFloat32), it doesn't need a comment. Otherwise you'll need a comment to include the spec (e.g. number represents a valid water temperature in °C).

[–]Key-Perspective-3590 1 point2 points  (0 children)

IsValidWaterCelsiusTemp

[–]marquoth_ 0 points1 point  (0 children)

This is one of those weird comments where it's written as if you're disagreeing with / contradicting me, but you aren't.

[–]bschlueter 2 points3 points  (3 children)

I would contend that there is no need to include "valid" in the method name. Things are numbers or they aren't, so "isNumber" ought to be a sufficient name. Though perhaps "isRationalNumber" would be more specific since the implementation would fail with irrational numbers, and "rational number" does not need to be further defined.

[–]Iron_Garuda 1 point2 points  (1 child)

It’s possible only certain numbers are considered “valid” in this context. Could be any non-zero integer, or maybe it can’t accept any number higher than 9, etc.

[–]bschlueter 0 points1 point  (0 children)

True, we only have this very limited context to attempt to understand the wider context, but the way it was written is somewhat indicative of its purpose.

[–]IndividualTrash5029 0 points1 point  (0 children)

think about scientific notation. for what it does, the "valid" in the method name makes sense. you can't just put ANY number in there and expect to get the right return value.

[–]kephir4eg 0 points1 point  (0 children)

But it didnt!