7 ms·
Web Application Development with Clojure
- andrewcooke 14y agowhy do you need a database for static text? at the very least why doesn't your site have basic caching so that multiple requests for one page don't take it down? i'm not just aiming at this post (the series of articles here look good). but web pages are not new tech these days. blog sites particularly. why do we still see so many go down once they have more than zero load? especially when the article is supposed to be teaching about web dev... cache: http://webcache.googleusercontent.com/search?q=cache:C6RrQdORJN8J:www.vijaykiran.com/2012/01/11/web-application-development-with-clojure-part-1/+&cd=3&hl=en&ct=clnk&gl=cl http://webcache.googleusercontent.com/search?q=cache:C6RrQdO... (first page only) [edit: there are lots of ways of caching to static files. wordpress has plugins that do it. more recently github has popularised jekyll. you can have comments through javascript and a 3rd party - i've set up a jekyll based blog with discuss comments on bitbucket and it was easy to do. it's not even hard to write your own (my own blog is nothing exciting, sure, but for years was generated as static pages from email using just a few bash scripts).]
- reagan83 14y agoI agree but how would you implement this? Aside from your caching remark, how would you design a dynamic content system like a blog? Should blog engines like Wordpress produce and maintain a series of static files to prevent db lookups for each page?
- maybesofast 14y agoyou can't have a content system (like a blog) without a database. (At least you can't have an easy to manage one)
- noblethrasher 14y agoHacker News doesn't use a database (assuming 'database' means some separate system like an RDBMS or KV store).
- ConstantineXVI 14y agoBut it doesn't have to be an online database. See Octopress[0]. [0] http://octopress.org/ http://octopress.org/
- chc 14y agoHe did say "easy to manage". I guess that's relative. Having the database always available has some conveniences (e.g. you can actually have comments on your pages instead of a JavaScript placeholder), and using a platform that's both really popular and quite mature has even more. A couple of comparisons should illustrate: How to write a post with WordPress: 1. Click the + button 2. Write 3. Check the tags you want 4. Click publish How to write a post with Octopress: 1. Type `rake new_post["whatever you want your title to be"]` 2. Navigate to source/posts/yyyy-mm-dd-whatever-you-want-your-title-to-be and open it 3. Type your post 4. Enter the categories in brackets at the appropriate place in the YAML front matter 5. Go back to the root of your site and type `rake generate` 6. Type `rsync -az public/ user@yourserver.com:yoursitedirectory`. This is based on the Octopress documentation -- I've only ever used naked Jekyll, but it sounds fairly similar, so I don't think I'm being too unfair here. I'm also giving Octopress a lot of leeway by e.g. including the press of "publish" as a separate step for Wordpress but not the equivalent step of saving when writing for Octopress. It only gets harder from there. Installing and tweaking a Wordpress theme or plugin is pretty easy. With Octopress, you actually have to sit down and code. I get that some hackers might be into all that, but surely you can see why somebody might find Wordpress more convenient.
- vijaykiran 14y agoYes, I use WP-Cache, but I was in the process of experimenting with my blog moving it around the servers - didn't know that internet cared :) Using WP is just convenience, nothing more than that.
- italophil 14y agoUnfortunately not working: Error establishing a database connection.
- mvts 14y agoMaybe that's just what it's like developing Web Applications with Clojure... ;-)
- vijaykiran 14y agoThere's a better performing Clojure Application (on EC2 micro) I'm working on - not this blog though :)
- vijaykiran 14y agoAuthor here - Didn't see that someone posted this to HN - and my I was wondering why my puny VPS kept on dying - rescaling it now :)
- vijaykiran 14y agoIt is up now.
- lkrubner 14y agoThank you again for writing this series. I studied it last year as I got into Clojure programming. These are fantastic posts and I learned a great deal.
- akurilin 14y agoGlad more folks are posting up-to-date tutorials for these core basics! The more, the merrier. Any thoughts on using vim for slime/swank-like development? I hear Nailgun can be quite rough to get working.
- franzus 14y agoGreat. I perceive webdev as pretty boring. I hope using an exotic language like clojure will make it a little more interesting for me.
- pestaa 14y agoI just got started in functional programming. How is web development different with Clojure than, let's say, Haskell? What are the trade-offs between the two?
- eggsby 14y agoI'd compare the two most popular web development platforms for those languages and try building similar apps in each. For haskell, that's http://www.yesodweb.com/ http://www.yesodweb.com/ and for clojure it's http://www.webnoir.org/ http://www.webnoir.org/ What trade-offs you encounter are going to be unique given what problem you are trying to solve with your web app, but the best way to see which suits you is just to take some time and try them out!
- eggsby 14y agoThis series is nice in that it shows working with databases (and schema migrations!), using the ring http abstraction, and hooking the two together. That said, I think that clojure is one of the worst platforms you could choose for building a blog (at least if you did it the way described in this article rather than the approach taken by things like jekyll). I understand the choice to build a blog was arbitrary, but as a clojure dev looking at this it just looks an immensely painful process for something that should be one of the simplest things to do on the web. I've found clojure to be a fantastic language for managing data transformations (we're using it for continuous delivery stuff at work and it's been remarkable). For static content like a blog it just seems remarkably burdensome. There is probably a reason most clojure developers don't use blogs written in clojure.
- vijaykiran 14y agoThanks for the comment, the goal is really to share how I was able to use Migrations/Templates etc. that you need to build any kind of web-app. Choosing to build a blog was to just avoid writing more about the type of the app I'm building & to skip explaining the requirements :)