Today is a good day to code

JoostBook – Joost to Facebook Interface Widget

Posted: December 31st, 1969 | Author: | Filed under: java, JavaScript, Programming, Uncategorized | Tags: , , , | No Comments »

JoostBook – Joost to Facebook Interface Widget

Picture of IrvinSince I'm in love with Joost, I have been thinking about good applications that I could write for the platform. Before I get into talking about the widget / plugin, let me just say that the experience I have had with communicating with the Joost engineers, through their joost-dev google group, as well as them allowing early access to their SDK, has been outstanding. I have rarely come across a more open and generous group. Typically, the SDK guardians are very selfish about discussing future features, and are usually quite arrogant about the possibility of a developer finding an undiscovered bug. None of this has been the case with the Joost SDK staff.

If you don't want to read the details about how I built it, and you just want to use it, you can get it here: JoostBook: Joost / Facebook Interface. You will need Joost, and a facebook account to get started.

Now, about the widget. Firstly, the installation is a little wierd because of the level of control facebook insists on. In order to use the SDK, you have to authenticate, if an unauthenticated request is made, the response is with the facebook login page. This makes for some unique error catching conditions.

Secondly, we web developers often take for granted that the DOM will have a listener attached to it, and will automatically refresh if anything in the DOM changes. Well, I know that the Joost engineers are working on it, but it doesn't refresh, and therefore, while you can create new XHTML elements, as well as modify the ones that are there with JavaScript. You are best off currently just hardcoding all of your objects up-front, and changing their contents. Also, injecting XHTML using innerHTML doesn't really work so well currently either. I'd suspect that much of this is because there is a bridge between the 2D world of XULRunner / Mozilla, and the 3D world of the Joost interface. I'm sure there is a lot of complexity between the two.

So basically, once you have downloaded Joost, and installed the plugin, the first thing I had to do was check for if you are logged in, if you aren't logged in, it has to show you the facebook login page in an iframe so that the XULRunner browser can be cookied. After that, the widget should work like one would expect. You may have to log in alot, and if you aren't logged in, obviously the application can't update the JoostBook facebook application.

Writing the Joost plugin was the easy part, getting the facebook stuff to work was the hard part. Most of it was because the error handling is terrible. Since facebook doesn't allow you to see the 500 errors that your server is throwing, and it doesn't log it, you have to find other ways to check to see if your server is behaving properly. I spent a lot of time in my logs checking for errors.

The install process is a little wierd too, for example, in Firefox 2.0.0.8 on Windows XP, when I clicked on the Joda file linked in the page, it tried to open it as if it were some kind of markup file, obviously the joda looked like garbage, I had to right click and save. Perhaps if I had used a joost:// link it would have worked OK, but I think more research is in order. I didn't really try it in IE because most of the readers of this blog use Firefox, but it should work the same way.

Then having to install the application in facebook can be a little difficult as well. Well, the installation isn't difficult, its the concept that you have to install two applications that work together that is hard. At least there is no particular order in which you need to install them, worst case whenever you run the JoostBook plugin in Joost, it'll show you the facebook login page all the time.

At any rate, it was a fun experience, and I still think the guys at Joost are on to something. I'm slightly less psyched about the facebook platform, but I'm still excited about it.


Coding Using Mides the PHP IDE for iPhone

Posted: December 31st, 1969 | Author: | Filed under: iPhone, java, mides, Programming, Uncategorized | Tags: , | No Comments »

Coding Using Mides the PHP IDE for iPhone

Picture of IrvinSo I have been checking out twitter, and it seems that people think that I am either crazy or sadistic for writing Mides so that one could code using PHP, JavaScript, and HTML on iPhone. The truth is that I am neither, well perhaps a little crazy.

What made me write it is that I was thinking it would be awesome if I could work on my sites on the iPhone. Everyone has downtime every once and a while where you wish you could do a little work. Mides does that for me. Working on projects here and there, it is amazing how much one can get done.

The way I came up with it was actually working in NetBeans and playing around with the code-collapse. That started the thought process that lead to the code collapsing metaphor present in Mides. I know that some hate it, and others love it, but for me it seemed to be a quick easy way to drill down into your code. Also, an additional benefit was that it allowed me to focus on the class, function, or loop that I was writing.

To me, the keyboard has never really been too much of an obstacle. I understand that for others it can be a problem, but having had my iPhone since it came out, the last time I thought about the keyboard was about two weeks after I had bought it. I really wanted a flexible bluetooth keyboard for blogging from the phone, but later I really didn't need it.

While not perfect, the code completion does help a lot, and once you get used to it writing markup can be really quick. I will keep working on ways, other than the ones already present, to allow Mides to accelerate text entry.

Some of the things that frustrate me while using it, even though I wrote it, are that I can't easily look up reference material on code that I am writing without leaving the code. Clearly copy and paste would be nice, and I wouldn't be surprised to see it in a subsequent release. The ability to debug JavaScript, and a real HTTP server running locally would be awesome, to help with resolving absolute paths. Ideally, I'd be able to process PHP directly on the iPhone, but that is complicated for a number of reasons.

Many of these features will be coming, but actually most of the effort has gone into thinking about how to achieve the complexity of a full modern IDE, while keeping the UI cluttered. I feel that I have succeeded in many places, where others need work. It is my aim, however insane, to build Mides into as feature complete an IDE as is possible given the hardware and software stack provided by Apple.

I used Mides to build the mides site, including all of the canvas tag work. I think I only did about 5% of the coding on the Mac. There were some interesting incidents working with alpha quality code trying to build a site on the iPhone.

Well, feedback is always welcome, and I am not above listening to rational criticism. I want Mides to be useful to everyone, and am looking forward to the day when I can do just about all of my work from my phone!


The Web as Google”s Data Source

Posted: December 31st, 1969 | Author: | Filed under: java, Programming, Uncategorized | Tags: | No Comments »

The Web as Google's Data Source

Picture of IrvinOne of the things that Google is doing to the web is that it is, I believe by design, deterring individuals from doing things that make the presentation layer richer. The method by which they crawl and index pages leaves out Flash and AJAX content entirely. When a company that bases their revenue on pageviews and or visits is designing a web property, doing an all AJAX / Flash / Silverlight / etc… implementation of the interface is often swept off the table because Google and other search engines can't crawl it. It makes more sense for these companies, financially, to do a tidy looking crawlable interface.

The interesting thing about doing a “SEO friendly” interface is that it often isn't the best from an architectural perspective since your presentation and business logic are tied up in your controller. Technically speaking, you can't change one without the other changing on the application server. I talked about this a while ago in an article discussing the MVC pattern and application servers. Instead what you get, minus any JavaScript and CSS, is a nicely formatted, structured document, ready for ingestion into a massive database, i.e. Google's, and presented through a much nicer UI, i.e. Google's.

When looked at this way, it becomes apparent what the future of the web looks like. At first I was against things like AppEngine and doing SEO based pages until I realized that much of what is happening around us, RSS readers, and the like, are really interfaces that aggregate web content and taylor it to the way I want to see it in an often native interface. When you imagine the web as a massive data source you begin to understand the need to impose formatting rules on the interfaces. Not that crawling AJAX sites wouldn't be a daunting task, but with Google's technology, they could accomplish it, but I don't think it would be in their best interest.

If Google can get everyone to insert their content into the App Engine, then it saves them a step because your content would be inserted directly in their database, no need to crawl. Then Google could create optimized mashups of your content with other content to create superior applications. Anyone using AppEngine, or anything of the sort has to be aware that this is a possibility. If they want to control the creation of mashups, they should not use it.

My recommendation to build a future-proof site would be to build a clean simple version for the web, per Google's guidelines, and then build a desktop and mobile version that can digest your content and present it in a more flexible way. This may change as runtime web scripting languages become more powerful, but in some ways I think that we would be worse off without Google's webmaster guidelines. The web as a data source is a powerful concept, one that I'm sure is not lost on Google, or Vint Cerf. I just don't know how much that concept jives with the way people currently think of the web as a platform.


Some Java Long to Time Stamp Conversions

Posted: December 31st, 1969 | Author: | Filed under: java, JavaScript, Programming | 1 Comment »


Recently I found myself in timezone hell, trying to convert back and forth from GMT to Local timezones, as well as the larger problem of trying to convert from a java long to ColdFusion’s strange ODBC date format. I looked around the web for some little tools to help, but I couldn’t find any conversion tools from long to a timestamp, so I could verify my conversions. So, I decided to write them. Here they are:

Input a Long to Convert Into a Time:

Converted Time

Current Time


The MVC Disaster Befalling Application Servers

Posted: December 31st, 1969 | Author: | Filed under: java, Programming, Uncategorized | Tags: | No Comments »

The MVC Disaster Befalling Application Servers

Picture of IrvinI have always felt that the entire metaphor of MVC has been broken to a degree in web development. For a while I thought that AJAX held promise that eventually we would reach the point where we could have true MVC in that the controller would be the application server, the model would reside in the database, and the view would be entirely pushed down to the client as JavaScript.

Unfortunately, largely because of Google and its cohorts, this promise will have to wait. Since pages must be indexed, and Google refuses, not can't, but refuses to index AJAX content the pattern will remain broken.

The first and most egregious breakage of MVC is between the controller and the view, so we'll start there. The current implementation of web applications typically has HTML residing on the server mixed with JavaScript. This HTML is usually generated by an application server, so it is mixed with some, hopefully small, amount of business logic. Frequently this resembles a family gathering over noodles, tomato sauce, and meatballs. If people want dynamic behavior they will frequently deliver an RSS feed, or some other form of XML or JSON to the client via AJAX and update some div somewhere after parsing it. This is how good implementations are done today. What I'd like to know is where is the MVC in that design? business logic should not be allowed in template pages at all, no conditionals, no loops, definitely no method definition, this should not be allowed. What should happen is that you should be able to use an XML tag to create an instance of a bean representing a view interface and call getters. This would be a proper implementation of an application server IMHO.

The next and most dangerous breakage of MVC, not just in code cleanliness and readability, but also in security comes in the interface between the model, and controller, or as in some cases the model bypassing the controller and heading straight for the view. Typically this manifests itself in some process generating HTML, JavaScript and CSS from the domains data, and putting that content on an application server. Then using JSON or XML and the XmlHttpRequest pulling that preformatted content and putting it directly on the screen. In this case, there is no separation between layers at all, its just that kid putting his stupid hand down through the cake and squeezing at your birthday party.

If you are a single developer, it may be possible to manage such an implementation, but for a team it is impossible, there are bottlenecks everywhere, UI people have to wait for the process to run to generate the markup, the back-end people have to wade through lines and lines of markup to debug their code, and if you have AJAX engineers, forget it, they have to understand your back-end code to deal with the generated JavaScript. In other words, and put simply its a mess. Even sending HTML to the UI, a hijacker could change URLs so your client clicks and goes to a phishing site, etc… that is not to say that it couldn't happen with XML, but it is a little easier to handle these security issues if you have several steps between receiving the data and displaying / executing it.

On the security front, many people like JSON. I like it too if all hackers were to disappear. If someone were to inject packets into your JSON stream, it is too easy to hijack someone's browsing session. Remember all JSON is executed once its loaded in most cases, at least with XML usually it is treated like text and is never eval'd.

Unfortunately there is no application server that comes close to this strict MVC implementation. Maybe, in a stretch you could suggest that JSF, JSP, JSTL, and Tomcat all together create a decent MVC implementation, but really no server does that. Even if it did, people wouldn't know how to use it anyway.

Why does this matter? It doesn't if you are the only one maintaining and implementing a web application, if you waste your own time it really doesn't matter. It is when you need to scale in performance via parallelism, or in resources that you will constantly curse yourself for not fixing this broken MVC implementation. As far as I can see, facebook is coming the closest to doing a good job, at least metaphorically in this area, that may be because I can see their API. The fbml model is a good one, it conceptually separates business logic from the view, and hopefully their model is separate, I'd say it is because of the robustness of their model API it is.

At any rate, I'd hope to see better application servers, and implementations soon. I think it will take better application servers forcing better implmentations to make people change.


Google Forcing Apple to Embrace Java on iPhone

Posted: December 31st, 1969 | Author: | Filed under: java, Programming, Uncategorized | Tags: | No Comments »

Google Forcing Apple to Embrace Java on iPhone

Picture of IrvinWith the Android SDK preview now out in the wild, we can guess a few things about the future. The first is that the iPhone will find itself stuck as a niche device, and never find its way into business, or be the “Jesus Phone” that everyone wants, if they don't embrace Java, or release a crippled SDK. The second is that Android will be a force to be reckoned with in the cellular industry and that Symbian had better watch its step. The third is that Google is proving its commitment to keeping information free.

The iPhone will remain a niche player if they don't embrace Java. This is a bold statement. What I really mean is that basically, more people know how to write Java applications, than know how to write Objective-C applications, or AJAX applications. It is a much better understood language, and with the Jazelle ARM extensions, the iPhone is an excellent platform for the language and a Java SDK could incite an explosion of applications developed for the iPhone. I have talked about the iPhone's Jazelle processor before, and it is almost a no-brainer as to Apple releasing Java and Swing for the iPhone.

With Google, however releasing a Java based SDK, the applications will be developed for the Android platform, these will include music playback applications, video applications, all sorts of mashups between, business applications, you name it. While the iPhone will end up being just an MP3 player with a phone, and a great browser crippled by an awful data network. People who love iTunes will keep using it, but the hue-and-cry of the prosumer and enterprise for better interoperability and more applications on the iPhone will go away, and people will just buy Android phones instead of pushing Apple.

By being whatever carriers and phone manufacturers want it to be, Android can easily become the most popular phone OS, quickly replacing Symbian, at least on “smartphones.” Let's face it. Until the iPhone the best interface we had, when it was not locked up, was on the Windows CE devices. Android gives users a good looking interface with minimal effort. Its pretty much going to become the standard OS for smartphones, and will aid Palm on its way to becoming only relevant as a Wikipedia article entry.

Google is making good on its mantra to a) do not evil, and b) organize and make available the world's information. It will effectively free the information that is inside my cell phone, and enable me to take my phone from carrier-to-carrier, or just use Google's service, hopefully. By finally opening the cell phone's software, something that for years had been intentionally obfuscated, and by democratizing software development for the mobile platform, Google will enable users to choose what they want to run and how. Carriers may try to stop users from installing applications, but I think that given the handset manufacturer's partnership with Google, they won't try.

All in all, this is the best thing to happen to the cellular industry, basically ever.


MacWorld 2008 Spoiler Leaked Keynote

Posted: December 31st, 1969 | Author: | Filed under: iPhone, java, Programming, Uncategorized | Tags: , | No Comments »

MacWorld 2008 Spoiler Leaked Keynote

Picture of IrvinLike it was said on technovia, if the leak is real, it will probably be deleted. So it looks like there is going to be a 16 GB iPhone, no mention of 3G. There was mention of a new MacBook Pro ultraportable, great, but what I really wanted to see was information about the new SDK. What was there, if true, is good and bad.

First I want to point out that I think Apple is giving the indie community what they have been asking for. There will probably be many, many more widgets than Apps. The revenue and pricing model covers Apple's cost for distribution and validation of the source code. That is O.K., and will probably be O.K. for most developers. The current interface between widgets and Cocoa is a JavaScript Cocoa bridge, with Apple allowing use of the frameworks that are acceptable to them. If this is in place, it will, for all intents and purposes, make this the primary method of developing applications for the iPhone. The problem is that if larger 3rd party developers will be forced into a subscription model for their applications, especially if Apple does cap the max cost at $6.99.

At any rate, it was a cool read, if you want to read it too, here it is, but don't expect for it to be around long:

Leaked MacWorld 2008 Keynote


iPhone onorientationchange Event

Posted: December 31st, 1969 | Author: | Filed under: iPhone, java, Programming, Uncategorized | Tags: , | 1 Comment »

iPhone onorientationchange Event

Picture of Irvin* Update: I was wrong about this, it won't work. you have to use the dirty markup method and put it in the body tag. Safari's DOM renderer processes the JavaScript in parallel, so the body element is not recognized by the JavaScript if it is at the top. There are other ways to delay the execution of this command until the DOM is rendered, but they aren't worth the trouble *

I'm glad that Apple has created this event. I think most of the developers who started early with the iUI were polling for the window.innerWidth. While this was an awesome hack before Apple had a proper event. Well now they do, but I don't really like their example code.

It is somewhat nitpicky, but applying an event handler to an element explicitly in the DOM is not the best way to do it, besides not being valid HTML / XHTML, it is sloppy. Some would argue that most validator plugins will detect your addition of the event handler post rendering anyway, but at least your html looks clean for debugging if you don't have strings of event handlers on all of your elements!

At any rate, what Apple's example shows is:

That will work as long as your JavaScript libraries are included before the body element, something that YSlow! and Yahoo! suggest hurt performance. I don't agree with Yahoo! on their performance guidelines most of the time, but in this case, I have seen the improvement, and I am now a believer.

If you leave your markup alone and add the event handler in one of your JavaScript files like:

document.getElementsByTagName(“body”)[0].onorientationchange = updateOrientation;

Then your markup will remain clean, you can move your JavaScript script include tags to just before your closing body tag, and you will have a quick and efficient page.

If you are handling the orientation event, it will return 0 for portrait, -90 for landscape after a clockwise turn or to the right, and 90 for landscape after a counter-clockwise turn, or to the left if the screen is facing you.

For most cases, you would have to determine if it was not 0, like this:

if(window.orientation != 0){
// iPhone is in landscape mode
}else{
// iPhone is in portrait mode
}

That is simplistic, but it should get you started. At any rate, I am really happy that Apple is bringing more events online, hopefully we'll get firmware 1.1.3, local storage, and advanced WebKit CSS functionality in that update, or shortly thereafter.

Apple's original article is at:

http://developer.apple.com/documentation/AppleApplications/
Reference/SafariWebContent/HandlingEvents/chapter_8_section_6.html


JavaScript and Object Oriented Programming

Posted: December 31st, 1969 | Author: | Filed under: java, Programming, Uncategorized | Tags: | No Comments »

JavaScript and Object Oriented Programming

Picture of IrvinFor some time now I have advocated using what I, for lack of a better term, call object oriented style coding when approaching JavaScript. Recently, Joseph Smarr talks about some of the challenges faced by developers who try to do too much with JavaScript. He brings up some good points, I'd like to discuss some of his findings, and add a few that were left out.

He talks about every line having a cost with JavaScript and being brief when writing it. I would go along with that, with the caveat that if you are writing something with JavaScript's condensed notation and no one including yourself will be able to understand it in a year, you should probably go ahead and write it out longhand with comments, whether you leave the comments in when you release it is up to you, but I think the extra cost in performance is worth clarity.

You have to be willing to not make an object out of everything. In lots of ways, we have to “kill our darlings” to borrow a literary term, in that you have to be willing to break encapsulation, destroy design patterns, and do some hacking for performance. It is important to remember that with languages people typically use OO for, the compiler will take out redundant statements, and optimize away some of the things you have done to maintain sane code. With scripting languages, especially JavaScript, we don't have that luxury. That elegant factory pattern that looks so good in the code may, and probably will fall apart as far as execution performance. Unfortunately, many developers will not compromise the ideals they have been taught once they reach this point. So we end up with slow performing UIs that could be fast.

One thing that Joseph Smarr doesn't talk about is taking a hard look at what really needs to be done on the client. It is critical, when profiling to determine if the speed of a round-trip to the server is worse than the performance of your code against the client. It is important to think about ways in which the beefy server can do some processing. As sexy as a fully SOA is, if it performs like a dog, no one is going to care what the technology is behind it.

Many of the best developers refuse to work with JavaScript because of these things, and it is a shame because I think these are the people who are best in a position to change some of the negative aspects of the language. Also, writing procedural code forces some efficiency while OO seems to allow just about anything. If you can't handle the prospect of writing JavaScript, try C, not C++ it is the same sort of thing.


WebKit Nightlies With Local Storage and Wild CSS Functionality

Posted: December 31st, 1969 | Author: | Filed under: java, Programming, Uncategorized | Tags: | No Comments »

WebKit Nightlies With Local Storage and Wild CSS Functionality

Picture of IrvinMy head is still spinning after downloading the WebKit nightlies and messing around with the local SQL Lite storage, and the css animation and transitions. Man, this stuff has my head swimming with the possibilities for interesting applications.

More importantly, when is this going to make its way to the iPhone. I hope we don't have to wait for Apple's next big cat to be released for us to get some of these features. I know the SQL Lite access is really early, and also that most of these features are HTML 5 things being given to us early by the webkit staff, but for early features, they sure are pretty complete looking at first glance.

I don't know what the what3g is in an uproar about, with Apple starting work on HTML 5 in their browser. To me it looks like innovation. It isn't always tidy, but it is always welcome. I haven't been this excited about the web since gmail hit and AJAX started taking over!

Anyway, please check out the nightlies at: WebKit Nightlies I am not sure if it will work with PC Safari, I think those are earlier builds, but if you have a Mac, have a field day. Also, check out Drosera, the JavaScript debugger, and the Web Inspector in the debug menu, if you are using databases, you can check out the contents with that. Boy Safari has come a long way in a short time. I think the battle will definitely be WebKit and Mozilla, I wonder what Firefox is going to come back with. The new WebKit stuff is really strong.