Converting compojure noir to Liberator - clojure

I'm fairly new to clojure/compojure, but really love it. Naturally, started my exploration with Noir stack. Have written a POC app. Then, discovered Liberator -- makes a whole lot of sense. Just wondering, if anybody has ever migrated Noir applications to Liberator before. Any references to articles/blogs that cover this would be highly appreciated.

The goal for Noir and Liberator is slightly different.
In simple words, you would use Noir to create website or web applications, and Liberator to create APIs, by exposing your resources for RESTful access. So to answer your main question, you would not really migrate from Noir to Liberator.
Also nowadays, Noir has actually been deprecated for compojure+lib-noir
Just in case, the main frameworks to build web applications these days in Clojure would be:
Luminus
Pedestal,
(and to a lesser degree) ClojureScriptOne
(and as stated above) pure compojure + libnoir

I was learning most clojure/compojure from the the book http://pragprog.com/book/dswdcloj/web-development-with-clojure which is still in beta. Seems that it's out of date before it even published. The Pedestal seems to be very very interesting and exciting. Though, what do people think, I know it's hard to predict, but what is a possibility of Pedestal becoming a next defacto standard replacing compojure+libnoir? Just have very scarce resources, and trying to make correct choices early in the game. Making simple decision is difficult these days.

Related

Django API Rest Framework

this is - don't slap me in the face - a beginner question.
I have some knowledge in Python and Django, but it is not too overwhelming. I have a very appealing business idea in my head and I made it a challange to see if I can get the nessesary skills to make it come to life.
Long story short, somewhere along the road I want to be able to build an IOS and Android App (or bring someone in who can do it). I also need a homepage for this (Django is a good enough solution for this - this much I know).
As far as I unserstand it, I can use the rest API Framework to connect Apps with the Django Backend. Is this a good solution? Or would you recommend another way to realise this projekt?
Speed would be impartant for the final solution. Also I need good scalability, though, I don't plan to recreate Facbook.
Django REST Framework is brilliant, and the documentation is really helpful (http://www.django-rest-framework.org/), takes a little while to get used to but with django experience its very simple. There is also a short video tutorial(4 videos) by a guy called thenewboston https://www.youtube.com/watch?v=Yw7gETuRKjw which will help get you started.
Hope this helps, good luck with the business adventure

noir vs compojure?

I'm having trouble understanding the point of clojure's Noir library. It seems to be a framework written on top of compojure that renames defroute to defpage and calls it a day. Obviously an unfair simplification, but what exactly does Noir bring to the table? Why would I use Noir instead of plain compojure+hiccup?
EDIT/UPDATE:
Noir is deprecated, interesting write up here: http://blog.raynes.me/blog/2012/12/13/moving-away-from-noir/.
From the author of Noir himself:
Noir isn't really a replacement for [compojure and hiccup], more of an abstraction over them. It was born out of seeing how a real web-app evolved and what was missing from the ring/compojure/hiccup stack as I built http://www.typewire.io. Also, as I mentioned in one of the other comments, I hope that it will serve as the single "package" to start with web development in Clojure, instead of having to try and cobble it together from the pieces that are out there now. By controlling all of it, I can create a much more cohesive and well defined story for helping people get started. I can also share what I've learned about maintaining websites in Clojure and hopefully encourage patterns that avoid some of the pits I fell into.
(emphasis mine)
Noir, the framework has been deprecated by Noir maintener himself.
It suggests to use Compojure and lib-noir :
For new websites, please use Compojure and lib-noir. This is pretty much just as batteries included as Noir itself ever was! You just have to learn how to write routes with Compojure. It’s easy and just as concise as it was in Noir. You don’t have to use ring-jetty-adapter and stuff, just use the lein-ring plugin to start your server. Also, if you took advantage of Noir including hiccup by default, you’ll have to have an explicit dependency on it now. No biggy, right? Right!
Compojure
lib-noir
Compojure is a small framework that generates Ring request/response handlers, where handlers are chosen based on routes you define.
Noir adds functionality for session handling, cookies, templates and partials, an easier way to generate responses, form validation, route filters, encrypted passwords, JSON (de-)serialising and custom status pages. In other words, Noir combines Compojure, Hiccup, and a bunch of other clever stuff in one package.
You can always check the API on the webnoir.org website. There is a lot of added functionality besides defpage.

Development "model" for clojurescript/clojure applications

Note: I'm a backend (Java) developer by trade and work in Clojure in my spare time, so forgive me for my ignorance.
I'm trying to get my head around Clojurescript and how it could potentially fit in with projects I'm working on, or plan to work on in the future. As I've grown up with the "classic" web development mindset (e.g. Clojure running the backend, distributing data to the frontend via JSON to be processed in JS or returning a HTML page for the browser to render), I'm having trouble trying to understand how Clojurescript might make things better than this model.
Could anyone explain to me what the general approach to Clojurescript/Clojure development would be, seeing as the "Clojurescript One" project moniker signifies that application development will be unified under one language (as such)
What tasks would normally be done in the Clojurescript portion of the application?
What tasks would normally be done in the Clojure (e.g. backend) portion of the application?
Any help would be appreciated, or if anyone can point me towards some diagrams or explanations or anything - that would be great too!
I think Clojure/ClojureScript applications will be structured very similarly to X backend technology + JavaScript.
One big benefit with architecting applications with Clojure and ClojureScript - a richer data format than JSON (you can represent hash-maps and sets with arbitrary keys) without losing compactness.
JavaScript is a fine, fine language but ClojureScript offers quite a few benefits. It's semantically simpler (functional), ships with a rich standard library, a robust battle tested application library (Google Closure), and all the benefits you get from the tasteful application of syntactic abstraction via macros.
That said, it's still very much alpha software and the tooling still needs a lot of work.
A bit of background about me, I have developed with Clojurescript, JQuery, Vaadin, Servlets, JSP, and many other web technologies.
1) Clojurescript is much harder to learn than any other web technology I have used as you need, Java, Clojure, Closure (with an s ;), Closure Lib, and Closurescript specific knowledge.
2) Clojurescript doesn't make sense for a small app. It only makes sense when you will have ALOT of client side processing
3) Clojurescript's only use as far as I see is as a better javascript (which is why it is better suited to larger apps) as the minifier part of Clojurescript is available for javascript too
4) Only the client end would be written in Javascript, the server would be in Clojure/Java servlets
Maybe Ganelon micro-framework (which incidentally I am author of) will suit your needs - the execution model is similiar to Vaadin's: server-side Clojure code pushes UI updates to the browser through AJAX/JavaScript, but we don't store application state in session by default.
The demo and docs are available at http://ganelon.tomeklipski.com/
For me, clojure and clojurescript offers cleaner code than mixed stack. There is only one language to think of and code is quite easy to read.
At the backend clojure does things that java usually would do. Input validation, saving to database and above all, implementing business logic. Our backend also validates incoming / outgoing data by types using prismatic schemas.
Frontend in short: We get pretty code using ClojureScript and it is fast to write. We are using ClojureScript version of material-ui when writing UI components. We have to write less code when compared to the JavaScript and I find our UI component code to be easier to read than JavaScript counterpart. One of the main reasons is shorter closing tags and less noise by coding language. Development with ClojureScript is quite fast.
Of course ClojureScript is used for simple imput validation like RegExp for phone numbers etc.
One of the disadvantages of clojure which you have probably noticed is long lines after giving proper names to the functions. I havent found silver bullet how to cope with that.
As dnolen said: ClojureScript is still developing. It is way better now than it was 6 months ago, so you'll have to keep checking its maturity now and then.

Django or Zope?

I want to create a website and I am confused which web framework to use. Please recommend me which framework is better: Django or Zope. I am using Python.
If you mean plain Zope2 by zope then I'd go for Django. Most interesting stuff in the Zope world takes place with either Plone or Grok (which is Zope3, which is actually quite different from Zope2).
Grok works nice with relational databases, Plone doesn't really, so if you depend on an RDBMS, either go with Grok or Django.
Zope and Plone have a rather steep learning curve so you'll get started more quickly with Django.
The largest downside about Django is, in my opinion, that it tries do do everything by itself (templating, object publishing, ORM, and so on) while there are many excellent existing components out there. If you want to be able to use your code / knowledge outside of the web framework you're using, consider Pylons or BFG
Many options, no clear answer, sorry :)
I have no idea what sort of website you're trying to create, so it's hard to recommend a specific framework.
I'd recommend getting through some tutorials to see which one you like best (There's also pylons and TurboGears to pick from).
Django seems to be the most popular starting kit these days though.
If your website is very hierarchical and needs fine grained permissions, I'd use Zope. (Don't use Zope if you intend to store your data almost exclusively in an SQL database.)
If you have large datasets that can be put into (sql)tables and need many forms, I'd use Django. (Don't use Django if you need very fine grained access control, and hierarchical data)
You see: both have their weaknesses and strengths (although I am only developing in Django these days. The Zope community seems to be a bit in dispute these days about the way it should develop)
Zope is dead. As is TurboGears, Pylons, BFG, Repoze, CherryPy etc.
Active and popular Python web frameworks include:
* django
* flask
* bottle
Big, medium and small. Take your pick.
Here is a good comparison of Django and Zope (and Rails)
http://cd-docdb.fnal.gov/cgi-bin/RetrieveFile?docid=2715;filename=Comparison.html;version=3
They preferred Django. I, personally, use Django too, so I don't know much about Zope.
Another good thing about Django is that they have very good documentation (though I don't know that of Zope). Many people praise that very much.
Also I found Django quite easy to use, and also they have a ready 'administrator panel', which allows quick web-oriented site management from the first steps. More important for me, however, is its fine integration with python and the simple organisation (in the link above they complained that Zope uses very much of its own features, while Django is closer to pure Python).
If you are starting from scratch I will suggest you should go for Django. You will get lots of features and suppost from django. Easy to debug and best suited for rapid developement. In the other hand, You should only choose Zope, if you have experienced developers familiar with Zope or have existing projects based on Zope and the cost of switching is too high for the potential value gain.
In zope's website it self it is written, It is no longer recommended to start new projects based on it, unless you are intimately familiar with the technology stack.

webjure vs compojure?

I've heard of two Clojure based web application frameworks: Webjure and Compojure. Can someone let me know which is better?
Now you can add Ring to the list. All of these frameworks are very new and likely to evolve (or die) quickly, but Compojure does seem to be the most actively developed based on the past 6 months or so.
"Better" is too subjective a question to get a definitive answer to. Try them all and see what works.
Compojure has been working very well for me so far. I like the simplicity of the design, the flexibility and the fact that it encourages a nice idiomatic functional style.
Sample server:
(use 'compojure)
(defroutes my-app
(GET "/index.html"
(html
[:h1 "Hello World!!"]
[:body "This is some text"]))
(ANY "*"
[404 "Page not found"]))
(run-server {:port 80}
"/*" (servlet my-app))
Note that Compojure uses Ring internally.
I second Rayne's recommendation on Moustache.
Right now, we are using Ring (base layer, middleware), Moustache (routing), Hiccup (html generation). We just began using Compass for CSS (http://compass-style.org/). So far, I'm happy with this collection of small libraries rather than a big "complete stack" framework (Django, Rails, ect...).
Now, there is also a new one named Noir build on top of compojure. Really recommended, especially with Heroku.
Compojure seems to be getting the most buzz right now. Not necessarily indicative of quality, but the one with the most eyes will probably evolve the fastest.
There is also Moustache, which is what I use in TryClojure, along with Ring. It's pretty awesome.
Compojure is based on Ring, which is a low-level framework that doesn't attempt to hide much of HTTP. It's similar to WSGI (Python) or Rack (Ruby). Ring has a concept of middleware, small pieces of code that can do something meaningful with an HTTP request and/or response, such as dump header infos, manage cookies etc. Compojure is a higher-level framework, somewhat similar to Ruby's Sinatra. Its aim is to provide a convenient API (or DSL, if you prefer) for most tasks a Web app developer faces. It's usually used together with an HTML generation library, such as Hiccup.
I haven't heard much about Webjure in the last few months, I'm not sure it's in active development (but I'd be interested to find out more). It precedes Ring, AFAICT, which seems to have become somewhat of a standard for Clojure Web frameworks.
I've been building a project for my own use using Compojure and it has worked out great. It doesn't really get in the way very much and lets you focus on what's important, your problem domain. The project is about 1100 lines of clojure just to give you an idea of the size.