在功能性建筑的语言思维 [英] Architectural Thinking in Functional Languages

查看:83
本文介绍了在功能性建筑的语言思维的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的相关问题框overfloweth函数式编程的问题。在审查了最相关的,我还是好奇,听取意见如下:

My Related Questions box overfloweth with functional programming questions. Having reviewed the most relevant, I'm still curious to hear opinions on the following:

您如何看待关于函数式语言构建的应用程序?

我不是在谈论一个特定语言的语法。我感兴趣的是概念上的组织范式(如面向对象)。

I'm not talking about a language-specific grammar. I'm interested in conceptual organizational paradigms (e.g object orientation).

许多人一样,我第一次接触到封装和code重用来自于OO背景。正如我一直在研究不同的语言,函数式编程真正吸引我的眼球。我开始掌握不变性的好处,高阶函数,等等。但我还是失去了我如何构建一个功能应用无感回落的面向对象的概念。其实,很多我见过的功能的例子有更多的共同点与意大​​利面条code,但我敢肯定这是由于的例子,而不是功能性的任何方法固有缺陷的简易性。

Like many, my first exposure to encapsulation and code reuse came from the OO background. As I've been researching different languages, functional programming really caught my eye. I'm beginning to grasp the benefits of immutability, higher-order functions, et cetera. But I still lose my sense of how to structure a functional application without falling back on OO concepts. Actually, many of the functional examples I've seen have more in common with spaghetti code, although I'm sure that's due to the simplicity of the examples rather than any inherent flaw in the functional approach.

此问题是近亲的时候,我应该使用函数式编程,但是我已经满意自己的功能性做法,尽管在某些领域利弊,是要公正的东西可用。我只是有麻烦想象一个复杂的应用程序的大画面组织。

This question is kin to "when should I use functional programming," but I've already satisfied myself that the functional approach, despite pros and cons in certain domains, is usable for just about anything that you want. I just have trouble picturing the big-picture organization of a complex app.

推荐答案

在上世纪70年代末,芭芭拉里氏等人开发的,目前仍在广泛应用的今天,哪些大型的面向对象设计技术的一大堆申请不变函数式编程。它们是最容易使用具有明确的接口和实现一个语言,这意味着标准的ML(其中接口被称为签名和实现被称为结构或算符)或目标CAML(其中接口被称为模块类型适用和实现被称为模块)。如果preFER计划再由马修·弗莱特和马提亚Felleisen开发的单位的语言被内置到PLT的计划,是前pressing大型功能一个很好的办法。

In the late 1970s, Barbara Liskov and others developed a boatload of large-scale "object-oriented design" techniques which are still widely used today and which apply unchanged to functional programming. They are easiest to apply with a language that has explicit interfaces and implementations, which means Standard ML (where interfaces are called "signatures" and implementations are called "structures" or "functors") or Objective Caml (where interfaces are called "module types" and implementations are called "modules"). If you prefer Scheme then the "unit" language developed by Matthew Flatt and Matthias Felleisen is built into PLT Scheme and is a very good way of expressing large-scale functions.

在简短的:


  • 整理这些类型周围的抽象类型应用程序(在OO班,FP抽象类)和操作。

  • Organize your applications around abstract types (classes in OO, "abstract types" in FP) and the operations on those types.

使用封装机制(班OO,在FP模块)隐藏你的抽象类型的再presentations。

Use encapsulation mechanisms (classes in OO, modules in FP) to hide the representations of your abstract types.

构建应用程序,使每个实现依赖于其他实现间接通过其接口。这样,您就限制$ C $的量c,你要明白建立或修改任何一件你的应用程序。

Structure your application so that each implementation depends on other implementations indirectly, through their interfaces. This way you limit the amount of code you have to understand to build or modify any one piece of your application.

你去城里!

的主要区别是,当你在写程序的功能,你不使用继承重用实现。而是使用高阶函数,或者你使用哪种采取其他模块的参数模块

The main difference is that when you're writing functional programs, you don't use inheritance to reuse implementations. Instead you use higher-order functions, or you use modules which take other modules as parameters.

摘要:是在架构层面,有没有很大的差异,但使用函数式语言时,你可能需要寻找稍用力以找到您所需的封装机制

Summary: at the architectural level, there's not a lot of difference, but when using functional languages you may need to hunt a little harder to find the encapsulation mechanisms that you need.

这篇关于在功能性建筑的语言思维的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆