The joy of clojure-clojure philosophy (1)

Source: Internet
Author: User
Document directory
  • Simplicity, simplicity
  • Freedom to focus
  • Empowerment, which is useful as king
The clojure way

Simplicity, 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 complexityIs inherent in the problem domain, whereasAccidental complexityIs 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 divided complexity into two types: Essential complexity and accidental complexity.
For example, if you develop tax return projects, the complex tax calculation belongs to the essential complexity, which is necessary. The complexity brought about by the design of the visitor mode in charge is, it belongs to accidental complexity, and the complexity is not the problem.

Simple does not mean clojure is easy to learn or use.
In the face of complex problems, we need to first divide complexity into two types: accidental and essential. The essential part cannot be avoided.
Therefore, the simple language means to minimize the accidental complexity when solving complex problems, and clojure is such a language.

Typical examples: OO solutions, class definitions, design patterns, inheritance, and so on all belong to the complexity of accidental, not the essential complexity of the problem itself, clojure uses simple functions to reduce accidental complexity to a low level. for another example, the lock mechanism is the complexity of accidental, while clojure greatly reduces the complexity through immutalbe and variable state management mechanisms.

 

Freedom to focus

If code can be regarded as an art, the most feared part of creation is the interruption. Complex languages always have to stop thinking about the characteristics of the language and hinder the idea of actually solving the problem.
So the really easy-to-use language is that when you write code and algorithms, you cannot realize the existence of the language at all, rather than always considering the complexity of a bunch of languages.
So focus is actually guaranteed by simplicity...
Writing code is often a constant struggle againstDistraction, 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 need e 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.

More importantly, freedom, clojure not only features dynamic language like python, but also provides language extensions through macro, giving users great freedom.

One key to delivering this freedom is a commitmentDynamic Systems. AlmostEverythingDefined in a clojure program can beRedefined, 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, which is useful as king

Some programming versions ages have been created primarily to demonstrate some nugget of academia or to learn e 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 demo-about some design point in clojure had to weigh the trade-offs between the practical solution and a clever, fancy, or theoretically pure solution, usuallyPractical Solution won out.

For Java libraries encapsulation, if the layers encapsulate more pure and beatiful APIs, but for practical consideration, the selected solution is to directly call

Clojure cocould try to shield you from Java by inserting a comprehensive API between the programmer and the libraries, but this cocould 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.

The choice of JVM is also a practical embodiment.

The demo-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.

 

Conclusion,

Function citizens
Concise code and thinking

Data immutable, persistent
Data operations are concise, especially for concurrency
The concepts of identity and state are separated from those of traditional variables, which facilitates clarity of thinking.

Macro
The language scalability allows everyone to customize their own DSL

Based on JVM and Java libs
It is practical and can quickly reuse a large Java library to build a system.

Code is data, no syntax
Language conciseness and consistency, without too many special syntaxes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.