设计大型功能程序的方法
我已经阅读了大量有关函数式语言的文章,并且可能想尝试用 F# 重写我的应用程序的某些部分。从外向内设计好还是从内向外设计好?
I've been reading lots on functional languages and would like to maybe play with re-writing some parts of my application in F#. Is it better to design from the outside in or the inside out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
关于 FP 主题的有影响力的著作之一为什么函数式编程很重要 可以被视为直接答案:
我还建议您查看 InfoQ 上 John Hughes 的当代访谈。
One of the influental works on the subject of FP Why Functional Programming Matters by John Hughes can be considered as a direct answer:
I would also recommend looking at contemporary interview with John Hughes in InfoQ.
真正帮助我了解函数式编程的一篇文章是:
http://prog21.dadgum.com/23.html
这是有关如何使用函数式编程技术创建吃豆人克隆的教程。我什至不认识他使用的语言(可能是 Erlang),但是这个解释帮助我理解了我在Scheme 中重写一个程序时所使用的正确思维方式。
One article that really helped me come to terms with functional programming is this one:
http://prog21.dadgum.com/23.html
It is a tutorial for how to create a Pac-Man clone using functional-programming techniques. I don't even recognize the language he used (it might have been Erlang,) but the explanation helped me understand the correct mindset which I used when rewriting one of my programs in Scheme.
我根本不是这个主题的专家,但这里有一个关于这个主题的文章的链接,作者是“我们”自己的 布莱恩:
函数式编程如何影响代码的结构?
以及 SO & 的一些问题程序员(顺便说一句,我怀疑这个问题更适合)
I'm not an expert at all on this subject, but here is a link to an article on this subject, by 'our' very own Brian:
How does functional programming affect the structure of your code?
And some questions from SO & Programmers (where - incidentally - I suspect this question would be a better fit)
不确定我是否理解“由内而外”/“由外而内”的含义,但 FP 在“小方面”(在功能级别)最有用。面向对象可能仍然是组织大型项目的最佳方式。处理与您的业务领域相关的对象是最简单的。
Not sure I understand what is meant by "inside out" / "outside in", but FP is most useful "in the small" -- at the function level. OO is probably still the best way to organize projects in the large. It's easiest to deal with objects that correlate with your business domain.
我猜你所说的从外到内是指从上到下的方法,而从内到外是指从下到上的方法。如果这就是你的意思,那么 FP 更适合自下而上的方法,即由内而外。
在设计 FP 程序时,请考虑使用以下方法解决问题:
哪种数据结构最适合表示该数据。
所以基本上你从底层开始,为每个原子问题编写一个函数,然后当你在设计中向上移动时,你使用这些原子函数通过组合来创建更高级别的函数。
请记住,始终考虑使用抽象和这些抽象的组合来解决问题,而不是像在命令式编程中那样按顺序思考。
I guess by outside in you mean top to bottom approach and by inside out you mean from bottom to top. If this is what you mean than FP is more suited towards bottom up approach i.e inside out.
While designing FP programs think about solving the problem using:
which data structure is most suitable to represent that data.
So basically you start from bottom, for each atomic problem you write a function and then as you move upward in the design you use these atomic function to create functions at higher level using composition.
Remember always think of solving problem using abstractions and composition of those abstraction rather than thinking sequentially as you would do in a imperative programming.