New to Clojure

364 views
Skip to first unread message

(hash-map :new "to clojure" :need "assistance")

unread,
Jan 9, 2017, 6:06:30 PM1/9/17
to Clojure
Hi all!

So, I'm new to Clojure! I'm coming in from a Java background and am currently working on a project that has prompted me to have a look at whether Clojure would be useful. 
I have started by going through the "Brave Clojure" website and working through the exercises and what I've seen has at many times just made me smile at the (at least so far) intuitiveness, simplicity and power of the language. My use case is this:

A real time (sealed bid) auctioning system. We have a maximum number of bids (example 100) that's set by the owner of the product. Our clients then bid on the product. Once a bid is made, it's committed to a database and the counter increments. The next bid is processed, and so on. Once the maximum number of bids is reached, bidding stops. This auctioning system is for a mobile application however the main code for the real time system sits on a web server. The mobile app is a very thin client so simply makes a call to the app server via an API which then processes that request (and returns the result). 

Requests are processed in order - so we're following a "first come first serve" approach. If at any time a request is due to be processed and the counter hits 100, all requests should gracefully "fail" and be blocked from bidding. Now this is obviously possible in Java, albeit with a lot more code and thinking about the different ways to make everything thread-safe, etc. This is a completely new project so there's no restriction on languages to be used, etc. PS: We're all Java developers.

I was really attracted to Clojure because of a) the JVM b) the fact that it seems to be able to handle concurrency effortlessly c) our API needs to scale and so we want to ensure that we can handle the 100K+ connections easily when the project reaches that stage. Obviously this is more to do with the hardware, but the way we build the API is a definite factor. Finally, there seems to be less verbose codebases on Clojure and it might help to keep our overall codebase light and readable! 

My questions therefore are these:

With the time we have (around 1 month for this stage), is this something we can easily build in Clojure?
Is the movement from Java to Clojure easy for someone completely new to Clojure?
Are the libraries that we might use for this - I had a look at Ring briefly robust for our use case?
Does Clojure have good support for using AWS for example? (You can call Java from Clojure so I guess this wouldn't really be an issue.)
Does it interface well with MySQL?

I'd be very grateful if someone could point me in the right direction on this - like I said, really really like what I'm seeing of Clojure but just want to be sure from the community before I recommend this as an action to take!

(hash-map :many "thanks")

Dennis Roberts

unread,
Jan 9, 2017, 7:05:48 PM1/9/17
to Clojure
From what you've described, it seems as though it would be easy to build the server side of this application in Clojure.

I found Clojure to be very easy to pick up. I won't say that the first few applications that I wrote in Clojure were great Clojure code, but it was easy for me to move from Java to Clojure.

Ring is a good start. You might also want to check into some libraries built on top of  Ring such as https://github.com/weavejester/compojure and https://github.com/metosin/compojure-api. We've found compojure-api to be extremely handy.

I haven't played with any AWS clients in Clojure, so I'm afraid I can't answer that question.

Clojure does integrate well with relational databases in general. We're using PostgreSQL, but any database that has a JDBC driver available should be easy to use. You may want to check into some of the Clojure libraries that provide DSLs for generating SQL statements. I've tried http://sqlkorma.com/ and https://github.com/jkk/honeysql, and I've had fairly good luck with both of them.

Dennis

Matching Socks

unread,
Jan 9, 2017, 7:28:44 PM1/9/17
to Clojure
You mention SQL.  Note, that using JDBC in Clojure is really, really easy.  It's a porcupine in Java, but in Clojure it's pure fudge.  Whatever your Java frame of reference for an ORM might be, Hibernate or Spring or whatever, bang! you probably won't need it.  Sure, there are JDBC wrappers for Clojure, to help with joins or portability or whatever, but when push comes to shove, if you need to do something "yourself", there is no mystery to it. 

For your one-month aspirations (ha!), Clojure is an interesting plan because you work in generic data structures and a lot of the alternative web-oriented libraries more-or-less agree about those structures.  So for example, you start out with Ring + Jetty, super simple, definitely good enough for Month No.1, but later you decide you need async and you want to switch to Aleph + Netty.  Amazingly little work will have to be thrown out and redone just on account of switching libraries.  You don't get dug in so deep with library- or framework-specific class names, as it were.  Clojure is a great insurance policy.

By the same token, with your own code, you spend so much less time dressing stuff up behind made-up APIs, and therefore those APIs are not a source of constant churn.  When you really want a hard subsystem boundary you can achieve it (same way you would in Java), but most of the time you avoid that song-and-dance and just call a duck a duck.  The Clojure way helps keep the prototyping stage of the project grounded in pragmatism.

Sean Corfield

unread,
Jan 9, 2017, 9:55:05 PM1/9/17
to Clojure Mailing List
> With the time we have (around 1 month for this stage), is this something we can easily build in Clojure?

Hard to say. I would expect a small team already familiar with Clojure could probably build this in a month but I don’t know how long it’ll take your team to ramp up. Java-to-Clojure is easy for some and extremely hard for others.

> Is the movement from Java to Clojure easy for someone completely new to Clojure?

See above. Familiarity with Java means the ecosystem and tooling (and stacktraces) won’t cause you any problems, but at the same time, if your developers are steeped in Java / OOP thinking, Clojure can be very confusing at first (How do I encapsulate my data? How do I write a loop? How do I handle state? Etc).

> Are the libraries that we might use for this - I had a look at Ring briefly robust for our use case?

Yes, people are building solid production systems with Clojure all the time. We’ve used Clojure in production for nearly seven years now and we’ve been extremely happy with the stability of everything we’ve used.

> Does Clojure have good support for using AWS for example? (You can call Java from Clojure so I guess this wouldn't really be an issue.)

It’ll depend on exactly what you plan to use from the vast AWS stable but, in general, yes since as you observe, you can always drop down to Java.

> Does it interface well with MySQL?

Yes, we run a large MySQL-based production system in Clojure – and all our JDBC access has been via Clojure for several years. Caveat: I maintain the clojure.java.jdbc Contrib library, so I may be a little biased here ☺

Sean



(hash-map :new "to clojure" :need "assistance")

unread,
Jan 12, 2017, 2:43:17 PM1/12/17
to Clojure
Hi Dennis,

Thanks very much for getting back to me - this sounds really good. I've had a look at sqlkorma seems simple enough to get started working with.

Once again, thanks very much most appreciated.

(hash-map :new "to clojure" :need "assistance")

unread,
Jan 12, 2017, 3:48:04 PM1/12/17
to Clojure
Hi Sean,

Thanks for your reply. This is really helpful - I really like the look of the jdbc library! Much appreciated.

Christopher Small

unread,
Jan 12, 2017, 9:58:42 PM1/12/17
to Clojure
I would _strongly_ recommend you consider HoneySQL over KormaSQL. Korma is based on macros, making it much more difficult to dynamically/programatically construct queries. HoneySQL by contrast is simply a translational layer from Clojure data structures to SQL queries, so the probablem of querying SQL databases is reduced to one of composing Clojure data structures. This is signifcantly more in line with the Clojure philosophy of being a "data-driven" programming language. Zach Tellman's talk Always be Composing (https://www.youtube.com/watch?v=3oQTSP4FngY) makes an excellent argument in this vein.

My 2c

Chris

simon lomax

unread,
Jan 14, 2017, 8:52:08 AM1/14/17
to Clojure
As far as SQL libraries for Clojure are concerned I would highly recommend HugSQL. Comprehensive documentation and a pleasure to use.

Good luck with your project.

regards,
Simon 

Gregg Reynolds

unread,
Jan 14, 2017, 5:00:06 PM1/14/17
to clo...@googlegroups.com


On Jan 9, 2017 5:06 PM, "(hash-map :new "to clojure" :need "assistance")" <nas...@gmail.com> wrote:
Hi all!

So, I'm new to Clojure! I'm coming in from a Java background and am currently working on a project that has prompted me to have a look at whether Clojure would be useful. 
I have started by going through the "Brave Clojure" website and working through the exercises and what I've seen has at many times just made me smile at the (at least so far) intuitiveness, simplicity and power of the language. My use case is this:

A real time (sealed bid) auctioning system. We have a maximum number of bids (example 100) that's set by the owner of the product. Our clients then bid on the product. Once a bid is made, it's committed to a database and the counter increments. The next bid is processed, and so on. Once the maximum number of bids is reached, bidding stops. This auctioning system is for a mobile application however the main code for the real time system sits on a web server. The mobile app is a very thin client so simply makes a call to the app server via an API which then processes that request (and returns the result). 

Requests are processed in order - so we're following a "first come first serve" approach. If at any time a request is due to be processed and the counter hits 100, all requests should gracefully "fail" and be blocked from bidding. Now this is obviously possible in Java, albeit with a lot more code and thinking about the different ways to make everything thread-safe, etc. This is a completely new project so there's no restriction on languages to be used, etc. PS: We're all Java developers.

you might want to take a look at the awesome https://github.com/ztellman/aleph

Gregg Reynolds

unread,
Jan 14, 2017, 5:08:53 PM1/14/17
to clo...@googlegroups.com
On Jan 9, 2017 5:06 PM, "(hash-map :new "to clojure" :need "assistance")" <nas...@gmail.com> wrote:
Hi all!

So, I'm new to Clojure! I'm coming in from a Java background and am currently working on a project that has prompted me to have a look at whether Clojure would be useful. 
I have started by going through the "Brave Clojure" website and working through the exercises and what I've seen has at many times just made me smile at the (at least so far) intuitiveness, simplicity and power of the language. My use case is this:

A real time (sealed bid) auctioning system. We have a maximum number of bids (example 100) that's set by the owner of the product. 

just curious, I don't know this market, but why set a limit on bids?

gregg

(hash-map :new "to clojure" :need "assistance")

unread,
Jan 16, 2017, 6:11:51 PM1/16/17
to Clojure
Hi Simon,

Many thanks for the advice - will have a look at HugSQL.

(hash-map :new "to clojure" :need "assistance")

unread,
Jan 16, 2017, 6:15:08 PM1/16/17
to Clojure
Hi Gregg,

I had a look at Aleph - looks fantastic! Plus it seems to have good docs as well. RE the bids, very special use case constraints set by the clients.

Many thanks

Gregg Reynolds

unread,
Jan 16, 2017, 6:25:42 PM1/16/17
to clo...@googlegroups.com


On Jan 16, 2017 5:15 PM, "(hash-map :new "to clojure" :need "assistance")" <nas...@gmail.com> wrote:
Hi Gregg,

I had a look at Aleph - looks fantastic! Plus it seems to have good docs as well. RE the bids, very special use case constraints set by the clients.

Many thanks

many welcomes!  you mentioned you have about a month.  if you do go with clojure, I'm sure many of us would be interested in hearing how it goes - please Doble us know, good or bad.

g

Gregg Reynolds

unread,
Jan 16, 2017, 6:26:54 PM1/16/17
to clo...@googlegroups.com
that would be "do let us". ;)
Reply all
Reply to author
Forward
0 new messages