

Noir - The Clojure web framework - abp
http://www.webnoir.org/

======
vetler
The 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>) 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>).

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
That 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>) is a better solution
because the HTML remains as HTML.

~~~
weavejester
The 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
I 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
HTML 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
I don't see anything in Enlive which is at odds with your viewpoint.

~~~
weavejester
My viewpoint is that HTML shouldn't be written directly, because the language
isn't designed to be particularly DRY. Isn't that very much at odds with
Enlive?

~~~
swannodette
Enlive does exactly what Hiccup does with the additional bonus that it allows
designers who are comfortable with HTML to be a part of the process. Enlive is
not page centric - that's the whole point of snippets.

~~~
weavejester
But if none of your designers are writing HTML, what benefit does Enlive have
over Hiccup? Whilst Enlive could probably mimic Hiccup's style through
aggressive use of snippets, it seems to me that it would need more code to
produce the same result. Enlive seems the wrong tool for the job if you want
to use it in the same fashion as Hiccup.

------
rix0r
Looks 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?

------
timclark
Why would I use Noir instead of compojure or ring + moustache?

~~~
ibdknox
Zak's characterization is basically correct. Noir isn't really a replacement
for those things, 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.

~~~
weavejester
I'm encouraged that Noir builds on top of existing tools. It indicates that
our current set of web libraries is flexible and modular enough to act as a
good foundation for more sophisticated frameworks.

It looks like Noir uses a custom "lein run" command to start the server. Have
you considered using the lein-ring plugin, instead?

~~~
jcromartie
I've found that this is a really nice "feature" of Clojure, and maybe other
Lisps. Most libraries are very small and tend to all speak in terms of the
same de facto standard interfaces (functions, seqs, hash maps, vectors, etc.)
so they can be easily composed. Trying to fit together Java or C# libraries
like this is basically impossible without some mediating standard base classes
or interfaces.

~~~
owlpic
Not about Clojure, and has probaby been posted before, but:
[http://gbracha.blogspot.com/2011/06/types-are-anti-
modular.h...](http://gbracha.blogspot.com/2011/06/types-are-anti-modular.html)

------
elevenE
I 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
The 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/...](http://skillsmatter.com/podcast/java-jee/radical-
simplicity/js-2051)) 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.

------
akuzi
One 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
Can you give me an example of what that would look like? Or a description of
the flow you'd want to achieve?

------
dusklight
Hey I really liked the syntax highlighting color scheme you used in the
webpage, is there an emacs theme for that?

~~~
ibdknox
I use vim ;)

~~~
rads
Is there a vim theme for that?

------
IvarTJ
While 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?

------
MatthewPhillips
Very 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.

~~~
jm4
I 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>

~~~
mark_l_watson
I would recommend reading books like "Learn You a Haskell for Great Good!"
with an open repl. I find it is too difficult to remember new language
features until I type and run code.

I agree that learning Haskell as a prelude to learning Scala and Clojure might
not be a bad idea (I blogged about this a few days ago).

------
ZeSmith
I'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
I honestly never really saw the appeal in those... There's a link to the
source there though, so that's roughly equivalent :)

------
va_coder
Here'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
You 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
I 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
Tapestry, 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.

~~~
va_coder
I studied Clojure and I hope really cool stuff comes out.

When Rails came out it solved all kinds of new problems. For one, by using
metaprogramming a whole bunch of files were eliminated. As soon as Rails came
out I was much more productive than I was with Tapestry or Wicket. Not so with
Clojure.

~~~
rbxbx
The metaprogramming capabilities in Clojure greatly exceed those of Ruby, so
that's a bit of a weak argument if you're impressed by things of that nature.
Also one shouldn't forget about Clojure's concurrency model and functional
purity which lend themselves to correctness and scalability.

Just because it doesn't necessarily better solve your class of problems
doesn't mean it's unsuitable for other people's.

~~~
va_coder
"bit of a weak argument if you're impressed by things"

I'm impressed by results

------
iLie
Way 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!

