Good start to a new year

February 3, 2007

Filed under: JavaScript, Java — Doug Clinton @ 2:05 pm

A month has passed since my last entry. Have I really learned nothing at the office in that time?

Actually, I have been very busy. Last year was a year of consolidation for my small company. We built a good foundation on top of the opportunities we had the previous year and have solidified our relationship with our main client. This year I hope to make one of expansion. Our aim is to really build on that relationship and expand the company from our current 3 people to, perhaps 7 or 8.

I’ve spent a lot of January working on planning out the year and we have a number of potential projects in the pipeline so things are looking good. This means, hopefully, that I can get my head back down into the technology again. We have an interesting project lined up to do with processing Schematron. That maybe doesn’t sound so interesting, but we’re taking a novel approach in order to re-use the platform we build last year and it should be quite fun.

BTW, we’re recruiting. We’re looking for a really good all-round Java developer and also a really top-notch JavaScript person. I know that’s not much of a job description but if you think you might be interested in working for a small, innovative and friendly company in West London then by all means send you CV to <jobs at gsl.com>.

JSONRequest proposal

October 26, 2006

Filed under: JavaScript, Web2.0 — Doug Clinton @ 10:34 am

Here’s an interesting proposal from Doug Crockford at json.org that would allow javascript apps to connect to sites other than the one they were loaded from in order to retrieve data. He is appealing to browser makers to incorporate it into future versions.

XMLHTTPRequests, and in fact any form of HTTP request, to sites other than that from which the page was loaded are forbidden by browsers as they pose a security risk. HTTP requests carry the cookies from the original site which means that requests to other sites would be able to see those cookies.

The proposed JSONRequest would not send cookies and can only send and received JSON encoded data. JSON is an IETF RFC that specifies a subset of JavaScript that only allows data to be encoded, not functions, so there is no danger in eval()’ing the returned data. The only downside I see with this is that if you want to get data from an authenticated connection on the originating server then you have to use XMLHTTPRequest which makes access a bit inconsistent. It would be useful if JSONRequests to the originating site included the cookies, but requests to other sites did not.

I have used JSON since I started working with Ajax since it seems much more logical and a lot simpler and faster than passing XML around and parsing it. There are good libraries available for many languages that make it easy to process on the server side and on the client side it is just a matter of running eval() on the JSON string to get a JavaScript object.

Technorati Tags: ,

First experiences of jQuery

October 18, 2006

Filed under: JavaScript, Programming, Web2.0 — Doug Clinton @ 10:53 am

I latched on to dojo early in my Ajax career (that would have been, oh, say 4 months ago). The approach the dojo developers take to modularity, classes and so forth appealed to the Java programmer in me. It made things familiar enough to get a handle on easily. Plus, I went to see Dylan Schiemann present a workshop and was impressed by the depth of his knowledge.

However, as I started to work seriously on our application, I began to get the feeling that I was missing something fundamental about JavaScript by hiding it behind the familiar constructs of classes, inheritance and encapsulation in the form that I am used to. Because real work (you know, the stuff that pays the bills) came up I needed to pause what I was doing with JavaScript, but in the meantime, I began to take a close look at HTML and CSS design. In my spare minutes I re-developed our company website to use the ideas I was learning from Andy Budd and others about separating content from presentation, making the design flexible to handle different screen sizes and printers, and things like using CSS for rollovers rather than JavaScript actions.

Then, last month, I came across jQuery for the first time. The first thing that impressed me was the documentation. It’s not 100% comprehensive, but it’s a lot better than dojo’s documentation and good enough to get going straight away. The other thing that struck me, however, was the different focus it has. Using dojo, I felt as if I was using a programming language first and DOM stuff second. I’m not saying that that is the fault of dojo, but its efforts to make things more Java-like meant I didn’t need to break out of my mental model. Also, jQuery has the feel of a second wave of toolkit, building on the lessons learned from things like dojo and protoype.

jQuery most definitely focuses on the DOM first. It provides a lean, but well-formed set of constructs to search and manipulate DOM trees. The searching bit uses CSS selector strings (or XPath, but I like the CSS) which are now more familiar to me. My own focus has now shifted and I’m seeing the client-side application as primarily visual elements with behaviour attached, rather than application behaviour with views attached as I had been. I can see pretty clearly now how this fits in with an MVC-style and how I can connect it up with the messaging system we wrote earlier to reflect changes in our business domain objects.

A bonus is the large number of plugins that exist for jQuery, written by third parties. I am making use of the drag and drop features of the Interface plugin and already I am seeing a big reduction in the amount of code I am having to write to get things done.

Throughout the 25 years or so that I have been writing software I’ve looked at a lot of different languages. I’ve always believed that even if a language was not practical to use for whatever sort of problem I was trying to solve at the time, it is still valuable to be pushed into thinking about things in a different way. I’m starting to feel that JavaScript and jQuery are causing me to think in new ways

Technorati Tags: , , ,

Setting the CSS class name on DOM elements created in JavaScript

October 2, 2006

Filed under: JavaScript, Programming, CSS — Doug Clinton @ 10:29 pm

When I’m developing in JavaScript I primarily use Firefox to display the results as it has really good tool support for debugging code and inspecting the resulting page. Every now and then I cross-check in IE 6 to make sure things are still working.

I was very surprised the other day to find that when I took all the style settings I was applying to DOM elements created in JavaScript out of the JS code and put them in a separate style sheet, that all the style formatting disappeared when viewing things in IE. It took a good half-hour of hair-pulling, google searches and referencing the dozen or so books I have available on web development before I finally stumbled across a fragment of code which pointed me in the right direction. I had been setting the class name of the new elements using:

domNode.setAttribute("class", "classname");

which works perfectly well in Firefox. However, IE seems to completely ignore this (although the DOM inspector from the IE web development toolbar showed the class apparently being set). The code I came across showed this instead:

domNode.className = "classname";

After converting my JavaScript to use this form, lo and behold my styles were correctly applied in both browsers. This is the kind of thing which I have come across a lot since starting to work with JS - it is really hard to find answers to some really basic things like this. One thing that is clear is that most of the books and other literature is approaching JavaScript from the point of view of HTML and CSS designers, not people coming from a background of software development in languges like Java, C++ and C.

CSS overflow and height - compatability between IE6 and FF

Filed under: JavaScript, CSS — Doug Clinton @ 10:28 pm

I’m displaying text inside boxes by creating div’s with a 1 pixel border. To ensure the text clipped to the size of the box I wanted I set “overflow: hidden” and “max-height: 1.2em” and it all worked just fine in Firefox. However, in IE6 the box would stretch to show all the text. A bit of playing around has led me to discover that setting “height: 1.2em” instead of max-height works in both browsers.

Now I just need to get to grips with the DOCTYPE declarations. Using HRML 4.01 transitional without a DTD URL means the fonts aren’t the right size in IE6 (for “font-size: smaller”) but if I add the DTD to put IE into standards compliant mode then FF loses it.

I think I need to read this http://www.alistapart.com/stories/doctype/ quite thoroughly.

Powered by WordPress