Wednesday, September 23, 2009

The Insanity of Google Chrome Frame

So Google is fixing Internet Explorer for Microsoft. Great, fine. You know what really pisses me off however? Is that Google decided this was a priority when you have people like Ray Ryan at Google I/O 2009 telling people we don't have infinite resources to get GWT 2/UiBuilder out the door.

Or the same speech about various AppEngine features. Like, for example, how about a JPA implementation that is actually worth a damn in AppEngine? Like instead of giving us a big speech about de-normalizing data on AppEngine, how about you use the current JPA annotations to do it for us, you have enough information in those annotations to do it for us.

Or a browser on Android that is actually good, you know with multi-touch and pinching. And don't give me that crap about Apple patterns. Apple is at war with Google, Google is just too dumb to realize it yet. Also, people, don't call the Android browser Chrome Lite, it's not fast enough to be deserving of the name Chrome just because it's WebKit based. The architecture of these 2 browsers are very, very different.


Monday, August 24, 2009

Ending Series on C++0x Feature Focus

Considering that the "x" in C++0x now appears to be an hexadecimal number, I'm no longer interested in continuing my series on this topic.

Sunday, June 28, 2009

WebKit: Bridging the Great Mobile Divide

I hate Objective C and I hate Apple's Xcode and I think I hate Apple's AppStore policies even more but the people do love their iPhones. Furthermore, if you've had to deal with development on many different smartphones on the same project, you know how painful this is. You code one version for the iPhone, then you port it to BlackBerry, then Windows Mobile, then Nokia N60, and if you're lucky, Android.

So, if you want to develop for iPhone you either have two choices: develop a web application or go native. Unfortunately, even if Mobile Safari is a fantastic browser, it doesn't yet implement all of the HTML 5 features. Assuming iPhoneOS 3 here, Safari supports the following:
  • The new video/audio tags. Albeit using only mp4 containers, h264 video and AAC audio. Furthermore, it does so by opening the video player application, in effect exiting the browser
  • It supports app cache. With the proper manifest, your application's assets will be stored locally. Opening the door for the application to run without connectivity
  • Support for HTML 5 databases. First is the assets, then it's the data. With both, your application can potentially run without connectivity.
  • Canvas. It supports canvas for more complex rendering.
  • Workers. Thread workers so that long running JavaScript code doesn't need to lock up the user interface
The only big in-draft HTML 5 (the file desktop API isn't in the draft yet) feature it doesn't support is geolocation. That being said, what if you need access to the accelerometers? Or the iTunes music library? Sorry, you're back to native and coding in Xcode and Objective-C.

Well, a funny thing happened to me the other day while watching this Google I/O session. I was expecting an introduction to the C/C++ kit and that's it. Turns out that was pretty boring. What wasn't boring however was the idea of using a web view and injecting custom JavaScript element in the document's DOM.

That concept introduces a new, more sane, alternative to coding in Objective C and Xcode and supporting many different platforms. Basically, you write an HTML 5 application using GWT. So you're writing with Java 5 syntax in the IDE (and debugger) of your choice for the majority of the application. You only write a small shell containing web views in your iPhone application.

So how about porting to other phones? Well consider the following phones that have WebKit in some variant or another:
  1. BlackBerry. Ships with a WebKit based browser since 4.6. That means the Storm/Bold, won't cover most of your users but eventually it will. Please note however that JavaScript is disabled on BlackBerry phones by default.
  2. Android. Ships with a WebKit based browser.
  3. Nokia S60. WebKit is now the default browser engine in S60 phones. Write a shell using C++ and Qt.
  4. Windows Mobile. WebKit is nowhere to be found. Again, not a problem since the Qt port to this platform has WebKit, write a shell using C++ and Qt.
  5. Pre. Ships with WebKit. Not only, but Palm only wants web based, HTML 5, apps to be written for its phone using WebKit. They even introduce some new DOM elements to access other services in their implementation.
  6. Finally, iPhone, write a shell in Objective C embedding WebKit.
The strategy is the same, use a native application so that you're not jailed by the browser but keep most of your code portable by embedding a web view using WebKit. Furthermore, thanks to GWT's deep JavaScript integration and GIN, you could write interfaces that get bound to the proper native/platform specific implementations automatically at runtime.

So now we actually have a platform for sharing a lot of code between the major smartphones out there. And what if you need those iPhone like visual effects? Well, it's absolutely possible with JavaScript. Consider gwt-fx, it has all the standard iPhone visual effects and more and when you're stepping out of what the standard iPhone controls do out of the box, is actually easier and less verbose to use in terms of code. For your enjoyment, gwt-fx has an effect playground available here.

Ah, NSObject reference counts, how will I miss thou? Well, not at all I must say.

Monday, June 22, 2009

Windows 7 Exploit Source Released

In an effort to get Microsoft to change their mind on UAC's default behavior in Windows 7, the source code for the UAC injection technique has been released. Considering this system has been covered here many times, I won't rehash anything here but you can find the source and information about the tool here.

Saturday, June 6, 2009

Microsoft Research For the Win?

Experience in reviewing Microsoft counts. Paul Thurrott is one of the most credible Microsoft technology reporter in the business.

In his latest podcast with Leo Laporte, episode #110, he rants very humorously at Project Natal. All I can say is ouch and thanks for putting this technology in perspective.

Tuesday, June 2, 2009

Microsoft Research For the Win

Just a light post to say how impressed I am with "Project Natal".

EnGadget has the details here.

Saturday, May 30, 2009

Move Construtors

For simplicity sake, we assume the name space 'std' is used here. Given the following:

vector<vector<string> > v;

We now have an expandable array of string arrays. Now I don't want to poke inside the possible different implementations the string class could have here. We assume the worst, that string is implemented using a single C array of characters and leave it at that.

However, also for the sake of this discussion, we assume that the vector template class capacity is always at least bigger than its size. So we can assert the following:

assert(v.size() <= v.capacity());

Where the capacity holds numerous empty slots at the end of the array for future allocations. So, if we have the following:

vector<string> v1, v2;

v.reserve(32);
v.push_back(v1);
v.push_back(v2);

We are can safely state that the insertion of v2 inside of v did not cause v1 to be re-created, copied and destroyed.

The problem comes from the following:

v.push_back(v1);
// v.push_back(v2..v(n - 1) where n == capacity == size
assert(v.capacity() == v.size());

The next time we insert into this vector, the capacity will be expanded, most implementations will double the size to avoid any extra copying that might be caused by being over-conservative.

This means we have the following algorithm going on inside v the next time we insert:

1. Save the capacity to a local variable and double it, we call this n
2. Allocate a new array of vector of size n.
3. Copy construct a copy of every element found in the original array
4. Destroy every element found in the original array
5. Delete the original array
6. Capacity is now equal to n
7. The new array replaces the old one
8. The new element is inserted at the position "size" and size is incremented by 1

The problem here are steps #3, #4 and #5. Vector simply can't move the pointers found in the array because ISO C++98 dictates that vector (and all standard C++ containers) be safe for storing objects, i.e., data types that have a virtual pointer table. In fact, in this case, vector can't even hold pointers to its elements because the standard also dictates that vector, like all other standard based containers, is value based for maximum flexibility.

So the problem is that all these vectors found inside 'v' are copied element by element, string by string and then destroyed.

Now, considering that capacity is usually expanded by 2 every time this limit is reached, this shouldn't be too bad right? Well, unfortunately no, without any compiler optimizations, returning the value from a function or method is sufficient to trigger a copy. So simply put:

v = do_something(v);

where do_something is defined to be:

vector<vector<string> > do_something(vector<vector<string> > v) {
return v;
}

is sufficient to trigger 2 copies, one by the value argument, and one by returning the value. Suffice it to say this is not very efficient especially considering how widespread the standard containers have now become in the world of C++.

The new ISO C++0x standard introduces a new feature to address this shortcoming, a move constructor. In the previous example, our vector template class defined a copy constructor using the following syntax in order to perform copies:

template<typename T>
vector<T> (const vector<T>& other) {
// perform the copy
}

However, we can now complement this constructor with a move constructor following this new syntax:

template<typename T>
vector<T> (vector<T>&& other) {
// OK, let's steal some memory, so for example
m_rawArray = other.m_rawArray;
other.m_rawArray = 0;
m_size = other.m_size;
other.m_size = 0;
}

Here, the move constructor only gets called when a copy is performed and the previous copy is also known to be at the end of its life. So that means it's OK for us to "steal" memory that belonged to our forebearer.

This is a simple feature that will address the main performance concern of the standard C++ based containers. Even if end users are unfamiliar with this new feature, they will still reap the benefits of it the next time they compile since most standard C++ library implementations (and the Boost libraries) will be enhanced to use move constructors. By using a move constructor here, vector can now avoid all the expensive copy operations it needed to perform in the previously showcased algorithm.

Monday, May 25, 2009

C++0x Feature Focus

Starting a new series of blog posts related to language changes found in the upcoming C++0X standard. These will focus on core language changes and not on any libraries. You will need gcc from the head branch or the Visual Studio 2010 beta 1 to compile any of the upcoming samples. Even then, some of the samples will not build even with these compilers since some features have yet to be implemented.

I want to highlight the following new features:
  • Move Contructors
  • Perfect Forwarding
  • Variadic Templates
  • Closures
Closures, a.k.a lambdas, are already implemented today in the libraries but the ISO committee decided it was time to put this in the core to have a unique syntax across all systems.

Friday, April 24, 2009

A Peek at the Compatibility Future

Users enjoy the broad compatibility Windows has. Even 20 year old 16-bit DOS based applications still run on Windows 7. However, the flip side of this is that it has made Windows very hard to maintain for Microsoft and very hard for developers to use.

That is, targeting multiple version of Windows is very difficult. Bugs present in one version and not another meant different run-time behavior for the application. Add to that the complexity that earlier versions of Windows were also fundamentally different depending on which version of Internet Explorer was installed, even the kernel was touched, meant you add a significant number of operating systems to test and debug. Ultimately, the best solution for portable applications for Windows was to use some kind of layer between your application and the operating system, most notably Java. Sun, or whoever, does the heavy lifting and you target one platform.

If you're familiar with Microsoft however, there's one very interesting technology that you just know is the future. The future of compatibility that is. That technology is called MED-V. Yes, it's a stupid name but the technology is far from stupid. MED-V is based on Virtual PC but instead of running a different operating system with a different desktop it runs your applications side by side.

What is stupid however, other than the name of course, is that this technology is currently only for enterprise customers who have volume licensing. This is a very sad state of affair considering that this would allow for a much more streamlined user experience for people who only want the latest and greatest and much greater compatibility for those who do not. What I mean by that is that ever since Vista shipped, Windows is a considerably more modular operating system with the capability to turn various features on or off. The potential still isn't realized today but Windows 7 goes a step further by allowing various applications to be "turned off".

Now, with MED-V, you could go that extra step, on your brand spanking new machine, you could, say, no 32-bit application, so that entire part of the OS goes missing. No resources no nothing. It also means that even if you're running these compatibility modules, it doesn't mean they're running all the time or at the same time. Furthermore, since these are full virtual environments, they're actually a copy of the target OS that the legacy application was designed for. What's also very interesting is even if these are virtual environment, they're running on the bare metal which means you still have the full power of your actual machine unlike actually using a virtual box.

Well everyone who knows about MED-V knows it's the future, well, at least the technology if not the name. This technology would allow for Windows to grow at a faster pace and cut off deprecated APIs and SDKs without breaking compatibility with older applications.

Which brings me to today, Microsoft has unveiled Windows XP Mode (XPM) for Windows 7. This is the same technology that powers MED-V but what it means is that every copy of Windows 7 will ship with a fully licensed copy of Windows XP SP3 for compatibility mode. So if you're a large enterprise with poorly written line of business (LOB) applications, all of them really, you'll be able to depend on this Windows 7 module to run all those applications. If you just happen to not care about this and just consider it bloat, that's fine too, just turn it off. In fact, if you don't really care about any of this, XPM doesn't actually run unless you use something that needs it.

Reviews of pre-release versions of Windows 7 praise how lean it is compared to its predecessor. That you agree with that or not doesn't really matter, thanks to XPM and eventually the full MED-V, you'll be able to turn off huge, gigantic portions of the operating system and developers and users alike will be able to enjoy new versions of Windows that are free from binary compatibility with older applications but nonetheless offer full compatibility which will mean a much leaner, more secure operating system for all.

Monday, April 13, 2009

Google Updater

Google has been very busy this past week making new release after new release. The release however of Google Updater as open source is definitely very interesting.

One of the most annoying aspect of the modern Windows XP/Vista desktop is keeping your applications up to date. That is, you have an auto-update for Windows and other Microsoft software. You have one from Adobe for your Adobe applications, one from Mozilla for Firefox and the same software but yet another instance for Thunderbird. You have one for Vuze, you have one for any number of applications. Keeping all your software up to date today just requires too much work.

It was hoped that with Windows Vista, Windows Update would be opened to 3rd parties beyond the driver space but that hasn't happened.

The availability of a high quality open source application updater for Windows doesn't guanrantee it will become the de-facto standard nor that all companies that end up using it will share the same instance/server on the back end but it may pressure Microsoft to finally open up Windows Update to 3rd parties.

Anyway, I see this as good news and just hope that we will finally see some progress in this area.