News for hackers. Stuff that matters.
Re:Code doesn’t have to be a mess by idontwantthis on Monday July 25, 2022 @10:38AM (#32224938)
Unit Tests. If you can't write a unit test for it, it's too complicated and it's going to snowball quickly into a giant mess.
Re:Code doesn’t have to be a mess by marginalia_nu on Monday July 25, 2022 @10:43AM (#32225007)
Unit tests, while good at promoting decoupling, can absolutely be a major driver of complexity, as it may break the code into far more units than what is reasonable.
Re:Code doesn’t have to be a mess by dasil003 on Monday July 25, 2022 @11:08AM (#32225428)
Be careful with this. Unit tests don't tell you much about the correctness of a system overall, and they rarely survive a substantial refactoring. Optimizing for unit testability can make individual classes/functions "simple" but at the expense of creating a ton of them and pushing the complexity to the interfaces and integration between them.
Re:Code doesn’t have to be a mess by bbarn on Monday July 25, 2022 @10:43AM (#32225016)
I love unit tests, but admit I have absolutely seen unnecessary complexity including complete classes and namespaces solely to enable testability in many cases.

It's a justifiable trade off for me, but I don't pretend that unit testing reduces complexity.

Re:Code doesn’t have to be a mess by nosianu on Monday July 25, 2022 @10:51AM (#32225155)
I think it is of at least slight interest to some who missed it, to bring back this thread from 2018, about Oracle code (I too once worked on it so I immediately saved that comment link when it was posted):

https://news.ycombinator.com/item?id=18442941

Re:Code doesn’t have to be a mess by idontwantthis on Monday July 25, 2022 @01:45PM (#32228136)
I'm not sure if you're saying so, but those are not unit tests.
Re:Code doesn’t have to be a mess by nosianu on Monday July 25, 2022 @02:18PM (#32228625)
Yes it is about tests in general. I think it fits the discussion and many comments very well, this does not really seem to be about only unit tests specifically. Many comments are more general in tone.

The very comment at the top of this sub-thread does not seem to limit itself to the subject of unit tests.

Re:Code doesn’t have to be a mess by matheusmoreira on Monday July 25, 2022 @11:01AM (#32225311)
My experience with automated testing was great until I had to test I/O functionality: files, databases. That's when the test suite itself became too complicated.
Re:Code doesn’t have to be a mess by dsieger on Monday July 25, 2022 @02:43PM (#32229059)
Absolutely! For me, comprehensive testing is key to keep things clean over time. Not sure why this didn't come to my mind when writing the article. I think I was somehow assuming that this is a necessary pre-condition anyway.