Ph: 9781430236658

SublimeText2 Plugin: RunBuild

Jan 16 2012

I was talking to my coworker, Todd Anderson, today about running build systems in Sublime Text 2. It’s a great editor, very powerful and configurable. But somewhat of a lack of documentation on all those features. One problem we both had was setting up multiple build systems on a project, say one for running unit tests, one for running JSLint, one for deployment, etc. You can specify build systems right in a project file as per this reference: http://www.sublimetext.com/docs/2/projects.html. For a drop dead simple example, you could have one that launches your index.html file in chrome, and another that launches your unit tests in tests.html. This would look something like this:

"build_systems":
[
    {
        "name": "preview",
        "cmd": ["/usr/bin/google-chrome", "$project_path/index.html"]
    },
    {
        "name": "test",
        "cmd": ["/usr/bin/google-chrome", "$project_path/tests.html"]
        }
]

Now, in your “Tools/Build System” menu you should have two entries: preview and build. You can choose one, and the next time you build it will do what you specified in that system. The problem is switching between them. Grab the mouse and go to Menu / Tools / Build System / test (or preview). Then, F7 or Ctrl-B to build. Or maybe you forgot which one you were on, so when you build it builds the wrong thing and you have to cancel and go back and check and redo it. Minor pain, but it gets annoying.

Ideally, you could assign a specific keyboard command to each build system. So I started digging in to see how to do this.

First Part of the Solution: set_build_system

After some digging around, I found that there’s an internal command called “set_build_system”. You pass it a single argument called “file”. The value is one of two things:

1. The path to a sublime-build file, such as “Packages/Java/Ant.sublime-build”

or

2. The name of a custom build path in your project file (like what we just created as “test” and “preview”.

You can use this command in a keyboard shortcut. Go to the Preferences menu, Key Bindings – User. This will open up a Default sublime-keymap file, which should contain an empty JSON array like this: [], unless you have already added some shortcuts. You can create shortcuts that will change your build system like so:

[
    { "keys": ["ctrl+shift+p"], "command": "set_build_system", "args": { "file": "preview"} },
    { "keys": ["ctrl+shift+t"], "command": "set_build_system", "args": { "file": "test"} }
]

With this, Control-Shift-P will set your build system to your custom preview build system, and test likewise. But it’s still a two step process: set the system, then build. And again, there’s no visual indication of which system is currently set, and no visual indication of when it changes, so you’ll still find yourself checking manually in the menu to see which is checked.

Ideal scene again, would be one shortcut that chooses the system and then builds.

Second Part of the Solution: plugins

A keyboard shortcut can only run a single command. But we need to run two commands: choose the build system and then build. To do this, you can create a sublime text 2 plugin. This is far easier than it sounds. In fact, Todd and I were both pretty shocked at how easy it turned out to be and how quickly we got it working.

A plugin is a Python class that creates a custom command. It extends one of three plugin classes: WindowCommand, TextCommand, or ApplicationCommand. This post was very helpful in getting me started:

http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/

Here’s the command that Todd and I came up with virtually at the same time:

import sublime, sublime_plugin  

class RunBuildCommand(sublime_plugin.WindowCommand):
    def run(self, build_system):
        self.window.run_command( "set_build_system", {"file": build_system } )
        self.window.run_command( "build" )

Running through it, this imports a couple of sublime packages, defines a class that extends WindowCommand, and a single method called run.

The run method takes a single parameter (besides “self” that all python methods get) which will be the name of the build system to run.

It then does the two things we need to do by making calls to self.window.run_command, passing in the command to run and any arguments.

First we call “set_build_system” like we did in the first keymap example. This passes through the build_system argument.

Then we call build, with no args.

So we’ve accomplished our two actions in a single stroke: set the build system, then build.

You can save this file as “RunBuild.py” anywhere in your Packages folder in Sublime’s config folder (check documentation to see where that is on your OS). I suggest you give it its own folder so it becomes /Packages/RunBuild/RunBuild.py.

Now we just need to change the keymap to call this custom command instead of set_build_system. The name of the class, RunBuildCommand, will be mapped to a command called “run_build”. CamelCase becomes camel_case in this setup. So we do this:

[
    { "keys": ["ctrl+shift+p"], "command": "run_build", "args": { "build_system": "preview" } },
    { "keys": ["ctrl+shift+t"], "command": "run_build", "args": { "build_system": "test" } }
]

And we are done! Control-Shift-P launches index.html in the browser, and Control-Shift-T launches test.html. Of course, your build system(s) could be far more complex than the simple one I showed here, there you go.

Join me on the New Digg

2 responses so far

CSS Roadblock

Jan 16 2012

Generally I like to use my blog for dispensing knowledge, advice, opinions, thoughts, musings, and of course, FACTS. But occasionally I get stuck on a point and all my research leads me to a dead end, and I’ll write a post that asks for help. I figure the answers just might help someone else down the line anyway, so it’s not purely selfish.

OK, so I’ve learned to stop worrying and love JavaScript. HTML I can tolerate. But CSS is gonna kick my ass.

Here’s what I want:

Two divs, floated side by side, varying amounts of text in them, but that text needs to be bottom aligned. Here’s what I came up with after a few Google searches:

<style type="text/css">
        .header {
                position: relative;
                float: left;
                width: 200px;
                margin: 10px;
                height: 100px;
                background-color: #ffcccc;
        }
        .header-content {
                position: absolute;
                bottom: 0;
                left: 0;
                width: 100%;
        }
</style>
<div class="header">
        <div class="header-content">Some content that will wrap lorem ipsum and all that crap just to make a long lon long div</div>
</div>
<div class="header">
        <div class="header-content">other stuff</div>
</div>

And here’s what it looks like:

But I have one more need. I’m hard coding the height of the header class to be 100px. I want it to be the exact height of the tallest content. So that it looks like this:

The thing is, that because the header-content div is absolute positioned, then the header div’s height will be 0 unless explicitly set. So the bottom of header is the same as the top of header and header-content goes off the top of the page.

The only way I’ve managed to do this is via JavaScript something like this:

var contents = document.getElementsByClassName( "header-content" );
var h = 0;
for( var i = 0; i < contents.length; i++ ) {
        var content = contents[ i ];
        h = Math.max( h, content.offsetHeight );
}
var headers = document.getElementsByClassName( "header" );
for( var i = 0; i < headers.length; i++ ) {
        var header = headers[ i ];
        header.style.height = h + "px";
}

This loops through the header-content divs, finding the tallest one. Then with that value, sets the height of both header divs. Works just fine.

In Flash, I'd have no problem using code for layout. But I'd love to know if there is some pure CSS way to accomplish this.

Join me on the New Digg

19 responses so far

JavaScript Code Reuse: Object.create

Jan 14 2012

FACT: After my post of a few days ago, I’m going to try to avoid beginning blog posts with the word “FACT”. I think labeling something as an ALL-CAPS FACT is just taunting someone to come along and dispute whatever you say. But anyway, I’ve already done it again.

OK, in the aforementioned post, I said that there were other, possibly … “better” ways of reusing code in JavaScript than by emulating classes. Take that “better” with a grain of salt. There are other ways, and some consider them better.

Prototypes

JavaScript is a prototype-based language. This means (as you can read for yourself in the link) that it creates new objects by cloning existing objects. The object you are cloning serves as the prototype of the new object. For now, just use the English language definition of prototype: “the original or model on which something is based or formed.” You have an object and you make a copy of it. It has all the properties and methods as the old one, and you can add new properties and methods to it. That’s how you get code reuse.

Now, a poor way to implement this would be to actually clone the existing object, copying over all its properties and methods to some new empty object. In that case, you’d wind up duplicating many of these properties on every single object, which could wind up in excess memory usage. So what JavaScript does is let you create a new object and link to the old original with an internal prototype property. This is NOT the public prototype property that you see on functions. This is an internal property that is not publicly accessible and is referred to in the spec as [Prototype]. Thus, if you try to access a property on a copied object, it will first look on the object itself, and if it does not find the property there, it will look on the object’s [Prototype]. If it’s not there, it will look on that object’s [Prototype] and so on up the chain until it reaches the top of the line, Object. If nothing on the chain has that property, it’s undefined for that object.

If that were the whole story, there wouldn’t be too much controversy on the subject. We’d create objects and create new objects based on them, and everyone would be happy. In fact, the Io Language, another prototype-based language, implements this very cleanly, and is a really fun language to program in. In it, you create a new object by cloning the base object, Object:

person := Object clone

You assign properties to the new object:

person name := "keith"

And then you can clone that object:

evilTwin := person clone
evilTwin attitude := "bad"

The problem with JavaScript is twofold: It originally offered no simple, native way of cloning object like Io’s clone method, and it introduced the new operator and constructor functions. When I say “problem”, I mean problem in a sense that it detracted from and wound up confusing JavaScript’s prototype-based nature, in an attempt to make it look “kind of” like a class-based language.

No access to [Prototype]

Because JS’s internal [Prototype] property is not accessible, it was initially hard to create prototype-based clones. Some browsers have provided a __proto__ property which exposes [Prototype]. If this exists, you can achieve prototypical inheritance almost as simply as in Io, like so:

var person = { name: "keith" };
var evilTwin = { attitude: "bad" };
evilTwin.__proto__ = person;
console.log( evilTwin.name ); // keith

You could make a clone function like so:

function clone( parent ) {
    var obj = {};
    obj.__proto__ = parent;
    return obj;
}

var person = { name: "keith" };
var evilTwin = clone( person );
console.log( evilTwin.name ); // keith

This will actually work if your browser supports the __proto__ property. Unfortunately, __proto__ is not a standard property and is not implemented in every browser. So that’s out.

The new operator and constructor functions

Instead of giving us a way to clone objects, JavaScript instead gave us the new operator and constructor functions. You know this already. It’s like this:

function Person() {
    this.name = "keith";
}

var me = new Person();
console.log( me.name ); // keith

What actually happens when you use the new operator with a function? A few very interesting things.

First it creates a new object and runs the function using that object as “this”. Any assignments to this in the function get assigned to the newly created object.

Next, it looks at that function’s prototype property. This is the publicly accessible property that is called prototype, not the hidden [Prototype] or __proto__. All functions have this property. Whatever that property is, it is assigned as the new object’s [Prototype]. This allows us to put properties and methods on the function’s prototype that will become part of the objects’s [Prototype].

Finally, it returns that object. So now you can do something like this:

function Person() {
    this.name = "keith";
}
Person.prototype.sayHello = function() {
    console.log( "hello" );
}

var me = new Person();
me.sayHello(); // hello

None of this is new to you. The point is that there is no real magic going on here. We could duplicate this functionality as long as we have access to __proto__:

function Person() {
    this.name = "keith";
}
Person.prototype.sayHello = function() {
    console.log( "hello" );
};

var me = {};
Person.call( me );
me.__proto__ = Person.prototype;
me.sayHello(); // hello

Again, we’re creating an object, calling the constructor using that object as this, which we can accomplish with call (or apply). You could even pass arguments to that constructor:

function Person( message ) {
    this.name = "keith";
    this.message = message;
}
Person.prototype.sayHello = function() {
    console.log( this.message );
};

var me = {};
Person.call( me, "yo, sup?" );
me.__proto__ = Person.prototype;
me.sayHello();

You could even create a function to make objects based on a constructor:

function Person( message ) {
    this.name = "keith";
    this.message = message;
}
Person.prototype.sayHello = function() {
    console.log( this.message );
};

function create( constr ) {
    var obj = {};
    var args = Array.prototype.slice.call( arguments, 1 );
    constr.apply( obj, args );
    obj.__proto__ = constr.prototype;
    return obj;
}

var me = create( Person, "awww yeah" );
me.sayHello();

Now, I’m not saying you should do this. In fact, I’ll reiterate that you absolutely shouldn’t. But it’s a fun exercise to see exactly what’s going on under the hood of new, and to fully understand that new is just sugar coating on top of JavaScript’s underlying prototype-based nature.

new and inheritance

The problem with this class-lookalike new operator becomes apparent when you start having one “class” inherit from another. The generally accepted solution is to create a new instance of the super “class” and assign it to the prototype of the new “class”.

function Person( message ) {
    this.name = "keith";
    this.message = message;
}
Person.prototype.sayHello = function() {
    console.log( this.message );
};

function EvilTwin() {
}
EvilTwin.prototype = new Person( "muahahaha" );
EvilTwin.prototype.doBadStuff = function() {
    console.log( "bad stuff is done" );
};

var twin = new EvilTwin();
twin.sayHello();
twin.doBadStuff();

This works fine, seemingly. The new object has the properties and methods from both “classes”. But various problems start to creep in. For one, notice that in what I’ve set up, there is no way to pass a message that will be used in the sayHello method when you are creating a new EvilTwin. In other words, there’s no automatic way of calling the super constructor. Also, if I overwrite a method, there is no way to call the super method. Various other problems arise based on the fact that constructor functions are not really classes at all, but some sleight of hand used to create prototype-based objects, as we’ve seen. Sure, people have gone about creating long complicated fixes for these issues that make JS look more and more like a class based language, but at what cost? I recently looked at one pseudo class library that was something like 1200 lines of code. All this complexity added no end user functionality whatsoever, only a way to make the programmer feel like he or she is using classes.

Object.create to the rescue!

As I’ve said, JavaScript has wound up with a confused identity due to it being a prototype-based language that had no way to create clones of existing objects (the core concept of prototype-based languages) and instead gave us a new operator to use with constructor functions to make it look more like a class-based language.

Fortunately, that is changing. ECMAScript 5 defines something called Object.create. This is essentially the clone method we created earlier. You pass it an object and it passes you back a new object that has the original one as its [Prototype].

var person = { name: "keith" };
var me = Object.create( person );

var evilTwin = Object.create( me );
evilTwin.attitude = "bad";

console.log( me.name ); // keith
console.log( me.attitude ); // undefined
console.log( evilTwin.name ); // keith
console.log( evilTwin.attitude ); //  bad

This is pure prototypal inheritance. Just like Io. Objects inheriting from other objects.

The good news is that many browsers already implement Object.create, so chances are you should be able to run that example right now. The other good news is that it’s easy to shim for those browsers that don’t have it:

if( typeof Object.create !== "function" ) {
    Object.create = function( obj ) {
        function F() {}
        F.prototype = obj;
        return new F();
    }
};

Since we cannot assign anything to an object’s [Prototype] (without __proto__), the only way of getting something in there is to assign it to a function’s prototype and then creating an object using new with that function. A bit of kludge, but it works, and with the above solution, you’ll get the native implementation if it exists.

Extending objects

Actually, the native version of Object.create is supposed to take an optional second parameter that is another object. All the properties on that object are copied over onto the new object. In the native version, this will be done with some new ECMA5 methods that deal with property attributes. So this can’t be exactly faked with environments that don’t have that. But you can create a method that extends an object by looping through another object and copying it’s properties. In fact, plenty of frameworks already have just such a function. But here’s a bare bones version:

function extend( obj, props ) {
    for( var prop in props ) {
        obj[ prop ] = props[ prop ];
    }
}

We can now redo our last example like so:

var person = { name: "keith" };
var me = Object.create( person );
var evilTwin = Object.create( me );
extend( evilTwin, { attitude: "evil" } );

console.log( me.name ); // keith
console.log( me.attitude ); // undefined
console.log( evilTwin.name ); // keith
console.log( evilTwin.attitude ); //  evil

Of course, for such a simple example, the extend function seems a waste, but if you were extending an object by adding some significant functionality, it would make it worth it.

Summary

I believe that going back to Object.create and treating JavaScript as the prototype-based language that it is will be a good thing. That’s 100% opinion. Not FACT. At any rate, it’s something that you should know about. I highly suggest you download the Io language and take a spin with it. In addition to the online documentation, there’s a chapter on Io in Seven Languages in Seven Weeks, which gives you a great intro to the language. Learning prototyped-base programming on a language you have no other experience with, and that implements it purely like Io is a great way learn the prototype way of doing things.

As always, don’t get serious about it. Learn some new stuff and have fun.

Further reading and Acknowledgments

I’d like to say I thought all this up myself, but of course it’s the distillation of lots of other stuff I’ve read over the past year.

http://javascript.crockford.com/prototypal.html

http://yuiblog.com/crockford/

[ http://rcm.amazon.com/e/cm?lt1=_blank
(Chapters 7 & 8 in particular)

And last but not least…

If you disagree with anything I say here, in the words of The Dude…

Join me on the New Digg

16 responses so far

Backbone, Underscore, and Require

Jan 14 2012

As interesting as this problem was to solve, it seems I could have solved it easier by grabbing the latest version of underscore, which does indeed define _ on global even when loaded via Require.js. Anyway, I learned a lot in the process!

I’ve been enjoying working with Backbone.js in the past month or two, and now I’m getting into Require.js to better organize my projects. I ran into a killer problem that I know others have encountered, as there are plenty of fixes and workarounds for it around the web. But I’ll add mine to the mix, as I think it’s pretty simple and elegant, if I do say so myself.

The problem comes from the fact that Backbone relies on the Underscore library. In particular, in the current version (0.5.3) it expects that when Backbone is loaded, the _ identifier is defined in the global scope. If it is not, it calls require(‘underscore’) to load it and assigns _ to global. You can see this in the following snippet in the backbone.js file at http://documentcloud.github.com/backbone/backbone.js

  // Require Underscore, if we're on the server, and it's not already present.
  var _ = root._;
  if (!_ && (typeof require !== 'undefined')) _ = require('underscore')._;

There are two problems here.

First is that if you load Underscore with require.js, it does not automatically create a _ variable in the global scope. Furthermore, because Underscore is not coded to be a require.js module, it does not return a reference to itself in the require callback. I’ll explain more in a second.

The next problem is that this is written for require on the server side, with node.js is synchronous, and require(‘underscore’)._ returns a reference to the Underscore library immediately, so it can be assigned to root._. But on the client side, require is asynchronous, and this will result in root._ being undefined, and you’ll get a failure with an error message about not being able to call the extend method of undefined.

So, the first thing we need to do is to load the Underscore library with require, prior to loading the Backbone library. This might look something like this:

require(
        [
                "app",
                "order!underscore-min",
                "order!backbone-min"
        ], 

        function( app ){
                app.init();
        }
);

You might put this in a main.js file that is referenced in your data-main attribute where you load require.js. First we require our main app module which will contain our app logic, then underscore and backbone. Also note that I’ve added the order.js require plugin which forces underscore and backbone to load in the order they are called. For simplicity’s sake, I’m assuming that all the files are in the same folder so we don’t have to worry about paths. When all are loaded, the callback will fire and we can initialize our app. This is the first round try that I made, which gave me the error.

So again, the first problem is that when you load Underscore, it does not assign _ to global, which Backbone expects. The second problem is that it is not coded as a require.js module so if you were to do something like this:

require(
        [
                "order!underscore-min"
        ], 

        function( underscore ){
                window._ = underscore;
        }
);

it would still not work. A module meant for require.js would return a reference to itself in that callback and we could assign it to global like that.

We need one more step, and that is to require Underscore again, after it’s loaded. This time we do not call require with the file name, but the module name, simply “underscore”. Since it’s already loaded, the callback will give us a reference to the library this time and we can assign it to window._.

This much is already known by many, but some of the solutions I’ve seen tend toward the overcomplex. I’ve worked on a few solutions myself, which also got pretty crazy. But I finally settled on something that is quite simple, and IMHO, pretty elegant. We create a new js file called underscore_fix.js, which looks like this:

require(
        [
                "underscore"
        ],

        function( _ ) {
                window._ = _;
        }
);

This gets called after we require Underscore by its file name, “underscore-min”, so it is loaded. Again, now that it’s loaded, requiring it by its module name will return a reference to the module itself. This we can assign to window._ and THEN we can load Backbone, which will work fine. The final main.js file looks like so:

require(
        [
                "app",
                "order!underscore-min",
                "order!underscore_fix",
                "order!backbone-min"
        ], 

        function( app ){
                app.init();
        }
);

Simplest fix I’ve come across. Apparently, there is a version of Backbone in the works that addresses this problem internally. So hopefully, this post will become obsolete before too long. Any better solutions out there in the meantime? I’d love to hear them.

Join me on the New Digg

3 responses so far

JavaScript Classes

Jan 11 2012

Facts.

Fact: JavaScript is an object oriented language.

Fact: JavaScript does not have classes.

Fact: JavaScript is dynamic and expressive enough to create structures that emulate classes.

Beyond those three facts, everything else here will be theory or opinion.

Expansion of facts:

JavaScript is an object oriented language but it does not have classes. Some people see these two statements as conflicting, but object oriented does not necessarily equal classes. Classes are only one paradigm used in object oriented systems, one of the more common ones, yes, but not the only one. Object oriented merely means that you have objects which contain both data and behavior – or properties and methods if you like.

You can create structures in JavaScript that emulate classes. Yes, but should you? That’s today’s topic.

First of all, why do people try to create class-like structures in JavaScript? I think mainly because they are coming from some other class-based language and that’s what they are used to. It makes them feel at home and transforms JS into something they think they can understand better. But there are many drawbacks to such an approach. Read a couple of in-depth articles or books on the subject. It starts out simple. You create a constructor function and add methods to the prototype. No real problem there. But then you want to implement inheritance and things begin to get tricky. Every fix has various drawbacks which have more fixes. The code ends up being quite complex, especially when you think that the main benefit is to make the programmer more comfortable with the language by making it seem like another language. Complexity has various potential side effects, including code brittleness, learning curve, file size, performance, and memory use, to name a few.

But beyond the idea of programmer comfort, there are some valid problems that people are trying to solve using classes. In most languages, classes offer 3 main benefits:

1. Code re-use via inheritance.

2. Information hiding / encapsulation.

3. Data typing and polymorphism.

These are all very fine things to strive for in programming anything. Let’s look at how they apply.

1. Code re-use.

This means you’re not typing the same code more than once. The DRY principle. Say you have a sprite system where each sprite has an image it draws to a canvas in a draw method:

function render() {
    this.canvas.draw( this.image, this.x, this.y );
}

And you have a player object that has certain behavior and an enemy object that has certain behavior, but both need to render to the canvas. It would be a poor decision for each of them to have a duplicate render function. You would somehow want to define that function once and have both of them share it. Then, if you ever needed to change it, you’d only need to change it once, they’d never get out of sync, you wouldn’t find errors creep into one, but not another, etc. And futures sprite types could also share the same render method.

In a class based system, you’d have a base class where any common code would live. Say a sprite class, with the render method. Then both player and enemy could inherit from sprite and both get the single render method. This is what everyone is taught in week one of most computer courses that venture into OOP. But remember, the problem we are trying to solve is code re-use. Class-based inheritance is not the only way, or even necessarily the best way to reuse code. In fact, another key principle often espoused in software design is “favor composition over inheritance”.

2. Information hiding and encapsulation.

This is all about setting up a public interface or api for an object that other objects can use, and having an internal implementation that other objects cannot (or should not) use. This means that you should be able to change the internal implementation without breaking any code that is using the public facing api. In class base languages, this is usually done with access modifiers such as public, private, protected, etc. Some languages have additional modifiers such as internal, friend, etc. and the actual rights that these modifiers bestow or block can vary slightly from language to language.

JavaScript does not have any native access modifiers, but there are ways of using closures to create functions and properties that are only accessible by methods of an object and not by outside code, thus accomplishing information and encapsulation. Interestingly, though, many pseudo-class systems in JavaScript do not even attempt to implement privacy, whereas other non-class based systems, such as modules, do this as a matter of course.

3. Data typing and polymorphism.

This says that if I create a class called Dog in a strictly typed system, I can make a variable that only accepts instances of the Dog class. And I can make a function that only accepts an argument of the Dog class. Furthermore, I can make a class called Animal and classes Dog and Cat that extend Animal. Now I can have a variable or method parameter that states it only accepts Animal objects, to which I can pass either Dogs or Cats.

Since JavaScript is not a strictly typed language, this concept is almost completely useless. I cannot specify what type my variables should be, nor can I state what kind of object a method parameter can accept. Yes, I could code all my methods with checks to typeof or instanceof and throw runtime errors if the wrong type was passed, but … nah.

Summary.

So, what it comes down to in most cases of people creating these complex class emulation systems, is code reuse. A valid concern, but not one that I am convinced has pseudo-class-based inheritance as its best answer. In future posts, I’ll cover some of the different ways to accomplish code re-use as well as encapsulation in JavaScript.

Join me on the New Digg

25 responses so far

Foundation HTML5 Animation with JavaScript

Dec 31 2011

[image]

I’m very happy to announce the release of this book, and need to say a few things about it.

First, this is a direct JavaScript port of my previous books, Foundation ActionScript Animation: Making Things Move!, and Foundation ActionScript 3.0 Animation: Making Things Move!. Chapter by chapter, they cover the same material, but teach you how to do the same things in JavaScript, mostly with canvas.

Second, I cannot take full responsibility for this book. Beyond the fact that my books served as the foundation for this book, I did no work on the actual writing of this book and had very little if any input on the book. I didn’t actually see the final manuscript until it was complete. I say this not as a complaint, or in any attempt to cover my own butt, or any kind of warning about the book’s quality (see point #3), but merely as a statement of fact. I gave consent to the project and sat back and let it happen, hands-off.

Third, when I finally did see the manuscript, I was very much blown away by what Billy Lamberta had done. Major respect to work through all the chapters of that book, converting it all into another language, while still staying true to the original form and intent. I can’t say enough how impressed I am at the job he did. Thank you.

Fourth, I’m also stoked to see that Apress released a Kindle version of the book at the same time as the print edition. Also, if you don’t want the Kindle format, you can buy direct from Apress: http://www.apress.com/9781430236658 and get the PDF, mobi, and ePub versions all for one price. I’m really happy to see Apress, O’Reilly and PragProg all doing deals like that on ebooks, as I’m trying to steer clear of any and all hard copy books and go all digital these days.

Join me on the New Digg

5 responses so far

The year they called “2011″

Dec 30 2011

I end this year feeling more excited about technology and programming than I have in several years. That’s really good because for most of last year and into the middle of this year I was going through a bit of a geek crisis. Nothing really seemed to excite me as a programmer. I ended the year doing Windows Phone 7 development, which is a great development platform, but unfortunately almost nobody has the devices. I was tired of iPhone development and nothing in Flash was exciting me.

Here’s kind of how my year went:

Continue Reading »

Join me on the New Digg

5 responses so far

Making Tools Presentation at Flash and the City

Dec 01 2011

In case you didn’t get to see my Making Tools presentation this year (or if you tried to see it at RIA Unleashed and suffered through my technical difficulties), you can now see it on line:

http://techchannel.att.com/play-video.cfm/2011/12/1/Conference-TV-Flash-and-the-City-Making-Tools

You can hear the guy who corrected me by pointing out that apparently crows use tools to make tools at 4:00. :)

Join me on the New Digg

One response so far

JavaScript Drag and Drop DOM Elements

Nov 16 2011

File this under “really writing this for myself so I can refer back to it later.”

window.onload = function() {
    var foo,
        offsetX,
        offsetY;

    // so it exists
    foo = document.createElement("div");
    document.body.appendChild(foo);

    // so we can see it:
    foo.style.width = "100px";
    foo.style.height = "100px";
    foo.style.backgroundColor = "blue";

    // so we can move it where we want:
    foo.style.position = "absolute";

    // so it looks like something we should click on
    foo.style.cursor = "pointer";

    foo.onmousedown = function(event) {
        // where is the mouse in relation to the div?
        offsetX = event.clientX - parseInt(foo.style.left || 0);
        offsetY = event.clientY - parseInt(foo.style.top || 0);

        // add listeners
        document.onmousemove = onMouseMove;
        document.onmouseup = onMouseUp;

        // prevent event propagation
        event.preventDefault();
        return false;
    }

    function onMouseMove(event) {
        // move the div in relation to the mouse
        foo.style.left = event.clientX - offsetX;
        foo.style.top = event.clientY - offsetY;
    }

    function onMouseUp(event) {
        // remove listeners
        document.onmousemove = null;
        document.onmouseup = null;
    }
}

Yeah, I know there are ways to make it more reusable, and probably your favorite library has a better version. blah blah blah. I just wanted to lay out the bare bones functionality so it’s plain to see.

Join me on the New Digg

3 responses so far

Kindle Fire First Impressions

Nov 16 2011

[image]

I got my Kindle Fire last night and wanted to post some initial impressions of the device.

First of all, I love it. Great form factor, feels very solidly built, great display, does all that I need it to do. I could not put it down for more than 2 seconds last night. Take that as a 95% awesome. The rest of the stuff I say here will be in that 5% maybe not so awesome category, so read it with that in mind.

Two big caveats with this device.

One, do not buy a Kindle Fire expecting to get an Android tablet. I would not call this device an Android tablet. If you want or need an Android tablet, go out and buy an Android tablet. This is a Kindle tablet that happens to use a version of Android as its operating system. If you can’t let go of that expectation, you will have a hard time with this device.

Second, the Fire is every bit as tied to the Amazon ecosphere as the iPad is tied to the Apple ecosphere. Pretty much every top level navigation leads to an Amazon service – Kindle books, Kindle cloud music and mp3 store, Amazon video portal, Audible audio books, etc. I’m a fan of all those services. If you are too, you will be in heaven. If you’re not, you’re going to feel like you wandered into the wrong party. Of course, I’m sure what Amazon is hoping for is that people will become fans of those services when they get the device. And that’s probably a pretty good bet. When you click on the Videos tab and see thousands of movies and tv shows you can watch for “free” if you have a Prime membership, you’re going to be awfully tempted to fork over $79 a year for that.

There are a few things that detract slightly from the awesomeness of the device, in my eyes. A lot of it has to do with it not being a real AmazonAndroid tablet.

For one, there’s no standard home / launcher screen like you have in other Android devices. Instead you have a bookshelf metaphor. The top shelf is huge and holds the “carousel”. This is a history of all the books you’ve read, apps you’ve used, web pages you’ve looked at. Problem is, at this point it’s permanent. You read the latest teen vampire romance novel, it’s cover is going to be loud and large the next time you turn on your Fire. Guilty music addiction? Be careful, or everyone’s going to know that the last thing you listened to was Celine Dion. Same goes for web pages. Enough said. I’m sure eventually Amazon will allow us to edit those, or someone will figure out where that history is stored and how to edit it.

Lack of standard home / launch also means no widgets. Under the carousel, you can save other “favorites”, which can be apps, books, web pages, etc. But widgets have no place on this device.

There is only a single hardware user control on the device – a power button. All your standard Android controls – menu, back button, home button, search, are in a bottom bar that can sometimes be collapsed to give an app more screen space. Likewise, the volume controls are all in software, accessible through another settings menu in the top status bar. This is very much in line with the original Kindle philosophy, which is to make the device disappear when you are viewing content. I don’t hate it, but if you’re doing a lot of navigating and jumping around from app to app, it is noticeably slower.

Amazon’s app store is pretty good. Unfortunately, you don’t get the full app store on the Fire. Due to various hardware limitations and the fact that it’s built on a forked version of an earlier Android build, it looks like the Fire needs specifically built Fire apps. Sideloading is possible, but I’ve seen reports that this is a hit and miss situation, with some sideloaded apps working fine, and others crashing. Again, you have to think that this is not an Android tablet, but a Kindle fire and the apps it runs are not Android apps but Kindle apps.

Finally, in what I consider possibly the biggest oversight, there is no external storage on this device. It has 8GB internal storage, of which 6 something is available. For me, that’s just about the point where you can store a decent amount of things, but you DO have to pay attention to what’s on there and remove things you don’t think you’re going to need for a while.

Of course there’s lots of other things that people will complain about. No 3G, no camera or microphone, etc. I don’t miss any of those things and don’t really expect them on a device in this price range. And anyone arguing about whether this is or is not an “iPad Killer”, just shut up. You’re an idiot.

Summary

So it’s got some imperfections, but again, in my mind all the bad points fall into that 5% not awesome space. If you can accept it for what it is, and you like Amazon services, it’s an amazing device, especially considering the $199 price tag.

Join me on the New Digg

20 responses so far

Older posts »

Search

Speaking

No upcoming speaking engagements scheduled. What a shame.

BIT-101 Recommends

Archives

Categories

Meta


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser