Some Google employees defect, then rebel

Brian Kennish traded his job at Google for a table at Starbucks, where he works on his privacy software called Disconnect.

Brian Kennish traded his job at Google for a table at Starbucks, where he works on his privacy software called Disconnect. [Image: CNN]


Many computer engineers consider a job offer from Google as the golden ticket. Outdoor volleyball courts, free gourmet food, on-site haircuts, massages and laundry are among the perks Google has offered its employees at its main campus in Mountain View, California. But some of the people who do leave are challenging the company in the best way an engineer knows how: by developing programs that could detract from Google's core business.
Brian Kennish worked at Google for seven years, managing teams of engineers on a variety of products such as the Chrome browser and the moribund Google Wave.

Near the end of his stint at Google, Kennish developed a browser extension for Chrome called Facebook Disconnect.

The software blocks websites that have Facebook widgets installed from automatically sending information about the user back to the social networking company. Facebook Disconnect has 75,000 users, Kennish said.
"No one at Google asked me to do it," Kennish told CNN this week.

What sparked Kennish's project, he said, was reading the recent scrutiny of online data-collection tactics chronicled by news organizations. The Wall Street Journal has been running a series called "What They Know," and CNN had its own last week called "End of Privacy."

While Facebook and the applications that run on its platform can be considered personal-data hoarders, Kennish eventually realized his then-employer was, itself, among the biggest collectors. To name a few practices, Google can track search queries over time, target ads to its Gmail users based on the contents of e-mails, and use a person's location data to determine which shops' ads it will show. Google, like many Web advertising companies, uses small files called cookies to track internet surfing habits in order to better target ads.
"I never worked directly with user data," Kennish said of his time at Google. "I didn't have a good sense of what was being collected. Privacy wasn't a passion of mine or something that I knew a lot about until basically two months ago, when I started reading about this stuff."

Kennish left Google in November to focus more on programs that empower people to take control of their privacy online. "I had this holy-cow moment when I realized what was going on," Kennish said. "There's just so much unknown about what's being done with this data." "I think there is a good reason to be concerned with it all and, frankly, to be fearful of it," he said.

Last week, he released a second browser extension, another tool for Google Chrome, called Disconnect. Once installed, the program blocks major internet companies, including Google, from installing cookies on -- and thus tracking -- a computer. People using Disconnect can decide which cookies they'd like to allow onto their system. Cookies can be helpful when, for example, you'd like a website to remember your login credentials and not ask for them every time you visit.

"I would like to see us move to a point where all the data that's collected about folks is intentional," rather than without people's knowledge, Kennish said. "So if I give you permission to collect my data, then go ahead and do it." In its first week, 25,000 people downloaded Disconnect. Kennish is releasing a new version Friday that lets users choose whether Google can personalize search queries based on the data it has about the person. By default, Disconnect blocks Google from doing this.

"Any data that's collected has the potential to escape the collector," Kennish said. "So I would like to see Google only collect data that I explicitly allow them to collect." Google hosts a dashboard for users to review a breakdown of the messages and information attached to their accounts. The Google Privacy Center provides information on how the company collects data and lets people, whether they're registered with Google or not, opt out of ad and analytics tracking.

Michael Gundlach, another ex-Google engineer, developed an alternative to complicated opt-out systems that vary between ad networks. Like Disconnect, it's a browser extension, and there are versions for Chrome and Apple's Safari.

Called AdBlock, Gundlach's program can prevent Web pages from loading and displaying ads. That includes Google's ads, which account for the vast majority of the search giant's revenue. AdBlock offers a setting to easily enable ads from Gundlach's former employer, though those ads are disabled by default. "Google didn't ask me to put that in," Gundlach wrote in an e-mail. "I find Google text ads to be useful."
Still, Gundlach says he blocks most ads because "I don't wish to be bombarded by consumerism."
The real economic conundrum: If website visitors don't pay figuratively -- by watching ads or by having their personal information sent to advertisers -- they may have to start paying real money for online services.
Kennish plans to devote six months to developing Disconnect and will reevaluate then whether it could be a sustainable business.

He's "pretty close" to releasing an extension for Safari and recently began working on one for Firefox, he said. If he's forced to abandon the project, the source code is freely available to any enterprising developers who want to take up the cause. "The only business model I see," Kennish said, is to eventually provide a more advanced version of the software that costs money.

"When I use something like Google, I'm paying for Google with my attention and my data," he said. "There's no such thing as free. These are companies that have to pay employees' salaries."
Parts of Google's maturing business may clash with some of the wide-eyed engineers it hopes to attract, especially those passionate about taking risks to change the world, hopefully for the better.
But a Google spokesman, who declined to comment on most questions pertaining to this story, said the company's attrition rate -- that is, the percentage of employees that defect -- hasn't changed in more than seven years and is better than the industry standard.In addition to all the on-campus amenities, a program called "20% Time" lets Google engineers devote a sizable chunk of their work weeks to projects of their choosing. (Kennish said he developed Facebook Disconnect after work hours)

The perks haven't stopped some high-profile people from leaving the company. Product designer Douglas Bowman left in a huff last year for a job at Twitter after reportedly becoming fed up with nearly three years of what he publicly described as Google's design-by-committee mentality. Some notable Google alumni are spiting their former employer in a different way -- by joining Facebook. The social network is perceived by some as Google's biggest rival. People are spending more of their time online using Facebook. They're thumbing through photos and asking questions to friends, rather than searching the wider Web. Google is unable to crawl most of the data posted to Facebook.As Google-to-Facebook defections grow, Google is reportedly offering some employees multimillion-dollar packages to convince them not to go to Facebook.

After wooing executives who worked on Google-owned YouTube, Android and advertising; the architect of Google Maps; and at least two Gmail co-founders, this week, Facebook claimed Paul Adams, a former Google employee who was previously an outspoken critic of the social network. Sheryl Sandberg, Facebook's venerable chief operating officer, also came from the big G.

But abandoning Google hasn't always proved to be a wise or permanent move. Anna Patterson left the company in 2007 to start a rival search engine called Cuil. When that tanked, she returned to Google in September.
To subscribe to the "Guy WhoSteals" feed, click here.
You can add yourself to the GuyWhoSteals fanpage on Facebook or follow GuyWhoSteals on Twitter.
Any feedback can go straight into Guy's mailbox:
  • guywhosteals AT gmail DOT com
  • guywhosteals AT yahoo DOT com

Erlang is like an exotic beautiful woman with no dressing sense.
I came across Erlang about a year ago. It is a language of a kind - precise, crafted and powerful. Its been there for about two decades now, and people have been using it for serious real-time applications. But the hype Erlang is getting in the last couple of years is mostly for wrong reasons.
Having said that, its a language every programmer should look into at least once - its refreshing. And it might just be the perfect language that fits your needs.
What doesn’t Erlang have? It has its own Virtual Machine that it runs on. It is ridiculously simple to write distributed applications, with its message-passing style concurrency. It has its own database. It supports hot code swapping without even restarting the servers, and its already been proven in some telecom applications that need very high uptime. Hot code swapping is still a nightmare even in a supposedly mature language like Java which is targeted at building web applications - that have high availability and scalability.
However there are certain things that either suck or are not as convincing about Erlang.
1. Today’s mainstream developers who are used to C or Java like syntax wont find its Prolog-like syntax too friendly. Unless you started programming since the 80’s & 90’s and are used to languages of similar syntax, it will take quite some time before you get comfortable with Erlang’s weird syntax. I never felt too comfortable with the syntax.
2. While the core language itself is small and easy to learn, the libraries within the language are inconsistent, incomplete and poorly documented. I posted a couple of questions in the forums regarding how to use a library, and usually the answers would be “Don’t use that library, use the other one”. (Oh yeah, kind of like the Java JDK Logging. Please use Commons Logging.)
3. Only a few people have written production level codes and you rarely get to hear from them. All you hear from is Erlang enthusiasts, who are hyping it as the next big thing, but haven’t done more than a few labs from Armstrong book.
4. I can’t imagine how you can organize large code-bases in Erlang or even work as team, and this doesn’t feel right to any OO programmer.
5. Most of the performance matrices are one-sided, and are performed by people who have an interest in Erlang. I would love to see some independent analysis.
6. Its support for web-development is very primitive. With web frameworks like rails and grails, there is a lot of serious work for Erlang if it ever intends to go to that market.
7. Did I talk about Strings in Erlang? IO speed?
I know weaknesses aren’t as important as the strengths of a language. Erlang has it own expertise, its syntax structure, and its own audience. But the flaws of Erlang might just turn away a new programmer, even before he gets to its beauty.
If you are writing a web crawler, Erlang may very well be your choice. If you want to write a client-server, where the client makes a large no of requests, and you want to spawn concurrent processes to process the requests, Erlang could be your choice. If you want to write a Distributed Hash Table, Erlang could be your choice. Or if you are writing a video streaming server or doing system integration or writing any system utility. But a regular developer (building a CRUD application on top of a database, right? ) doesn’t have much to do with Erlang as yet. Secondly, even if you are working on those highly scalable, reliable and concrurrent systems, people have a hard time accepting Erlang along with its flaws.
The industry has a definite space for Erlang, currently and more so in future as we deal with more and more users, more data, and more forms of distribution. If not for Erlang exactly, then for an improved version of Erlang. It isn’t here to be the next Java, but to solve out the problems that Java couldn’t do smoothly in over a decade (despite having such a great community).
Erlang is going from an underestimated to an overhyped language. I wish it can convert the hype and raw interest in Erlang into something meaningful. How about a modern variation of Erlang on the Erlang’s virtual machine. Is it too late?

To subscribe to the "Guy WhoSteals" feed, click here.
You can add yourself to the GuyWhoSteals fanpage on Facebook or follow GuyWhoSteals on Twitter.
Any feedback can go straight into Guy's mailbox:
  • guywhosteals AT gmail DOT com
  • guywhosteals AT yahoo DOT com
I found it surprising that many people that works with Java everyday doesn’t know that there are debugging options that go beyond clicking the “debug” button in your IDE.

You can just attach your IDE to a running application (which has been runned for debug as we’ll see later), or you can even debug it from command line. And the application you debug can even be be in a different machine.

The magic lies in where the debug information actually resides. Apparently people normally think that is the IDE that knows how to debug your programs, but the truth is that is the program who knows how to debug itself, and makes that information available to whoever wants to use it.

The way it works is basically the following. When you compile a program, the .class files get debug information within them, like line numbers or local variables that are made accessible to others who want to access this information. You can then run the program in debug mode passing the following options to your java program execution(you can of course run any java program like this, including mvn goals, appllication servers, etc)

-Xdebug -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y

(you can also use -agentlib:jdwp instead of -Xrunjdwp in latest Java versions)

This line basically says: Run this program in debug mode, use the jdwp protocol, with a socket that listens to port 4000 and waits for connections to continue.

The jdwp protocol is a communication protocol used by the Java application to receive and issue commands and reply to them.

For example, you can connect to this port when the application is running an issue commands like “print variablex” to know the value of a variable, “stop at x” to set a breakpoint, etc. The application issues notification commands like “breakpoint reached”.
The truth is that the protocol is a little more complex than this, but this is enough to know to illustriate the point.

With the previous said, we can see that it would be even possible to debug an application with the use of Telnet! (we'll see later)

Well, enough theory. Let’s see an example Any simple example will do. We’ll make a simple program that takes two parameters from command line and prints the sum. The program won’t be well designed (In the sense that will include some useless temp variables, no validations, etc) but will do to illustrate the example.

class Sum{     public static void main(String[] args){         int sum1 = Integer.parseInt(args[0]);         int sum2 = Integer.parseInt(args[1]);         int suma= sum1+sum2;         System.out.println("La suma es "+suma);     } }

So we compile it: javac -g Sum.java (the g option adds extra debug info to the class. Like local variable names)
And we run it in debug mode: 
java -Xdebug -agentlib:jdwp=transport=dt_socket,address=4000,server=y,suspend=y Sum 3 4

Now we have the application listening on port 4000 waiting for connections

We will use the jdb command line debugger that comes with java. But first let’s try this. Run the following (you must run the second line fast after the telnet session starts)

telnet localhost 4000
JDWP-Handshake

That is the handshake to initiate the communication. You now have a debugging session with Telnet !

Ok, that was only to show, you (or i) would have to know the details of the jdwp protocol to use it. Let’s use instead jdb to debug our application. execute the following:
jdb -attach 4000
you’ll get some output like
Initializing jdb ...
>
VM Started: No frames on the current call stack

main[1]

That’s it, you have a debug session started. Now the interesting. Execute the following in your jdb session:

stop at Sum:6 You now have a breakpoint on line 6. execute run on the session, and the program will run until that breakpoint. you’ll get the output

Breakpoint hit: "thread=main", Sum.main(), line=6 bci=18
6 System.out.println("La suma es "+suma);


Now let’s see the value of our variables: run the following commands (one at a time) on the jdb session and see the results.


print sum1
print sum2
print suma
locals
set suma = 10
locals
cont


This is pretty cool stuff. You can debug your program from command line.

Of course if you have the opportunity to use an IDE like Eclipse you should take the advantage of it and still applying what you’ve learnt. So let’s do this.

You need to have the source code of the running application open in your eclipse as a eclipse project for this
Go to the step when you ran the program in debug mode. and run it.

Now go to your eclipse, go to the menu and select RUN -> DEBUG CONFIGURATIONS

In the left panel go to Java Remote Applications, and click new there.

Then select your project, write 4000 in the Port field, and click debug:


That’s it. you have attached your eclipse to the debugging program, now you can put breakpoints, do variable watches, and evaluate expressions from Eclipse.

That’s it. i hope this small article has helped you to understand a little better how the debugging of an application works and how you can debug and application that runs somewhere else.

For more Java Core information you can consult the good official book.

To subscribe to the "Guy WhoSteals" feed, click here.
You can add yourself to the GuyWhoSteals fanpage on Facebook or follow GuyWhoSteals on Twitter.
A Transmission Electron Micrograph image of Deinococcus radiodurans, one of the world's toughest bacteria
Researchers at the Chinese University of Hong Kong have successfully shown how to store encrypted data in bacteria. A colony of E.coli was used for the experiment, with the equivalent of the United States Declaration of Independence stored in the DNA of eighteen bacterial cells. As 10 million cells are present in one gram of biological material, this would translate to a data storage capacity of 90GB.
Data can also be encrypted thanks to the natural process of site-specific genetic recombination. Information is scrambled by recombinase genes, the actions of which are controlled by a transcription factor.

The method has some flaws, however, as an expensive sequencer is needed to retrieve data, with the process described as tedious as well. What's more, toxic DNA usually found in stored sequences will mutate and remove the toxic sequences, taking some of the data with it.

Only copyright information can be stored in genetically engineered organisms thus far. Bacteria has the potential to be more resilient to keeping data storage than traditional, electronic means. Deinococcus radiodurans bacterium, for example, can withstand electromagnetic pulses and a radiation from a nuclear fallout. [via BluSci]

Check out the an anime project solely made through Free and Open Source software click here.
To subscribe to the "Guy WhoSteals" feed, click here.
You can add yourself to the GuyWhoSteals fanpage on Facebook or follow GuyWhoSteals on Twitter.



It's almost the end of the year, which means that the usual flood of "Top 10", "Year in review" and other backward-looking articles are here.  Retrospectives can be a lot of fun and even occaisionally insightful, but in my opinion they are looking in the wrong direction.  So, in the spirit of looking forward to a new year, here's my top 10 list.  Not things that happened in 2010, but things I want to learn in 2011.  Some of these I have already started using but want to master, others are mysterious new toys that have grabbed my attention if not my time.

10.  HTML5.  The importance of HTML5 cannot be overstated, IMHO.  With support for the Canvas object, video, geolocation, etc, etc, HTML5 is already changing the web in surprising and innovative ways.  The best part?  It's not a new language.  All the tags I know and love are still there.  There is still a lot to learn, but I don't have to start from scratch.  In some ways (like the doctype), HTML5 is even simpler than earlier versions, a refreshing reversal of the usual cruft of complexity that builds up on a language over time.

9.  GroovyGroovy is one of a slew of new(ish) languages that run on the venerable and performant Java Virtual Machine.  Groovy borrows heavily from Java's own syntax, flattening out the learning curve for developers that already know Java.  So, it runs on the JVM, and it looks a lot like Java.  What's the big deal with Groovy?  Well, proper closures, for one.  A great console, for another.  One of the things I LOVE about coding in Python is that if I want to play around with some code I can just start up a Python console and go to work.  Java's edit -> compile -> debug cycle seems positively crippling by comparison.  Add in the fact that apps written in Groovy can leverage Java's gigantic library of existing components and you have a language that I have to add to my toolbox this year.  Oh, and don't forget Grails.  I've built a couple simple apps with it and I think I'm in love.

8.  The ins and outs of cross-platform mobile development.  Compared to the whole of computing, mobile applications are still in their infancy.  Without getting into the growing pains this market is going through (Apple's walled garden, Verizon Android crapware, etc), there is one big challenge as a developer.  What platforms do you support?  What language(s) do you develop in?  Is it worth it to build both Android and iOS apps?  Do you even have the resources to do so?  Companies like Appcelerator aim to make this easier by creating cross-platform dev tools for popular mobile device platforms.  I want to make my apps available to as broad an audience as possible without the headache of maintaining several codebases.  This is a space to watch.

7.  A NoSQL database.  Most of the platforms I work with rely on relational databases.  They work.  MySQL / Oracle ( the two I work with most frequently) are mature, stable and perform well enough when properly tuned.  But, like any tool, RDBMSs aren't the right solution for every problem.  They can be expensive to scale quickly, and frankly I don't always need a well defined schema.  Sometimes I just need a persistent store for some simple objects.  Now that CouchDB is available as a client-side DB for Android, I can see quite a few interesting applications for this technology.  If iOS support comes through then we have another choice for cross-platform data stores.

6.  Arduino.  What the heck is an embedded processor doing on a top 10 list for a web / mobile developer?  Well, the Arduino is simply one of the coolest things I have ever seen.  It's open source.  It's cheap.  It's easy to program.  It's capable of surprising feats.  I have an Arduino Mega sitting on my desk just begging for the right project.  I had originally intended to use it as the brains behind an automated bottling line for my homebrew, but decided that kegging was much more practical :-).  Right now it is hooked up to a 2 line LCD display and a couple of blinkenlights, just waiting for inspiration to strike.

5.  GIMP.  This is one of those tools that I already use constantly but wish I had a better handle on.  The GIMP is a great image editor for the price (free), and I use it all the time for creating iPhone buttons, logos, splash screens, etc.  If you just need to slice and dice some PNGs for the web it is a great option.  In the next year I want to hone my design skills and GIMP-fu.

4.  TropoTropo is a telephony platform that runs in the cloud.  If you want to add SMS or voice functionality to a web application, Tropo takes all the guesswork out.  They build the infrastructure and provide the APIs, you build the cool stuff on top of it in your choice of Ruby, Python, JavaScript, PHP or Groovy or your language of choice by calling their REST API.  Oh, and did I mention that it is free for developers?

3.  Django.  This is another one of those tools that I have worked with occasionally but haven't ever really mastered.  In particular I want to use Django running on the Google App Engine to build some simple scalable web services.  I haven't ever implemented a REST API in Django, but need to learn.

2.  Alfresco.  I use Alfresco constantly.  It's a big part of my day job and I have even written / contributed to a few open-source components that exist in the Alfresco ecosystem.  However, it's a huge product.  It provides so much functionality that I feel like I only know / use 10% of what it is capable of.  Maybe with another year of hard work I can bump that to 20%.

1.  Time Management.  As evidenced by the list above, I have more ambitions than time.  To get all of this done I will need to focus on what is, in my opinion, the single most important tool that any developer or engineer can learn.  This is one of those critical life skills that almost everybody has room to improve.  If I only get one thing done next year, this should be it.

So that's my list.  10 things that I want to focus on in 2011.  What are yours?

Check out the an anime project solely made through Free and Open Source software click here.
To subscribe to the "Guy WhoSteals" feed, click here.
You can add yourself to the GuyWhoSteals fanpage on Facebook or follow GuyWhoSteals on Twitter.
When starting any project, a developer has to navigate a tree of choices. Which programming language do I choose? Which distribution? Which editor or IDE should I use with it? Which operating system should I target? Sometimes, the decision is easy since the environment is dictated by management: we’re a C# shop, so fire up VisualStudio on Windows and go. Or, we’re using Ruby 1.9, so pick your favorite code editor (TextMate, vim, Emacs, Eclipse) and you’re off, since you’re limited to pretty much one official Ruby distribution. Same with Python, or Perl — pick an editor and your favorite *nix OS (Windows support is more shaky for all these scripting languages), and you’re set. Sure, there are often experimental or alternate VMs and interpreters, but the mainstream production choice is clear.

Not so with Smalltalk. Much like with Lisp, a casual user first approaching the Smalltalk world is faced with a bewildering variety of Smalltalk versions. Which distribution and virtual machine (and therefore a slightly incompatible dialect and set of libraries) should you choose?

Fortunately, a little bit of research narrows down the choices considerably. Especially if you want to use the Seaside web development framework. Essentially, you’re faced with either Cincom’s VisualWorks Smalltalk (for a stable, powerful commercial distribution with corporate support), GemStone’s GLASS platform (Gemstone, Linux, Apache, Seaside, Smalltalk, which uses the incredible object-oriented Gemstone database for persistence), or the free open-source Squeak Smalltalk.

Let’s run down the choices that I made in starting this project.

Q: Which programming language? A: Smalltalk
I have worked with Smalltalk for over 9 years, both as my day job (writing desktop applications in Visual Smalltalk and Cincom’s VisualWorks), and as a hobby (exploring Squeak Smalltalk). Though I have also worked on commercial projects using Java, Perl, PHP, Python and Ruby/Rails, I have not found anything in those worlds resembling Smalltalk’s powerful IDE and ease of debugging. Though the other languages enjoy a wider base of developers, open source projects, and third-party library support, the experience of working with Smalltalk (and Seaside) is profound, freeing and satisfying.

Q: Which Smalltalk? A: Squeak
Although the GLASS platform intrigues me, I don’t have much experience with it. And, given a choice, I always prefer to work with open-source technology rather than commercial distributions, hence the choice of Squeak (which I feel has more long-term longevity and openness) over VisualWorks (even though that has better commercial support, I don’t want to deal with license fees at this stage in the project)

Q: But which Squeak? A: The Pharo Project fork
One slight complication is that the Squeak project forked in 2008. Although I’ve worked with “plain Squeak” for a number of years, the Pharo fork seemed like a reasonable choice, since it was chosen to be the reference implementation for the Seaside platform (perfect, exactly what I need it for).

The original reasons that I posted for choosing Pharo were:

a) removing unessential code from Squeak (Squeak, having started as a children’s education project, has accumulated a fair amount of cruft over the years),
b) clearer licensing (MIT license),
c) more frequent updates (think Ubuntu versus Debian), and
d) being a reference implementation for the Seaside platform (perfect, exactly what I need it for).

However, as this thread on Pharo-Project mailing list pointed out, most of them are incorrect. My apologies for misunderstanding — I got those reasons from the Pharo Wikipedia entry when I came across the Pharo fork, and was trying to figure out whether to switch or not.

Q: Which IDE? A: Squeak/Pharo
Unlike most programming languages, the code editor and IDE is often built into the distribution/VM (though the IDE code can be stripped out when getting a VM image ready for deployment). This may sound strange, but it buys you incredible debugging and refactoring powers. Like in Lisp, both the source code and the (on-the-fly) compiled methods and classes are first-class objects, so with a single keystroke, you can do things like “Show me a list of all the methods called from this method” or “Give me a list of all the other places in the code this function is called from” — something that has to be approximated with full-text searches in other IDEs and environments.

Q: Which operating system? A: Doesn’t matter, actually
Both Squeak/Pharo and VisualWorks are cross-platform, with the virtual machine and IDE working almost identically on Windows, Linux and MacOS X. Currently, I do development on Windows and Ubuntu Linux (depending on which machine I’m working on), and deploy to a web server running Linux.
I hope this sheds some light on this very individual set of decisions. One last thing I’d like to reiterate: If you’re new to Smalltalk and Seaside, you essentially can’t go wrong with the main 3 distributions (VisualWorks, GLASS or Pharo). All three are excellent cross-platform environments, and the choice between them comes down to commercial support, licensing fees (and, in the case of Gemstone, whether or not you need a first class object-oriented database).

Check out the an anime project solely made through Free and Open Source software click here.
To subscribe to the "Guy WhoSteals" feed, click here.
You can add yourself to the GuyWhoSteals fanpage on Facebook or follow GuyWhoSteals on Twitter.

Tutorial: Build a Portable Web Browser


Writing portable code has been a primary goal of programmers for many years. The idea that you can write your application once and use it almost everywhere appeals to a programmer’s sense of frugality, and avoids continually having to reinvent the wheel. Join us as we create a webkit-based browser on multiple platforms to prove just how easy it is.


Portability was the driving factor behind Java. In the words of the Java developers, it was designed to be as ‘architecture-neutral’ as possible. As a result, the Java language and its applications have gone on to change the face of computing, running on everything from mobile phones to NASA’s 3D reconstruction engines for the Mars Rover mission. But Java achieves this by using a virtual machine – a middle layer that translates the programmer’s instructions into machine-specific instructions on the fly. The advantage of this approach is that you only ever need to port the virtual machine to your platform, and you can immediately access your entire library of Java. The downside is that Java applications seldom feel like native applications, and there’s very little direct hardware control.



1. Find a toolkit

There’s nothing stopping you writing your portable applications using Python, Perl, Ruby or even C and C++. These languages are widespread, and you can find compilers for most platforms. But when your applications are of a certain size, portability becomes more than just a matter of finding a suitable compiler. It’s about being able use OS-specific components without writing OS-specific code. If your application has a main window, a toolbar and help system, for instance, you’d need a separate implementation for each platform. And that’s a lot of duplicated effort.

The answer to this problem is to use a portable programmer’s toolkit. This is typically an API – a series of pre-built functions and libraries – which can be compiled and used on any compatible platform. You program the main window, toolbar and help system code using the portable toolkit, and this can then be compiled on any other compatible platform with very little extra effort. Linux has several cross-platform toolkits, each with their own strengths and weaknesses. For example, the popular cross-platform instant messaging client, Pidgin, uses a toolkit called GTK+, which has been ported from Linux to Windows. One of the best cross-platform toolkits we’ve come across, however, is Qt.


2. The Linux Development Environment

Qt is the toolkit at the heart of the KDE desktop environment. It was developed by Trolltech before it was acquired by Nokia late last year. The great thing about Qt is that it’s both commercial and open-source. This means that it’s generally of a much higher quality than pure open-source solutions. It’s also packed full of features, and as long as you’ve got a little C++ experience, you’ll find it well documented and relatively easy to use. You could code a music player using just a handful of lines, for example. Thanks to its portability, you can recompile the same application on Windows, or even OS X, with very little extra effort.

Creating a Qt development environment on your Linux machine is straightforward. Most installations will include a working toolchain built around the GCU Compiler Collection (GCC). Type ‘make’ on the command line to see if it’s installed. If it isn't, simply find and install the GCC in your distro’s package manager. This will include everything you need to build C and C++ applications from your Linux desktop. Similarly, if you're using a recent distribution release, you’ll find development libraries for Qt 4 within your distro’s package manager. You will need to install these along with a tool called Qt Designer.

To check that everything is installed, type ‘qmake --version’ on the command line. You should see something similar to the following:

Using Qt version 4.4.3 in /usr/lib

This displays the version of Qt you’re using, as well as the location of the libraries. For our small project to work, you’ll need a version equal to or later than Qt 4.4.

Finally, we need to install one more piece of software. This is Qt Creator, a free Integrated Development Environment that makes creating graphical Qt applications considerably easier that typing lines of code by hand. The Linux version of Qt Creator is a large binary file that should be executed to install it into your home directory. Running the application is then as simple as navigating to that directory (‘qtcreator’), and running the qtcreator tool from the ‘bin’ directory. If you’re lucky, you may also find an icon for Qt Creator in your Development menu.


3. Create the GUI

With Qt Creator running, it’s now time to create our application. When Creator first starts, it begins by asking what kind of project you want to start. You need to select ‘Qt4 GUI Application’. This will populate Creator with a basic framework of code for a simple application. Clicking on the large green ‘Play’ button in the bottom left of the screen will compile the code and execute the application. You should see an empty window, which is where we’re going to dump some functionality.

Quit the application and go back to Creator. In the file list in the left panel, you’ll see five separate files. The first has a ‘.pro’ postfix – meaning project file – which is used by Creator to manage your project. The second file is ‘main.cpp’, the launch function for all C++ applications. Following this, there’s ‘mainwindow.cpp’ and ‘mainwindow.h’. These classes inherit the Qt classes within your project, and allow you to add your own functionality. Finally, there’s ‘mainwindow.ui’. This is an XML file that contains the various GUI elements within the application. Click on this file to open the GUI constructor within Creator.

We need three elements, all of which should be dragged from the widget palette in the left panel and onto the main window area in the middle of the screen. Add a ‘lineEdit’ widget, a ‘pushButton’ widget, and a ‘QwebView’. Double-click on the pushButton and change the text to something like ‘Go’. You can rearrange these widgets in the window. We’d recommend doing the following: hold down [CTRL] and select both the lineEdit and pushButton widgets, then select ‘Layout horizontally’ from the right-click Layout menu. Holding [CTRL] again, select this new grouped widget as well as webView, and click on 'Layout vertically’ in the same Layout menu. Finally, select the background window and click on ‘Layout in a grid’. All the widgets should now be adjusted into the scaling application window.



4. Write some code

The idea behind this application is that when the user clicks on pushButton, the web page pointed at in the lineEdit widget will be loaded into Qwebview. To add this functionality, we need to use what Qt calls a system of signals and slots. Clicking on the button will emit a signal, which will activate a slot in our main application to update the web site. But we first need to add the slot that will connect the two. Right-click on your application’s window background, and select ‘Change signals/slots’ from the context menu. A window will open listing all the signals and slots Qt pre-defines for the Window class of object. Click on the upper ‘plus’ symbol to add a new slot, and call this ‘updateWeb()’, before clicking on ‘OK’.

We now need to attach the clicked signal from the pushButton widget to the slot we’ve just created. Click on ‘Edit Signals/Slots’ from the Edit menu, then click on the button widgets and drag the cursor to the main window background and let go. That sets the source and destination. A new window will appear, from which you can select a signal on the button to attach to a slot in the application window. You need to select ‘clicked()’ for the signal, and our newly created ‘updateWeb()’ for the slot. Now the only thing left to do is add the actual code to perform the action. Click on the mainwindow.h header file, and add the following under the ‘~MainWindow();’ line:
private slots: void updateWeb();
Click on mainwindow.cpp, and add the following chunk of code to the bottom of the file:

void MainWindow::updateWeb(){QUrl url;url = ui->lineEdit->displayText();ui->webView->setUrl(url); }

Even if this is your first time using Qt, it’s easy to see what we’re doing here: when the button is clicked, we simply grab the text from the lineEdit widget, and use this as a new URL in webView. You can find out which signals, slots, classes and functions are supported by Qt’s widgets from the excellent documentation. Finally, save everything from the File menu and click on the ‘Run’ icon to build your application and make sure it displays web pages correctly.



5. Building on Windows

Before you quit Creator on Linux, click on ‘Clean Project’ from the Build menu. This will remove any system specific files for Linux. This is because we’re now going to build the same application for Microsoft Windows. First we need to create a working Qt development environment for Windows. Fortunately, Nokia/Trolltech provides Windows binaries of the Qt package which include the MiniGW compiler, pre-configured and ready to run. Ideally, you should try to get hold of the same version you were running on Linux. But if this isn’t possible, any later release should work. The installation can take a while, as the MiniGW compiler is downloaded as part of the installation process. MiniGW is a cut-down version of the GNU Compiler Collection we were using on our Linux system, and performs the same task – building an executable from the C++ source files of our project.

You will also need to add the locations of both the Qt and MiniGW installations to your Windows’ path variable. This can be done by opening the Control Panel, clicking on ‘System’ and selecting the Advanced tab. Click on the ‘Environmental variables’ button, select the ‘PATH’ variable in the top panel and click ‘Edit’. You will need to add the two locations, each separated by a semicolon. For example, we needed to add ‘;C:\Qt\4.4.3\bin;C:\MinGW\bin’. After that, you're ready to build your Qt application.

Open a command prompt and ‘cd’ to the directory that contains your Qt project. If you type ‘qmake -v’, you should see the same output we had on the Linux system. If not, then there’s likely a problem with your PATH variable. All being well, you now need to type ‘qmake -win32’ followed by the name of your ‘.pro’ file. This will regenerate the makefile, which itself contains the dependencies for the Windows system. The final step is now to type ‘make’, which will build your project using the contents of the makefile as a guide. A few moments later, you’ll find the Windows executable for your application tucked within the Debug directory. Congratulations - you’ve just created a cross-platform web browser!

This article originally appeared in Issue 280 of PC Plus.

Check out the an anime project solely made through Free and Open Source software click here.
To subscribe to the "Guy WhoSteals" feed, click here.
You can add yourself to the GuyWhoSteals fanpage on Facebook or follow GuyWhoSteals on Twitter.
Related Posts Plugin for WordPress, Blogger...
top
Share