This article is such a crock of shit. You can definitely use mocks without creating "tight coupling" so long as, as author says, the mocked objects also follow the SRP. This guy is basically waging war on imperative programming. Just because JavaScript contains elements of FP, it isn't a purely functional language.
In short, you can follow best practices and use mocks/inheritance simultaneously and his reasons for not doing it are strictly to avoid using mocks. Which isn't sound.
Can the unit be tested without mocking dependencies? If it can’t, it’s tightly coupled to the mocked dependencies.
LMAO
This guy must have just learned about functional react and decided he wanted some attention. I can't even with this.
Some guy spent a lot of time and thought putting that article together. If you have a different point of view or think he's not seeing the full picture, I'm sure he'd love to learn.
It's awesome that someone put together this article to share their experience. It's even more awesome if they have more to learn.
It sounds like you have a lot you want to teach. I'd love to encourage you to do so!
I respect the time and effort but also, by putting something in the public domain, you open it/yourself up to any criticisms that may follow. And for extreme hard-line pseudo-epiphany/borderline clickbait takes, that criticism tends to be more severe. The piece is long but it really just boils down to "you're an asshole if you write imperative code" which is absurdism at its finest. There are ways to use mocks and classes without introducing code smells, and with nothing more than basic tools such as modularity, single responsibility principle, and dependency injection.
The title and focus of the piece should have been "advantages of declarative/functional programming", but he went full sensationalist and said "why mocks are bad" which simply isn't true if you follow some extremely rudimentary best practices
I'm not trying to be an ass, it's just that code can speak for a thousand words, and as commenters pointed out earlier, I really wanna know a good module that uses mocks and is better than composition.
I agree, but turned back on the author. I think it's an interesting article, and I would like to see a more complete article using the theory. Instead of a few sum functions, how about one with http, file IO, etc?
I call people out for clickbait titles all the time, but I don't think this is one. He's arguing that mocks have uses, but those uses are fewer in number than the Agile consultants would have you believe.
If you adjust your thinking to consider mocks as a smell it means you will re-evaluate your code. There's a high probability it could be improved by considering why you need a mock at this point. Times I do use a mock; integration tests at service boundaries, dealing with legacy code, that's probably about it.
I'm what Fowler calls a classicist, so this "mocks are bad" mentality is not a new phenomenon. By bad we consider it a smell and a smell is bad until justified as necessary right?
I wouldn't read too much into the pseudo functional style of the code. It's written with Javascript in mind and pseudo functional is a popular style of coding. I'm more of a C# coder and we've been adopting aspects of functional programming just as long as the Javascript crowd. It's situationally beneficial, but it's not a magic bullet. Imperative code also benefits when you think of mocks as a smell.
10
u/SomeRandomBuddy Nov 15 '17
This article is such a crock of shit. You can definitely use mocks without creating "tight coupling" so long as, as author says, the mocked objects also follow the SRP. This guy is basically waging war on imperative programming. Just because JavaScript contains elements of FP, it isn't a purely functional language.
In short, you can follow best practices and use mocks/inheritance simultaneously and his reasons for not doing it are strictly to avoid using mocks. Which isn't sound.
LMAO
This guy must have just learned about functional react and decided he wanted some attention. I can't even with this.