218
Debugging (lemmy.ml)
you are viewing a single comment's thread
view the rest of the comments
[-] leisesprecher@feddit.org 3 points 2 years ago

Tests first is only good in theory.

Unit tests typically test rather fine grained, but coming up with the structure of the grain is 80% of the work. Often enough you end up with code that's structured differently than initially thought, because it turns out that this one class needs to be wrapped, and this annotation doesn't play nice with the other one when used on the same class, etc etc.

[-] CanadaPlus@lemmy.sdf.org 1 points 2 years ago* (last edited 2 years ago)

Can't you just add the wrapper to the test as well, if it's easy to do in the actual code?

[-] leisesprecher@feddit.org 1 points 2 years ago

If you have to ask "can't you just" the answer is almost always no.

[-] CanadaPlus@lemmy.sdf.org 1 points 2 years ago

Well, yeah, but I was kind of hoping you'd explain why.

[-] leisesprecher@feddit.org 1 points 2 years ago

Because you don't know what you'll need that wrapper beforehand, that's my entire point.

Unless you're only doing trivial changes, the chances are very high that you won't be able to design the class structure. Or, you end up essentially writing the code to be able to write the tests, which kind of defeats the purpose.

[-] CanadaPlus@lemmy.sdf.org 1 points 2 years ago

That's kind of the whole philosophy, though. The tests are the main way you understand what you're doing, the working code is just an addition on top of that. Presumably, there's a way to do that without repeating yourself - although I'm not turning up much on a quick look.

this post was submitted on 20 Nov 2024
218 points (98.2% liked)

Programmer Humor

43434 readers
4 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 7 years ago
MODERATORS