7 ms·
Noir - The Clojure web framework
- vetler 15y agoThe examples uses Clojure as the language for defining the HTML. I've also seen Common Lisp examples (such as in Practical Common Lisp, http://goo.gl/CuUZQ http://goo.gl/CuUZQ) that use CL for the same purpose. In frameworks built for other languages, it is most common to have a separate template language for defining the HTML. It seems much easier to use the same language when using a Lisp dialect compared to for instance Java, which would be a lot more verbose, but it is also done this way to separate logic from presentation, and because it's (supposedly) easier for front-end developers. Coming from non-CL frameworks, it was natural for me to choose a template framework for my small (and now outdated) tutorial on writing a blog in CL (http://goo.gl/YHCw http://goo.gl/YHCw). However, I'm wondering if anyone has any experience developing web applications using a Lisp-dialect for generating the HTML (as Noire and the example in Practical Common Lisp), and if this is scalable to a team where front-end developers might not be used to or familiar with Lisp. The syntax seems easy on the eyes, so perhaps it's not such a big problem once they get over the unfamiliarity.
- timclark 15y agoThat will depend very much upon your HTML developers. Some will be able to do it, a large number will not. Even when using simple template languages I have experienced the I didn't understand those funny bits in the HTML so I have removed them far too many times. In Clojure, Enlive (https://github.com/cgrand/enlive https://github.com/cgrand/enlive) is a better solution because the HTML remains as HTML.
- markokocic 15y agoIs anyone aware of something similar to enlive in pure Java? I would certainly like to give it a try.
- SergeyHack 15y agoWicket and Tapestry are trying to do the similar thing. Not as good as Enlive though.
- ibdknox 15y agoI agree that it depends pretty heavily on who is doing your HTML. That being said, you can just not use the defpartial stuff and instead include Enlive to use with Noir just as well. There are purposefully no constraints on what you use to generate HTML. The main purpose of settling on Hiccup in this case is to provide something that I think the Clojure web community desperately needs: a single place to start and build something. The only way I can provide that start pointing is by making some choices and running with them. Also, I really love html functions as opposed to JQuery-esque template filling. It's cleaner and more flexible to me.
- weavejester 15y agoThe main advantage of writing HTML using a tool like Hiccup is that you can factor out repeated sections of markup into functions. For example, one might write a page like: (defn user-settings [user] (settings-for [user] (breadcrumbs (link home) (link settings)) (text-field :login) (text-field :email))) And the functions used would take care of generating the page, layout, form, fields, error notices, flash messages, CSRF protection and so forth. By the time you've finished with all that, those 4 lines of Clojure will be 50 lines of HTML. Hiccup tends to lend itself toward user interfaces that are uniform and predictable, with repeatable elements. Think Facebook or Github, for instance.
- swannodette 15y agoI don't see how this any different from what Enlive provides. Enlive templates/snippets create functions which generate HTML. In anycase, using Hiccup with Enlive seems to combine the best of both worlds.
- weavejester 15y agoHTML is a markup language, rather than a Turing Complete programming language, so there's a lot of redundancy in a HTML file that could be avoided in a programming language. You can get around this in Enlive and other HTML-based templating methods by taking a hybrid approach. The layout HTML is written by a designer, but all the tedious repeatable elements are written by programmers in helper functions, or factored out into dozens of smaller templates. I'm not sure I like this approach, as it (a) glues together several different methods for generating HTML, (b) encourages people to write the HTML around the page design, rather than treating HTML as purely semantic markup. I admit to being something of a purist when it comes to HTML. I'd prefer to keep the style and design of the page out of my HTML as much as possible; idiomatic HTML should be semantic markup, whilst the design of the page should be defined in CSS.
- swannodette 15y agoI don't see anything in Enlive which is at odds with your viewpoint.
- Autre 15y agoThe same philosophy is applied in the Seaside framework for Smalltalk. See for example [1]. [1]: http://onsmalltalk.com/page-templates-and-seaside http://onsmalltalk.com/page-templates-and-seaside
- draegtun 15y agoThe examples uses Clojure as the language for defining the HTML See this Stackoverflow question... CL-WHO-like HTML templating for other languages? (http://stackoverflow.com/questions/671572/cl-who-like-html-templating-for-other-languages http://stackoverflow.com/questions/671572/cl-who-like-html-t...) which provides some examples in other languages. However, I'm wondering if anyone has any experience developing web applications using a Lisp-dialect for generating the HTML (as Noire and the example in Practical Common Lisp), and if this is scalable to a team where front-end developers might not be used to or familiar with Lisp. I like keeping the HTML markup within the back-end developers domain and leave the front-end developers/designers to just use Javascript & CSS around it. (disclaimer: In most cases I'm both the back-end and front-end developer :)
- oconnore 15y agoIf a front-end creates a mockup using a certain DOM, it is easy for the back-end to generate that DOM (or tell the front what needs changing). If the back-end generates a DOM, it is typically easy for the front-end to create CSS/Javascript to fit (or tell the back-end what needs changing). Also, learning that (:a :href uri name) maps to <a href=uri>name</a> is not hard, so usually the front-end will be capable of making basic changes. It is not a significant obstacle.
- IvarTJ 15y agoWhile making a simple web application in Chicken Scheme, I used SXML transformations. From the code samples, that doesn’t appear to be the convention with this web framework. Is there a good reason to use alternatives to SXML? Or is it just preferences?
- timclark 15y agoWhy would I use Noir instead of compojure or ring + moustache?
- Zak 15y agoIt looks like Noir is a library of convenience functions built on top of Compojure, Ring and Hiccup. Some of it looks useful, though the fact that it uses SHA1 to hash passwords is not a good sign.
- ibdknox 15y agoAn oversight on my part :) Luckily, that is an exceptionally easy thing to fix. Edit: and now it is :D
- zaph0d 15y agoStill some nits - * SHA-x is not an "encryption" algorithm, it's merely a cryptographically secure, one-way hash. The function name and the documentation are thus misleading. * You shouldn't use SHA-x or MD5, etc. for password hashing anyway, because they are just way too fast! You should use BCrypt for password hashing. I can submit patches if you wish :)
- ibdknox 15y agoAbsolutely! I don't claim to be an encryption expert, by any means. :)
- zaph0d 15y agoI am no crypto expert either, but here is your patch - https://github.com/ghoseb/noir/commit/f814ea9d1bc7470197eb73cb0608009461926ffe https://github.com/ghoseb/noir/commit/f814ea9d1bc7470197eb73... (pull request already sent). Noir looks very good. Keep up the good work and let me know if you need any help ;)
- hencq 15y ago
- elevenE 15y agoI don't know Clojure (not sure how expressive it is), but for a framework isn't the code too less? I have seen other frameworks, but they are quite large (in terms of LOC.) Is it that they contain more functionality?
- nickik 15y agoThe clojure culture tents to build extremly small librarys that are really composable. Look at this video about simplicity (http://skillsmatter.com/podcast/java-jee/radical-simplicity/js-2051 http://skillsmatter.com/podcast/java-jee/radical-simplicity/...) it translates very nicly to the web librarys. In a nutshell: Make small simple things even if thats ends up beeing a bit more verbose then if you would have built it as one thing. If time shows that a set of librarys works very nicly together then you can write something new that combines these in a nice way. This is what the Noir does it just pulls together some librarys and delivers them in a nice package.
- puredanger 15y agoIf Clojure is too concise, you can always write a library to apply a more cumbersome syntax if you'd like.
- rix0r 15y agoLooks promising! One question: form rendering, validation and handling are the most important as well as the most annoying things you have to do while writing a web application. Do you plan to incorporate something for that into the framework?
- MatthewPhillips 15y agoVery nice, I've been wanting to get into Clojure, but not having a functional background I've found it hard to jump into anything. This looks easy enough that I could transition in slowly, I think I'll give it a try.
- DrJokepu 15y agoAs a side note, I've found that a very good way to familiarize yourself with a new programming language and its underlying concepts is by solving first 40-50 problems in Project Euler with the language: http://projecteuler.net/ http://projecteuler.net/
- rednum 15y agoWhile PE is great keyboard exercise and includes many cool puzzles, I think it is bad way of rewiring your brain for functional thinking. Unless you'll do some exercises that explicitly require new ways of thinking (and read something), you'll probably end up struggling with writing java code in clojure. I advice to do some FP course and then solving some problems in functional way - when you already know the way.
- rednum 15y agoIf you need functional background, you could try SICP - there is also a clojure version being developed. I took an Ocaml course on my uni 'strongly inspired' by SICP and I must say that it pretty much rewired my brain for functional.
- jm4 15y agoI have been doing mostly OOP for several years. I read just about every Clojure book out there, but the functional thing just wasn't clicking. It's a weird feeling. I knew the language, but didn't know how to design a program in a functional style. Maybe part of it is that most of the Clojure books available don't really cover this. Then I read "Learn You a Haskell for Great Good!" Eureka! I have never written a line of Haskell, but I feel like reading that book made me better using other languages. http://learnyouahaskell.com/chapters http://learnyouahaskell.com/chapters
- iLie 15y agoWay to go, webnoir! 502 Bad Gateway screen! Level of confidence instilled in me because of this: 0% Chance I'll come back later to check it out: 0% Probability I'll go visit Enlive right now: 100% Can't help but suspect you're choking on your own dog food here. Or crapping out a corn-studded loaf, take your pick. Well done!
- ZeSmith 15y agoI'm surprised that there's no large "Fork me on Github!" link at the top right corner of the screen. Still, looks very interesting.
- ibdknox 15y agoI honestly never really saw the appeal in those... There's a link to the source there though, so that's roughly equivalent :)
- va_coder 15y agoHere's what I don't get about Clojure fans: I don't see what problems you are solving. A simple Hello World program is made in Clojure and it gets upvoted all day. On the other hand Ruby on Rails folks are solving real problems today, making strides in integrating CoffeeScript and cleaning up javascript directories. It's like someone showing off a new garbage collection library built in C. The problem's been solved. Show me something new.
- chc 15y agoYou clearly weren't around the Rails scene six or seven years ago, when it seemed like everybody was writing blogs, to-do lists and similar basic CRUD apps (since it could be done with little more than a "script/generate scaffold"). When a technology is new and there aren't a lot of commercial projects using it yet, you'll get a low S:N ratio of projects coming from the community as people get their feet wet. As the technology matures, you'll see more "real problems" being solved.
- va_coder 15y agoI was around before Rails, back when Tapestry, Wicket and Appfuse projects were making my life easier. How does Clojure for Web development make my life easier? is the question that should be asked. Clojure's been popular in the hacker community for a good 2 years now. That's a weak argument.
- chc 15y agoTapestry, Wicket and Appfuse? You're making my point for me: The thinking you're using now to praise Rails and attack Clojure would have been just as valid seven years ago to praise Java and attack Ruby. All you're really remarking on is the maturity of the communities in question, but you're presenting it as a commentary on the usefulness of the technology. And Clojure has been known for a good two years now, but I would not have said Clojure was popular two years ago. It didn't have a lot of regular users, which is what you're observing when you say people aren't solving "real problems" in it. I'm not sure I'd even say Clojure is popular today. I'd say it's still roughly where Ruby was in 2004 — lots of excitement, but still lots of growing to do.
- dusklight 15y agoHey I really liked the syntax highlighting color scheme you used in the webpage, is there an emacs theme for that?
- akuzi 15y agoOne of the cool things about using a functional language for web development is the potential to use continuation-passing style (CPS) to make http look like a stateful protocol, which makes implementing chains of user interactions a lot simpler. I know Clojure doesn't support first-class continuations, but does anyone know whether is it possible to use Clojure Noir to program in this style?
- ibdknox 15y agoCan you give me an example of what that would look like? Or a description of the flow you'd want to achieve?