To write a downloader, Clojure.java.io or Java's io api?

自古美人都是妖i 提交于 2019-12-11 19:26:36

问题


I am trying to write a general http/ftp file downloader in Clojure. I did a little research and found that I can either use java's api -- BufferedReader BufferedInputStream etc, or Clojure.java.io's api -- writer, reader, input-stream, output-stream.

  1. I found Clojure's api somewhat easier to use and read than java's api, but how about in terms of performance, speed, etc, will java's api be a better choice then?

  2. Is there any other reason to choose one instead of the other?

  3. As a jvm platform language, is Clojure a good choice for file downloader project, in terms of performance? While doing research, I also read some posts debating on speed & memory performance on jvm platform, and I guess now I wanna know if my language choice is a good match to my project..


回答1:


Clojure API should feels more natural as it is created with Clojure idioms in mind. Of course, you can still use the Java API but then expect a lot of Java interop functions calls.
Which of course there nothing wrong with that but it is only not a fluent Clojure API.

I don't see performance penalties, JVM is slow to boot no matter what you are using, whether it is Java, Scala, Clojure or JRuby. Clojure is really performant. By the way, do you know that in Clojure you can compile your project to Bytecode format?

Is Clojure as good choice for file downloader project?
I would say definitely!
One main advantage is how Clojure deal with concurrency. If you think about it, your project will do a lot of threading, locking and synchronization (you are building a downloader that can download many files simultaneously, correct)?
In Clojure you will use a higher abstractions such as agents (really convenient for your project), refs and atoms.

I'm not sure about the resources you read about JVM performance and memory management. JVM is a sophisticated piece of software. JVM offers many strategies to manage memory. Some are suitable for desktop applications, others are suitable for servers. You can pick the suitable strategy depending on your application/system requirements.

By the way, are planning to build your application with Swing? If yes and you decided to go with Clojure, then have a look at Seesaw.

Seesaw is a library/DSL for constructing user interfaces in Clojure. It happens to be built on Swing, but please don't hold that against it.



来源:https://stackoverflow.com/questions/18141029/to-write-a-downloader-clojure-java-io-or-javas-io-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!