3 ms·
No. Those are test cases that you put in your unit tests. You don't put data examples as comments in your code.
by kyberias 10y ago
No. Those are test cases that you put in your unit tests. You don't put data examples as comments in your code.
- RangerScience 10y agoNo. Why make myself or another developer find an entirely separate file in order to comprehend a line (or three) of code? Why leave in a line of code that is all but incomprehensible without an example or explanation? Why provide a paragraph of explanation when a single line of example data will be more informative? Why further decouple the "documentation" from the code itself? Yes, you want test cases, and that's where you also put all the weird edge case conditionals; but, it's not like you're going to copy the actual line(s) of code into the test case, so you'd either need to temporarily copy the code (or the data samples) to be adjacent, or open side-by-side editor panes, or what have... All of this is more complicated than an example. But what about sample data that doesn't fit on one line? Then either your sample data is too complex, or this method is unsuited to your situation. There are guidelines for maximally legible code. There are no rules. If you follow rules, someday, you will encounter a situation where the rules force you to produce sub-optimal work. "Simply" strive to write legible code, and you will succeed. Strive to follow rules, and you will succeed at following the rules; and maybe you'll succeed at writing legible code.
- TheCoelacanth 10y agoThat's why more languages should let you write tests in the same file as the code it tests like Rust does.