The Clojure way

Simplicity, 简约

It’s hard to write simple solutions to complex problems. But every experienced programmer has also stumbled on areas where we’ve made things more complex than necessary, what you might call incidental complexity as opposed to complexity that’s essential to the task at hand (Moseley 2006).

Essential complexity is inherent in the problem domain, whereas accidental complexity is introduced by things external to the problem domain. For example, in a software project that deals with filing taxes, complexity that arises from convoluted tax-codes is part of the domain, and hence essential. Any complexity that arises from, say, employing the rather intricate visitor pattern, is accidental.
Fred将复杂性分为两种, Essential complexity, Accidental complexity
举个例子, 你开发报税项目, 复杂的税费的计算属于Essential complexity, 这部分复杂度是必须的; 而你使用负责的访问者模式设计带来的复杂度, 就属于Accidental complexity, 这种复杂度是不属于问题本身的

首先simple不是指clojure容易学或容易上手.
面对复杂问题, 需要首先把complexity分为Accidental和Essential两种, 对于Essential部分, 无法避免.
所以simple的语言, 意思是尽量减少解决复杂问题时的accidental complexity, 而clojure就是这样的语言.

典型的例子, oo方案, 类定义, 设计模式, 继承等都属于accidental的复杂度, 不属于问题本身的essential复杂度, 而clojure使用简单的function就把accidental的复杂度降到很低. 又比如并发问题,锁机制属于accidental的复杂度, 而clojure通过数据immutalbe和可变状态管理机制大大降低复杂度.

Freedom to focus

如果code可以被认为是艺术的话, 那么创作最怕的就是被打断, 复杂的语言总是要停下来思考语言的特性而阻碍真正解决问题的思路.
所以真正好用的语言, 是当你用来编写代码和算法的时候, 根本意识不到语言的存在, 而不是总是在考虑一堆由语言本身所带来的复杂度
所以focus其实还是由Simplicity所保证的...
Writing code is often a constant struggle against distraction, and every time a language requires you to think about syntax, operator precedence, or inheritance hierarchies, it exacerbates the problem.

Clojure tries to stay out of your way by keeping things as simple as possible, not requiring you to go through a compile-and-run cycle to explore an idea, not requiring type declarations, and so on. It also gives you tools to mold the language itself so that the vocabulary and grammar available to you fit as well as possible to your problem domain—Clojure is expressive.

而更重要的是Freedom, clojure除了象python是动态语言, 还通过macro提供语言扩展, 使使用者具有极大的自由度

One key to delivering this freedom is a commitment to dynamic systems. Almost everything defined in a Clojure program can be redefined, even while the program is running: functions, multimethods, types, type hierarchies, and even Java method implementations. Though redefining things on the fly might be scary on a production system, it opens a world of amazing possibilities in how you think about writing programs.

Empowerment, 实用为王

Some programming languages have been created primarily to demonstrate some nugget of academia or to explore certain theories of computation. Clojure is not one of these. Rich Hickey has said on numerous occasions that Clojure has value to the degree that it lets you build interesting and useful applications.

If a decision about some design point in Clojure had to weigh the trade-offs between the practical solution and a clever, fancy, or theoretically pure solution, usually the practical solution won out.

对Java libraries的封装, 如果加层对API的封装更pure和beatiful一些, 但是出于实用考虑, 选择的方案是直接调用

Clojure could try to shield you from Java by inserting a comprehensive API between the programmer and the libraries, but this could make the use of third-party Java libraries more clumsy. So Clojure went the other way: direct, wrapperfree, compiles-to-the-same-bytecode access to Java classes and methods.

对JVM的选择, 也是实用为王的体现

The decision to use the Java Virtual Machine (JVM) itself is a clear example of this practicality. The JVM has some technical weaknesses such as startup time, memory usage, and lack of tail-call optimization(TCO). But it’s also an amazingly practical platform—it’s mature, fast, and widely deployed.

总结,

Function 一类公民
代码和思维的简洁

Data immutable, persistent
数据操作的简洁, 尤其对于并发
将identity和state两个概念, 由传统的变量的概念中分离开, 利于思维的清晰

Macro
语言的扩展性, 人人都可以定制自己的DSL

Based on JVM and Java Libs
实用性, 可以迅速重用庞大的Java库来搭建系统

Code is Data, no syntax
语言的简洁性和一致性, 不需要太多的特殊语法

转载于:https://www.cnblogs.com/fxjwind/archive/2013/03/01/2938817.html

The Joy of Clojure – Clojure philosophy(1)相关推荐

  1. The Joy of Clojure 笔记

    The Joy of Clojure 跳转至: 导航. 搜索 目录 1 基础 2 Data types 3 FP 4 large-scale design 4.1 Macros 4.2 Combini ...

  2. Clojure 入门

    我将尝试教一些人(主要是Python开发者,在OS X操作系统运行)如何使用Clojure, 因为我觉得目前已经存在的一些教人如何从零开始学习Clojure的文档不尽如人意. 当我自己在几个月前亲身经 ...

  3. clojure source code

    https://github.com/clojure/clojure/blob/c6756a8bab137128c8119add29a25b0a88509900/src/clj/clojure/cor ...

  4. Clojure入门教程: Clojure – Functional Programming for the JVM中文版

    http://xumingming.sinaapp.com/302/clojure-functional-programming-for-the-jvm-clojure-tutorial/ api:h ...

  5. clojure java.jdbc_Clojure驱动的Web开发

    Clojure是运行在JVM之上的Lisp方言,提供了强大的函数式编程的支持.由于Java语言进化的缓慢,用Java编写大型应用程序时,代码往往十分臃肿,许多语言如Groovy.Scala等都把自身设 ...

  6. NoSQL, Clojure

    NoSQL ACID 在传统数据库系统中,事务具有ACID属性(Jim Gray在<事务处理:概念与技术>中对事务进行了详尽的讨论). (1)原子性(Atomicity):事务是一个原子操 ...

  7. Clojure Project 工程文件分析

    捣鼓了一天,今天就学习了一下project.clj的工程配置文件. 最终要的就是理解各个配置的内容,自己记录一下心得. 1 (defproject cljsbuild-example-simple & ...

  8. 为什么用clojure作为storm 的主要开发语言

    Why you choose Clojure as the development language of Storm? Could you talk about your long practica ...

  9. Clojure Web 开发 (一)

    使用Clojure做Web开发需要的工具链还是比较特殊的,本文主要描述一下其中牵涉到的框架. 需要指出的是,Clojure可以把自己封装成jar包供java调用,因此最坏情况下还是可以用java se ...

最新文章

  1. thirft支持双向通信
  2. 图像检索:再叙ANN Search
  3. 对寄存器ESP和EBP的一些理解
  4. easyui数据表格显示复选框_【Excel技巧】使用控件一键切换实现单位元和万元随意显示...
  5. C语言和C++的区别整理详解!
  6. kettle连接mysql教程_kettle 连接 mysql8
  7. 《深入理解 Spring Cloud 与微服务构建》第十六章 Spring Boot Security 详解
  8. odoo10参考系列--命令行接口:odoo-bin
  9. 2018年最令人惊讶的WordPress统计数据
  10. 《SPSS统计分析与行业应用实战》之P2P行业中的应用
  11. 51单片机系列封装库
  12. 已解决谷歌浏览器打不开axure原型
  13. resin设置权限_Resin学习笔记
  14. ZigBee 快速入门(协议栈,协调器,路由器,终端设备,加入网络,安全,路由功能,频段)
  15. 网络远程计算机终止,电脑拨号上网出现错误629:连接被远程计算机终止怎么办...
  16. SoftWare Configure
  17. debug命令(debug命令的使用)
  18. 项目经验之Kafka压力测试以及kafka机器数量计算
  19. 关于 tchar.h
  20. uva 1218 Perfect Service 树形dp

热门文章

  1. 如何和老师沟通好博士的申请呢?
  2. phd or domain
  3. contract net with fipa
  4. 当你所有的尝试告一段落
  5. OpenV P N + AD(Ldap) + GoogleAuth认证安装
  6. 阿里云日志服务(ELK)
  7. 外媒炒作中国黑客入侵美保险公司 并无相关证据
  8. UIBezierPath 绘制正五边形
  9. web页面版权部分的显示问题
  10. 用twisted为未来安排任务(Scheduling tasks for the future