Posts

Doing it wrong, fun with Clojure

Image
I certainly take a liberal approach to programming, some may call it quantity over quality but I like to enjoy everything I do. This may include doing it wrong, but sometimes I like the end result. I am working on a SWT GUI tool and could not figure out a clean way to avoid SWT's illegal thread exceptions. When a user clicked a menu option on the gui, I needed to first take text from an edit box field and then use that data to pass to a long running thread. This is what I ended up with: ;; Define the clojure 'agent', save the state of our search box ( def *search-text-state* (agent nil)) ;; Define an implementation of 'SelectionAdapter/Interface' ;; SelectionAdapter requires one method 'widgetSelected' ;; With display.syncExec, pass an implementation of java.lang.Runnable ;; The thread updates the 'agent' search-text-state text. ;; After we get this text value, then launch another thread 'start-findgrep' ( def findgrep-listener (p...

Test Driven Development, BDD and Junit

Here is a question I asked on stackoverflow. The responses are pretty interesting. I don't know if you read the recent post by Joel, but basically he says that you don't need unit testing for every unit or piece of code in your code base. "And that strikes me as being just a little bit too doctrinaire about something that you may not need. Like, the whole idea of agile programming is not to do things before you need them, but to page-fault them in as needed." -- Joel And I would say that most developers don't have full coverage anyway, yet there are some blogs out there touting the 100% code coverage. "Yeah. In fact, if you're making any kind of API, a plug in API, it is very important to separate things into interfaces and be very very contractual, and tightly engineered" -- Joel "Right. The longer I think about this, the less I care about code hygiene issues (laughs). Because the unit of measure that really matters to me is, how quickly you ...

Cher is a moron, or why I hate group-think hate on other groups

Image
http://cnsnews.com/public/content/article.aspx?RsrcID=43192 Cher is a moron. "You know what? I have so – I try to be charitable and there are some really good Republicans, but I just don’t understand how anyone would want to be a Republican. I just can't figure it. I don’t understand," she said. 'If you’re poor, if you're any kind of minority – gay, black, Latino, anything. If you’re not a rich – I don’t know. If you're not a rich born-again-Christian, I don't get it." I have a comment for you, musicians shouldn't discuss politics. How does that feel? Doesn't make a lot of sense, does it? I feel that there isn't such thing as a "Republican", the same way that I feel there is no such thing as a "black" person or a "white" person. Race is also unscientific and difficult to categorize people. You have genealogy which can be traced from generation to generation, but that doesn't mean anything. For example, ...

Outline for "Enterprise Development with JVM languages"

I am creating a book, "Enterprise Development with JVM languages" I am an "Enterprise" (I know people don't like that term) developer and about to start a book that deals with JVM languages for use on larger enterprise applications, especially geared towards Web and Database driven systems. I want to cover a lot of the JVM languages that are used today, I don't feel that a book has truly covered these topics. If I am an Enterprise developer and am considering a JVM language, I would want to see how the language compares with other languages, possibly with the Java language. How could this language be used? What are the advantages, disadvantages, etc? I have also noticed that some developers are religious about the programming language they use. I am not partial and just want to find the most productive tool for the job. I want to cover the following languages, I know there are a lot, but a developer may decide to investigate all of them or use a combinat...

J2EE/Java Grips 1: Websphere is garbage, OMFG 1

I was debugging a websphere/RAD issue, thinking that maybe I had messed up a configuration way down in the cellar of RAD's infinite supply of configurations. Maybe the flux-capacitor node mx3e cell.xml missed the rptptppt_Vn_ setting. No my friends, RAD seemed to have bombed on a missing servlet tag in the web.xml. NPE, NullPointer on not having the most basic setting in a J2EE app. Don't get me wrong, a developer should have the setting, but something more helpful like 'You are missing your servlet mapping' would have been helpful. here is the configuration and the error. < servlet-mapping > < servlet-name >OnlineServlet</ servlet-name > < url-pattern >/OnlineServlet</ url-pattern > </ servlet-mapping > ------ [ 1/26/09 23:30:14:166 EST ] 00000047 SystemOut O Caused by: java.lang.NullPointerException at com.ibm.ws.wswebcontainer.webapp.WebAppConfigurationHelper.constructServletMappings(WebAppCo...

Simple Agents/Concurrent Programming in Clojure

Image
"All concurrency issues boil down to coordinating access to mutable state. The less mutable state, the easier it is to ensure thread safety." -- Java Concurrency in Practice (from Bill Clementson's blog) Like Erlang, Clojure is becoming a very powerful concurrent oriented language. It is designed to be a simple language making it easier to coordinate access to resources. "Agents provide independent, asynchronous change of individual locations. Agents are bound to a single storage location for their lifetime, and only allow mutation of that location (to a new state) to occur as a result of an action" -- http://clojure.org/agents Here is a simple example of two agent functions 'agent' and 'send': ;; ;; Simple example of agents (concurrent coding) in Clojure ;; The send function waits/hangs and then returns the result. ;; ;; Note: only the calls to 'Thread.sleep' in the main program ;; block the main thread. ;; @see http://clojure.or...

Simple lisp interpreters in C, Java and Erlang

Image
Overview I have already covered the lisp interpreters in Erlang and Java. I have created another example that is based on C. So, you have three different implementations in three different languages. Also, these interpreters are based on Peter Norvig's JScheme implementation. That is a fourth project that you can compare and contrast. Peter Norvig created JScheme, a Lisp Scheme dialect written in Java. It was created in 1998 and it has since been forked, extended and used quite extensively in other modern projects for the web and elsewhere. The C lisp interpreter is based on the JScheme interpreter. The JScheme code is copyrighted to Peter Norvig This is only a modifications to make our Lisp even lighter than it was originally. Norvig's most recent implementation of JScheme contains 1905 lines of Java code. This implementation contains 2000 lines of C code wrapped in additional Javadoc comments, including implementations of list, hashtable datastructures. There is...