Where those designations appear in this book and Addison-Wesley, Inc. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers discounts on this book when ordered in quantity for special sales. ISBN 1.
|Published (Last):||26 July 2004|
|PDF File Size:||14.67 Mb|
|ePub File Size:||15.24 Mb|
|Price:||Free* [*Free Regsitration Required]|
About the conference QCon is a conference that is organized by the community, for the community. The result is a high quality conference experience where a tremendous amount of attention and investment has gone into having the best content on the most important topics presented by the leaders in our community.
QCon is designed with the technical depth and enterprise focus of interest to technical team leads, architects, and project managers. I am Sadek Drobi. I am here at QCon with Stuart Halloway.
Can you tell us a bit about yourself? What you have been up to? I work at Relevance in North Carolina; we are a small Agile shop. We have been doing a lot of development primarily with Ruby over the last several years and in the last twelve- eighteen months have gotten very interested in Clojure programming.
So I wrote the book "Programming Clojure" which has been out for several months now and we have been doing a lot of customer work in Clojure and had a lot of interesting early experiences with this new language. We have this assembly language for the JVM called Java and then there is a lot of other languages that you can use on the JVM that have specialties in various areas, all of which are more expressive and are a lot easier to write code in than Java.
So Clojure does that. Second big piece is that Clojure is a Lisp and so if you are someone who is concerned about problems of meta programming, then eventually you are going to love Lisp and you are going to like languages like Clojure.
The third piece is functional programming, so Clojure is a dynamic functional programming language. So the notion that most of your program, say ninety five percent plus, is in a pure functional subset and then the non-functional, the imperative parts of the code, are atomic updates of values with well defined state and concurrency semantics and very easily separated out from the rest of the code and sort of kept sane. I mean people get scared from Lisp.
Do you have any prior Lisp experience or functional programming experience? If you are, in , a Java developer and you are looking for something more expressive, there are things that you can do that will have a much shallower learning curve and give you real value over working in Java. I had the good luck of starting my career in the eighties doing Emacs development.
It turns out that that is not as big a problem as people think. One of the things that needs to be done is, a case needs to be made for structural editing modes in IDEs. So when I am doing Clojure I use paredit mode in Emacs and what paredit does is it lets you look at your code not as characters, words and lines, but in terms of the structure of the language.
So it says "I know this is an atom or this is a list of code" and I can manipulate it at that level with a bunch of keyboard commands. Another piece of that which is really important is that all of the closing parentheses are ignored by the primary editing plans in paredit mode. If I am at the end of the word and if I hit kill to end of line and there is a bunch of parentheses those are just ignored by the kill, and they just get pulled back in and it all works.
So I think that structured editing modes, in fact structured editing modes in other languages would be really cool, they are just a little bit harder to implement. Paredit mode actually works with other languages in Emacs.
And so it would be interesting to see that idea take off, and I think that other languages would benefit from it and Lisp would look less scary at the same time.
So what are the application domains of Clojure? I think that the irony of functional programming for me is that functional programming is all about composition of pure functions to build applications rather than OO or mutable code. So something that talks to a database or something that answers web requests, or something that talks to a no SQL data store of some kind. There is no interesting state in the application anyway, I am doing a little bit of stuff and then I am asking a question of some other process, and waiting for an answer and then handing that off to someone.
There is no interesting state and there is no benefit to carrying around a bunch of noise, which is sort of incidental complexity of state in the application. So this is a very broad sweet spot but I think that the sweet spot for Clojure and really for other functional languages as well, is applications that have state. So by pulling out the part that is not state-full it actually makes it much easier to work with the part that is.
So there, I have claimed the entire world almost all applications do that. The flip side, the place where I think that Clojure is not a sweet spot today is anything where there is a solution almost done in another language. So if you sit down in front of a development project and say "Ninety seven percent of the intellectual property in this development project is already done in open source library x and I am just going to knit that together and put a bow on that and everyone wins", then And when you are willing to integrate your already existing Java code for example in Clojure, do you think you have to wrap it or can you interact with it directly?
I mean this is a gap between two paradigms, right? So would you wrap it or is it as easy as to call it directly? It depends on the kind of Java code that you are going to be using; some Java libraries are very Clojure friendly by nature like Joda-Time, because it is immutable time objects. I would use Clojure or maybe JRuby to do that kind of thing. Certainly Clojure has some antibodies against mutable Java code, so when from Clojure you look at a Java collection it actually gets reified as a Clojure sequence and becomes immutable on the Clojure side so you are protected.
This is not nearly as much benefit to the language if you are not going to accept the paradigm. Is it concurrency that made you interested in Clojure or is it more than concurrency? I mean we were very happy, we felt that compared to the industry average we were using very sharp tools, but it was kind of a quest on how can we make them sharper.
And I am an enthusiast of Paul Graham and Steve Yegge and other folks that have evangelized Lisp to the rest of the developer community over the years. So for me Clojure is over determined. If it had its Lisp features and its elegance of interop with the JVM I would have switched just for that. I had successfully ignored the siren song of Haskell and other things for quite a long time; not successful anymore, right now because of Clojure I am looking at FP from other angles as well.
And Rich Hickey, the creator of Clojure, has done a terrific job in some recent conference presentations that are recorded and up on the InfoQ website. One of the interesting things is that the approach to state is remarkably easy to use.
Rich on several occasions told us that we got the whole state concept, we got it wrong in enterprise and industry. Can you elaborate more on that? But in short the way that we think about state in the objects world is that we have objects, and objects are a combination of identity and behavior in state and they are all thrown together and from a getting started perspective there are some advantages to that. So for example in OO at a first approximation the "How do I solve this problem" question is really easy.
If someone walks up to you and you are an object oriented programmer and they say "I have a blah blah blah, what do I need? In the Java world we have this double checked locking is broken problem and the interesting thing about that is that when I first learnt about that issue it was about JVM esoterica. And so you can layer into a system one or ten or a thousand observers and they are not going to have any impact on the operations that are going on.
And this is not incredibly new, in some way if you come from a Haskell background or somewhere like that, but it is certainly outside the mainstream of the way most software is being written today. Several programming language implement functional programming in a slightly different way like there is the Lisp way, there is the OCaml way, and there is for example the Haskell way.
What do you think of functional programming, I mean which way do you like to see it and what is an interesting software[stuff? Because we are hearing more and more about functional programming. So a I am not qualified to answer.
There is a ton of interesting stuff in the functional languages that I am exploring because I got excited about it because of Clojure. That the difference in thinking about mutable state and references to mutable state is a lot more fundamental than whether you have a static or dynamic type system. Clojure is dynamically typed and I think that that means, for me at least, it provides an easier learning curve than Haskell. Because one of the things as an Agile software developer, type discovery maybe goes on throughout the process.
I know how to sit down with stakeholders and model things and very iteratively make those models converge on what they need. At this point it feels orthogonal to me to the whole issue of functional programming and my mantra for is everybody needs to be learning about functional programming. So Clojure chooses to use reference types for dealing with states, dealing more correctly with state.
There are other languages like Erlang and Scala copied it they use actors. Can you explain the difference between these two dealing with state? First off I think we need both. I think that Clojure has solved, to the extent that we know how to right now, what in process semantics should be about state. I think what Erlang does is really about something that works out of process. I mean you are going to pay the overhead of copying things around. If you use these immutable objects and have references, then you can have some amount of coordination locally without having to do stop the world and locking.
I would expect to see languages that have both models supported coming on. The actor model can be added with more or less pain even on top of a mutable language if you want to do it. Part of the idea of all this interop is that somebody should win. Congratulations Scala yours is the best and the Clojure guys are going to call it too, and so will the JRuby guys.
So it will be interesting to see if that actually happens, and it will strengthen the case for all of the JVM languages to see that kind of interop happening. So that would be exciting. The flip side is, how many Java programmers really only know Java? There is also an advantage to having significant history with mainstream industry languages and then go look at a language like Clojure because you have an appreciation.
If you just learned Clojure you might have a casual attitude to the features that were in it and say "Oh, this is a bunch of features that were thrown together and maybe another language with a bunch of other features thrown together would be equally interesting".
I actually think that the features that are brought together in Clojure are very tastefully collected and solve a whole bunch of problems that I was having on a daily basis writing code in other languages, and so it does kind of go both ways. For people that are interested in Clojure can you give us, from your experience, some motivating examples that gives motivation for them to switch to Clojure from your own experience about clients, about where you applied it?
A couple of things: just having functions be first class citizens. And you can see this with any language that has some sort of simple approach to functions and blocks, compared to the traditional OO pattern-heavy kind of way things are encoded.
But where it really becomes compelling is where you find the occasional re-factoring or change of approach that operates at a higher level but has that kind of effect on changing the code base where - we were working on a project where we had to implement a protocol for data, and so there is a message that has a certain structure and you have to receive the message, you have to unpack the message, you have to apply some business rules,based upon the message and some stateful stuff, do some stateful things based on how this message interacts with past messages, and then you have to assemble a message in response.
Now you have a second message, now you do a third message, now we do a fourth message, and so forth, as you start to do that you realize that you are doing a lot of incredibly repetetive coding. Inheritance and the kinds of tools for re-use that are in common play would solve some of that, but by no means all.
And what we were able to do with Clojure is basically say, "You know what? We are going to define with a macro what looks like a new language feature — def message". So you define def message, it lays out the structure of the message in data and then there is an interpreter that can read the structure created by def message and it sort of generates all the rest of the code for doing all the message processing, and then you have that very thin layer in the middle of doing the business logic, against now what has actually been converted into Clojure maps; just data.
And all of the messaging stuff is solved, with a set of def messages.
Component Development For The Java Platform
About the conference QCon is a conference that is organized by the community, for the community. The result is a high quality conference experience where a tremendous amount of attention and investment has gone into having the best content on the most important topics presented by the leaders in our community. QCon is designed with the technical depth and enterprise focus of interest to technical team leads, architects, and project managers. I am Sadek Drobi.
Component Development for the Java™ Platform by Stuart Dabbs Halloway
Most of this metadata is type information enumerating the base class, superinterfaces, fields, and methods of the class. Type information is used to make the dynamic linking of code more reliable by verifying at runtime that clients and servers share a common view of the classes they use to communicate. The presence of type information also enables dynamic styles of programming. You can introspect against a binary class to discover its fields and methods at runtime. Using this information, you can write generic services to add capabilities to classes that have not even been written yet. The binary class format is a simple data structure that you could parse to perform introspection yourself. Reflection provides programmatic access to most of the metadata in the binary class format.
Component Development for the Java� Platform
Stuart Halloway on Clojure and Functional Programming