Ellen Spertus
10/02/2024, 11:31 PM/**
* Displays text.
* @param text the text
* @param size the font size
* @param isBold whether the font should be bold
* @param isItalic whether the font should be italic
* @param isUnderlined whether the text should be underlined
*/
fun displayText(
text: String, size: Int,
isBold: Boolean, isItalic: Boolean, isUnderlined: Boolean
)
Please give me feedback on the KDoc. (This is for an example of the benefits of default argument values.)Daniel Pitts
10/02/2024, 11:42 PMDaniel Pitts
10/02/2024, 11:43 PMif true, the x will do y
.Daniel Pitts
10/02/2024, 11:48 PMenum Weight { Normal, Bold }
enum Slant { Roman, Italicized }
enum Decoration { None, Underlined }
Zach Klippenstein (he/him) [MOD]
10/03/2024, 12:37 AMchristophsturm
10/03/2024, 9:52 AMZach Klippenstein (he/him) [MOD]
10/03/2024, 4:03 PMCLOVIS
10/08/2024, 10:36 PMGenerally, avoid usingand@param
tags. Instead, incorporate the description of parameters and return values directly into the documentation comment, and add links to parameters wherever they are mentioned.@return
https://kotlinlang.org/docs/coding-conventions.html#documentation-commentsIn particular, as other posters have mentioned, repeating the name of the field provides little value. Also, your documentation doesn't really answer the most interesting questions. In your example, it's not clear what the
size
argument's unit is. It could be in points, it could be in pixels. It could be in any other unit. This is what we expect documentation to expose.
But, we can go one step further using `value class`:
fun displayText(
…,
size: TextSize,
…,
)
and you can have multiple constructors to allow callers to use whichever unit they find more convenient:
displayText(
…,
size = 2.pt,
…,
)
Using this approach along enums (as already recommended), there is almost no need to document anything anymore, as only explicit code can compile.