"Hello, world" on steroids

Let's take a rest from the Kindle and let's write some code =). The next blog entry will be the third and last of the cycle committed to Amazon's reader.

Since I'm recovering from sickness and currently unemployed I've begun a course to get the MCDP, or Microsoft Professional Certified Developer certification. As with every course, the beginning is somewhat slow: we've had about a week of theory and only today we've begun to write some code. Inevitably, that code has been the venerable "Hello, world". Since I have some previous experience under my belt, as the teacher was explaining to the rest of the pupils the details about solutions, code and compilation on Visual Studio 2010, I was trying some things and exploring the Console object a bit further. And here are the results:

The program is really simple: a blinking "Hello, world". Let's see how we get that effect on the C# console.

 static void Main(string[] args)
 {
     Console.Title = "BLINK demo!";
     Blink("Hello, world");
 }
 

this is the main method: from it we call the Blink method, and we set the Title of the console window.

 /// <summary>
 /// Function for making the text sent blink
 /// </summary>
 /// <param name="text"></param>
 private static void Blink(string text)
 {
     int i = 1; //Determine iterations
     do
     {
         //If we're in an even iteration
         //text color is white
         //if odd, black 
         
         if(i%2 == 0) 
             Console.ForegroundColor = ConsoleColor.White;
         else 
             Console.ForegroundColor = ConsoleColor.Black;
         //Center the cursor horizontally
         Console.CursorLeft = 
             (Console.WindowWidth/2)-(text.Length/ 2);
         //Center the cursor vertically
         Console.CursorTop = 
             Console.WindowHeight/2;
         //Writes the text at the cursor's position
         Console.Write(text);
         i++;
         //A little delay to avoid blinking too fast
         Thread.Sleep(150);
         //reset i to avoid overflow
         if (i >= 100) i = 0;
     } while (!Console.KeyAvailable); 
     //Ends the loop if striking any key
 }

The i variable is simply needed to keep a count of the do loop iterations. Not because we're particularly interested in knowing how many iterations we're having, but because we need to alternate the console's fore color between black and white to make our text blink. Upon entering the loop the first thing to do is asking if i is even, with the operation i%2 that founds the remainder of a division by two and comparing that remainder with zero. If they're equals, which is to say there's no remainder, the number contained in i is even and we set white as the color for the console's text. Otherwise is odd and we set black as the text's color. Since the console's background color is black, when we set the text (or fore) color to the same black, we'll make the text "disappear", which is exactly the effect we're looking for.

Setting Console.CursorLeft and Console.CursorTop to those values we position the console's cursor where we want to write, in this case centered horizontally and vertically; since we already know the console0's dimension thanks to the Console.WindowWidth and Console.WindowHeight properties.

Then two tricks: we use Thread.Sleep(150) to stop running the main (and only, in this case) thread of our application for 150 milliseconds, making the blink noticiable. Then some rough error checking: if we let the loop running there'll be a time when, eventually, the value of i will be too great to be contained in an integer variable, so when it reaches a random value we reset it to zero. Not exactly any random value, but an even value, since the first iteration of the loop was with an odd value.

Last we examine the exit condition for the loop: while(!Console.KeyAvaliable). This condition will run the loop as long as there are no keys pressed in the input buffer; that is, the loop will run indefinitely until the user strikes any key.

And that's it. A really simple example to surprise your teacher the next time you have to make a "Hello, world" in C#.

Ok, all right, I admit it: this post is a simple excuse to test the code formatting in the blog. Sorry for this. :)

Kindle 101 (II)

Once we’re over the differences between prices and models, let’s start with more meaty matters with one of the most impressive points in favor of the Kindle as a reader: its ecosystem.

Ecosystem

kindle-front-graphiteWe understand as Kindle ecosystem all the sorrounding organization Amazon has arranged around, and serving,  its hardware reader, in order to make things easier for their customers.  Obviously Kindle is the focus of all this concerted effort in the ebook market. But now, when saying Kindle I might refer to the ecosystem instead of the concrete hardware reader.

And that’s because you can use Kindle without buying a Kindle: the software version of the hardware reader is avaliable for free for PC Windows, Mac; and in the respective markets for iPhone, Android, Blackberry  and Windows Phone 7 mobile OSs.

All this software applications were not designed to substitute the hardware reader (although they could very well do it), instead they’re meant to complement it. Thanks to  Whispernet and Whispersync, the circle closes and the ecosystem is complete.

Whispernet is the name given by Amazon to the 3G technology used in Kindles. For the user this means that a reader with Whispernet (that is, with 3G) can work just as soon as we get it out of the box, without needing a computer: we can search, buy and download books from the same device. Besides, we don’t need a Wi-Fi hotspot for this: 3G access is almost as ubiquitous as mobile network coverage.

But the true magic of the system is in Whispersync, Amazon’s technology for automatically synch our libraries, notes and reading marks between different devices. Wehn I buy a book on my Kindle I can download it also for any other hardware or software versions of the Kindle that are registered to my account at Amazon and, thanks to Whispersync, I can carry on reading it between different devices without a hassle. If I stop reading a book on my hardware Kindle say on page 35, I can carry on in that same page on the Kindle app in my iPhone, for example. 

As I’ve said earlier, all of this without needing to pay anything, without choosing any mobile carrier or configuring (almost) anything: simply install and go.

Getting books

This ecosystem and its ease of use is what gives Amazon a huge advantage over its competitors. Let’s see with a little more detail how’s the process of getting Amazon books or our own documents into the reader.

As we’ve said, we can browse Amazon’s Kindle book catalogue from the reader; either by seeing new books avaliable, Amazon suggestions based on our previous purchases (same as their site) or searching by key words. Once located the desired book, we can either download a sample or simply buying it. In both cases we’ll get it (the book or the sample) on our device in less than a minute, usually and we can start reading. If we’ve made our buy from a normal browser on a computer the system is the same, except we’ll logically have to conect the Kindle to the Whispernet to get all our pending downloads. Amazon charges automatically the credit or debit card we’ve got registered as a valid pay method on our account, and it’s able to identify us because we registered our Kindle after buying it, linking the hardware devide or software app to our Amazon account. From the Kindle we don’t need to enter any passwords or login anywhere.

But of course this is not the only option for getting books and documents on the Kindle. We can load it with our own documents, ebooks purchased at other online bookstores, or downloaded from the Gutenberg Project, web pages saved to read later; and yes, also books obtained from the shady side of things. Even though Amazon-bought ebooks have DRM and are in an exclusive Amazon format (AZW, in fact a MOBI with some internal structure changes), the reader is compatible with more formats with the exception of the EPUB format.

Getting those documents into our reader is really easy: simply connect your reader to a computer via USB and pass along the files as with an external hard drive, no need of crappy iTunes, synching or any other hassle. We can also have Amazon sent it to us by mail to the reader’s account. Here there’s a help page detailing all the options avaliable.

And we can also use Calibre. It’s a free (as in beer) software application written by Kovid Goyal which deserves an entry on itself. Suffice to say for now that, among many other things, Calibre allows us to organise our local computer library, convert bvetween different ebook formats and copy books to and from our reader. It comes with Kindle native support and works like a charm. If you get books from the Internet you’ll find the ePUB format a lot, and Kindle can’t read that format. You get the EPUB book into your Calibre library, convert it to MOBI, pass it to your Kindle and you’re ready to go. Of course, you have to take into account that all the advantages mentioned before about syncing and having the book avaliable between different devices and apps are only for books bought in Amazon, they’re not avaliable for documents obtained otherwise.

Kindle 101 (I)

Kindle DXFor some months now I’m the happy owner of a Kindle DX. Although my first reader was a Grammata Papyre, I decided to try out a Kindle 2 and since then my test and trial days with readers are over: I was in love. 

I’m aware, however, that this is a reader seemingly complicated to the Spanish market: it can only be bought online at Amazon, no spanish support, and no native support for one of the most extended ebook formats, EPUB. But I believe it’d be a mistake to let this easily overcomable difficulties to stop you from considering a Kindle, because I believe it is, right now and for many motives, to be the best reader avaliable in the market.

In this post and in some future ones I want to help the potential Kindle buyer, speaking about the different versions, buying options, day to day and care, where and how to get books for the Kindle, software and hardware complements, and so on.

Models and prices

Right now there are two Kindle models to choose from: Kindle and Kindle DX. The main difference between them is their size: Kindle has a 6 inches display while DX is 9.7 inches. Prices for both devices depend on the exact purchasing option we choose, as of this table:

Model Wi-Fi 3G Ads Price
Kindle DX No Yes No $379
Kindle 3 Yes Yes No $189
Kindle 3 Yes No No $139
Kindle 3 Yes No Yes $114

First choice: Kindle DX or Kindle 3? It all depends on the use you’re planning for your device: if you’re going to read books where text is predominant (novels, essays, self-help books, and so on) you’re good to go with a Kindle 3. But if you intend to read books with a lot of graphics, tables where the layout is important, you need a DX. DX’s 9.7’’ display is perfect for reading PDFs without having to redistribute a PDG page in several reader screens, without zooming and without hassle: each screen of your reader is a full PDF page, and easily read. Besides, even being bigger is not much heavier than the Kindle 3, and you can grab it and read easily with just the one hand.

If we choose a Kindle 3, we’ve got three more options: WiFi + 3G, just WiFi and just WiFi with ads, or Special Offers as Amazon calls them, the most recent and cheaper option. Once again, knowing beforehand our intented use of the reader makes the choice easier: the main differential factor here is 3G. We use a 3G connection on the Kindle mainly to browse Amazon’s Kindle store on the go: from the device itself we can browse, buy and download books in seconds, and we can browse the web with certain limitations. 

(Let me be clear from the start: Amazon, unlike other companies, offers the 3G connection to the Kindle completely for free, one of the factors that make this option even more attractive, not only because of the savings but also because of the comfort it provides: you don’t have to choose a providing company, select a data plan or configure anything; you just fire up your Kindle, connect to the Web and you’re ready to go. Browsing and buying books from the bus, or in a park, at a whim is a real pleasure.)

So, if we want to be able to browse the Internet on the go we need the 3G; if not with the WiFi option it’ll be enough. Lastly, ads or no ads?

The Special Offers model is Amazon’s more recent idea to make their reader even more universal and accesible: at 76€ on exchange, I believe it is right now the cheapest ebook reader in the market by far. Every Kindle has a screensaver feature automatically activated when the reader is idle for an amount of time. Normal Kindle readers display images related to literature on their screensavers, authors and the like. Kindles with ads display, well, ads. In fact, the ads only show themselves when you’re not really using your Kindle, either on full screen mode when the reader is on screensaver, or on a bottom bar when we are on the Home screen, similar to the ads on smartphone apps. Unlike them, though, the ads are never shown when we are actually reading a book. This tasteful and undisruptive use of ads make it a very attractive option.