admin管理员组文章数量:1291716
So we're using the very nice ramda library at work, which is great because we're able to use a largely point-free style of code. The problem with this is that there are far fewer places to look when things go wrong that point to something in our code; most run time errors occur because of a misuse of posed ramda functions. Combine this with passing these functions to a framework that uses a lot of redirection (we're on react/redux), and often when something goes wrong, it's deep in library-only code, and it's very hard to find out where I went wrong.
Is there any way to mitigate this problem without moving away from point-free style?
So we're using the very nice ramda library at work, which is great because we're able to use a largely point-free style of code. The problem with this is that there are far fewer places to look when things go wrong that point to something in our code; most run time errors occur because of a misuse of posed ramda functions. Combine this with passing these functions to a framework that uses a lot of redirection (we're on react/redux), and often when something goes wrong, it's deep in library-only code, and it's very hard to find out where I went wrong.
Is there any way to mitigate this problem without moving away from point-free style?
Share Improve this question asked Oct 27, 2016 at 16:38 jstaabjstaab 3,8652 gold badges28 silver badges43 bronze badges2 Answers
Reset to default 9One option is to use R.tap
, like so:
const f = R.pipe(
R.tap(console.log), // logs x
g,
R.tap(console.log), // logs g(x)
h,
R.tap(console.log), // logs h(g(x))
i,
R.tap(console.log), // logs i(h(g(x)))
j,
R.tap(console.log) // logs j(i(h(g(x))))
);
f(x);
Another option is to use Sanctuary, which raises informative exceptions when a function is applied to arguments of the wrong types.
I've run into the same problem with Ramda in my side projects. It's what made me give up on it in production, for now.
As of the time of writing this answer, debugging point-free style programs in JavaScript is very hard to impossible. That's the only reason I'm not using it. Even with good unit test coverage, I've found the development cycle is too long, and debugging to hard.
I'll expand on that: While tools like Ramda-debug and R.tap()
exist, they are active debugging tools, that you need to add to your project, and in some cases, add to your code and remove later in production. However, when you get an error message, you don't get a useful stack trace, and you can't step through in a debugger to figure out the flow, you need to know the flow in advance.
本文标签: javascriptPoint free debuggingStack Overflow
版权声明:本文标题:javascript - Point free debugging - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741536848a2384076.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论