search
HomeBackend DevelopmentPython TutorialClojure 适合个人用来做 Web 快速开发么?

Web 快速开发很多人用 Python 及其它动态语言,Clojure 作为 Lisp 的一种方言,也很灵活。那么它适合用来做 Web 快速开发么? 理由是什么?
相对比 Python,Clojure 又有什么优劣势?

回复内容:

应该说还是蛮适合的。Clojure虽然历史不长但是支持web开发的"框架"[0]已经有了:Ring以及基于Ring的Compojure。Ring支持middleware机制(可以理解为插件),很多核心的功能都是通过middleware来实现的,比如session、cookie,params解析[1]等等,middleware机制使得你可以很轻松的向ring上面组装你需要的功能,比如这里[2]有一些已有的第三方的middleware。

对了Ring类库本身大量借鉴了Ruby里面的Rack、Python里面的WSGI特性,因此在快速开发方面不用担心。

虽然Clojure本身是JVM上面的语言,但是比Java爽的是,用Ring开发的代码你不需要任何特殊配置就可以做到:不管你是改html代码还是Clojure代码都是可以马上刷新就可以看到效果 —— 而不用重启服务器。这应该对于web开发速度比较重要的一个特性吧。

跟Python相比的缺点?一时还真的想不起来,可能我用的也不算多吧。这里是我晚上花了两个小时用Clojure写出来的东西,你可以感受一下: 公积金贷款计算器

[0] Clojure里面其实更喜欢叫类库,而不是框架,因为框架听起来是个很重的东西
[1] https://github.com/ring-clojure/ring/tree/master/ring-core/src/ring/middleware
[2] github.com/ring-clojure 开发还是很快的。rebajie.net 是我用clojure写的。这个是我用clojure写的blog 。。 github.com/baoliang/clo > 相对比 Python,Clojure 又有什么优劣势?

举例说明。
我前同事,原来专业写python的。后来因为clojure,到了我们公司,一直写clojure。他自己做的好几个项目都是Clojure写的。

我写Clojure2年多了,很喜欢这么语言,中间写过几个月python。这次到了新公司,公司大部分代码都是python+php。我就写python了。他们要我把服务搞快+稳定。python还是有点累,不过应该可以解决。

python应该还是一门不错的语言。Clojure更是。 很好用,可以开放端口,用来热调试,同时可以实现插件动态管理,开发流程很简单,快速,
(defn render-test [ret tmt]
  (-> (resp/response "------render----test------") 
    (#(resp/content-type %1 "text/plain"))))

(defn foo
  "I don't do a whole lot."
  [x]
  (str "来自源码目录的参数:" x))

(defn handler [^Integer x]
    {:$r render-test :text (str "hello world, road goes sucess!" (foo x))})

(defn home [req content ^Integer num]
    {:hiccup "home.clj" :content (str "home" content) :num num})

(defroad road (GET "/web-test-0.1.0-SNAPSHOT-standalone/main" handler) 
              (GET "/web-test-0.1.0-SNAPSHOT-standalone/home/:num{\\d+}" home))

(defn -main [& args]
  (log/info "---------log4j test-------")
  (jetty/run-jetty road {:port 3000}))
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you slice a Python array?How do you slice a Python array?May 01, 2025 am 12:18 AM

The basic syntax for Python list slicing is list[start:stop:step]. 1.start is the first element index included, 2.stop is the first element index excluded, and 3.step determines the step size between elements. Slices are not only used to extract data, but also to modify and invert lists.

Under what circumstances might lists perform better than arrays?Under what circumstances might lists perform better than arrays?May 01, 2025 am 12:06 AM

Listsoutperformarraysin:1)dynamicsizingandfrequentinsertions/deletions,2)storingheterogeneousdata,and3)memoryefficiencyforsparsedata,butmayhaveslightperformancecostsincertainoperations.

How can you convert a Python array to a Python list?How can you convert a Python array to a Python list?May 01, 2025 am 12:05 AM

ToconvertaPythonarraytoalist,usethelist()constructororageneratorexpression.1)Importthearraymoduleandcreateanarray.2)Uselist(arr)or[xforxinarr]toconvertittoalist,consideringperformanceandmemoryefficiencyforlargedatasets.

What is the purpose of using arrays when lists exist in Python?What is the purpose of using arrays when lists exist in Python?May 01, 2025 am 12:04 AM

ChoosearraysoverlistsinPythonforbetterperformanceandmemoryefficiencyinspecificscenarios.1)Largenumericaldatasets:Arraysreducememoryusage.2)Performance-criticaloperations:Arraysofferspeedboostsfortaskslikeappendingorsearching.3)Typesafety:Arraysenforc

Explain how to iterate through the elements of a list and an array.Explain how to iterate through the elements of a list and an array.May 01, 2025 am 12:01 AM

In Python, you can use for loops, enumerate and list comprehensions to traverse lists; in Java, you can use traditional for loops and enhanced for loops to traverse arrays. 1. Python list traversal methods include: for loop, enumerate and list comprehension. 2. Java array traversal methods include: traditional for loop and enhanced for loop.

What is Python Switch Statement?What is Python Switch Statement?Apr 30, 2025 pm 02:08 PM

The article discusses Python's new "match" statement introduced in version 3.10, which serves as an equivalent to switch statements in other languages. It enhances code readability and offers performance benefits over traditional if-elif-el

What are Exception Groups in Python?What are Exception Groups in Python?Apr 30, 2025 pm 02:07 PM

Exception Groups in Python 3.11 allow handling multiple exceptions simultaneously, improving error management in concurrent scenarios and complex operations.

What are Function Annotations in Python?What are Function Annotations in Python?Apr 30, 2025 pm 02:06 PM

Function annotations in Python add metadata to functions for type checking, documentation, and IDE support. They enhance code readability, maintenance, and are crucial in API development, data science, and library creation.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment