Updated Console Keyboard Shortcuts in Firefox

Keyboard

keyboard” by Mark Lane on Flickr

Cmd-Alt-K on OS X or Ctrl-Shift-K on Linux or Windows will now always focus the console input line. It will no longer close the entire toolbox and you’ll have to use one of the other global toolbox commands, Cmd-Alt-i (or Ctrl-Shift-i) or F12.

Keyboard shortcuts.

They are the bane of Firefox Developer Tools engineers. Ask us in #devtools for a new keyboard shortcut to do X and you will be greeted by a chorus of groans. There just aren’t enough keys on a keyboard for everything we need to use them for.

I added a recent change to automatically focus the Console’s input line when clicking anywhere in the console’s output area (bug 960695). This spawned a series of follow-ups.

The first of these was the addition of Page Up and Page Down controls on the input line. (bug 962531). Now when the input line is focused, it will scroll the output area with page up and page down keys. If the autocomplete popup is active, it’ll scroll too. It’s a little thing that’s nice to have when you’re flipping through all of the completions for, say, the global window object.

The most important change we landed this weekend is a change to the Console’s main Keyboard Shortcut, Cmd-Alt-K on OS X or Ctrl-Shift-K if you’re on Linux or Windows. This key will now always focus the console input line. It will no longer close the entire toolbox and you’ll have to use one of the other global toolbox commands, Cmd-Alt-i (or Ctrl-Shift-I) or F12. (see bug 612253 for details and history)

Try it out. Tell us if you hate it. You can reach us here, IRC, or on the twitters.

And there’s still more to do. I filed bug 967044 to make the Home and End keys do the right thing in the Console’s input line. We have this “metabug” tracking all of the open shortcut bugs in Firefox Devtools. Are we missing any? Let us know!

Fat Arrow Functions in JavaScript

windmills panorama

Hard to beat C# and CoffeeScript here
- Brendan Eich, Arrow Function Syntax Rationale

Since sometime back in the heady days of Firefox 22, Firefox gained the ability to use Fat Arrow Functions in JavaScript. Users of CoffeeScript (or, I guess, C#) will be familiar with the syntax. We’ve been using these in Firefox DevTools code for nearly 6 months.

You can use them today in any shipping Firefox and experiment with them live in the Scratchpad or Console.

They look like this:

let x = (args) => { /* some function gunk */ };

If you want to call it, you can with x();

Fat Arrow functions have a couple of interesting properties. First and probably most useful is that they gain the scope of the environment they’re defined in. You can’t change the value of this by using a call() or bind() function.

Second, Fat Arrow functions don’t have their own prototype or a constructor. (They have the standard Function prototype). This means trying to use the new operator on a fat arrow function results in a TypeError.

That’s all well and good, but what is the practical application of all of this? If you’re a JavaScript programmer, chances are you’ve seen (and done) something like this before:

var listener = node.addEventListener("click", function(event) {
    let _target = event.target;
    this.handleClick(_target);
}.bind(this));

Inside we call a local method called handleClick() with the event’s target property. Nothing too exciting.

With Fat Arrow Functions, that becomes:

var listener = node.addEventListener("click", (event) => {
    let _target = event.target;
    this.handleClick(_target);
});

Look at all that saved typing!

The real benefit of course is that you don’t have to go through the mental hoop-jumping of trying to figure out what scope your function is going to run in (and more often-than-not, you just wanted it to run inside the current scope the function is being defined in anyway).

It just does the right thing.

Some interesting facts about Fat Arrow Functions

You can use them recursively. Because the containing scope closes over the fat arrow function, you can do things like,

let fib = (n) => {
    if (n <= 1) return 1;
    return fib(n - 1) + fib(n - 2);
}

You can’t use fat arrow functions as Generators. Deep continuations are not allowed. Fat Arrow functions are intended to be super light.

The “=>” syntax behaves like a “low-precedence assignment” operation. In

let x = () => { }

the order of operation is from left to right.

Update!

I didn’t include it originally, but some Fat Arrow Enthusiasts encouraged me to mention expression function syntax.

let square = (x) => { return x * x };

is equivalent to:

let square = x => x * x;

For single arguments, you can leave off the ()s. And for function expressions, you can lose the {}s and the return statement. Note that you cannot even use a return statement in this case as it’ll generate a syntax error about a missing semicolon. Don’t even try it!

iPods

frank's demise

I have had a number of iPods over the years. Starting with my iPod 3G, then a 5G (whose screen is pictured above), a 1st-gen iPod Touch and lately an iPod 7G Classic with a 160GB drive in it. I’ve loved them all, but it really feels like “Device as a Music Player” is done. Apple’s shift from iPods to iPhones started that downward trend.

But it’s gone further than just the obsolescence of the dedicated player. Music storage itself has become another quaint notion. Services like Rdio and Pandora (still not available in Canada) have replaced saved music for many people. And video too is a thing that is streamed rather than “owned”.

I blame Apple. The company that started the shift to digital music has failed to innovate. The 256kbit AAC DRM file is now the pinnacle of purchasable audio and it’s not nearly good enough. Marketing phrases such as “Mastered for iTunes+” really mean “We’ve destroyed any dynamic range this recording might have had”. Sure, the Compact Disc wasn’t perfect, but mastering for that format certainly left a lot more room for the engineer to play with.

iTunes itself has become something of an abomination. More interested with selling you things than maintaining and organizing your library, it’s frustrating to use if you have any amount of content in your library. Ironically, I think the Apple Remote software available on the iPad may be my preferred interface for the new iTunes. It may feel more connected to my library than iTunes itself.

iTunes 11 is the Apple Maps of media software.

I think the field is ripe for picking. Someone could come along and ship some music library software that doesn’t suck. I would pay for it. Bonus points if it will recognize and consolidate libraries from around my home network. And if it could stream to my devices while I’m out and about, automagically compressing my music on the fly, well that’d be keen.

Android Photography

Android’s come a long way since my first fumblings a few years ago with a Dell Streak (“steak”). Both software and hardware have improved immensely since then. Sure, there are still some things that make you shake your head and question reality, but for the most part, Android 4.2 is a great platform.

In most cases when looking for a piece of software for a particular task, the problem you’re faced with is that there are too many options to choose from. So, I’m going to share a few of my favorite photo apps with you. (spoiler: none of them are Instagram).

Stock Android Camera

Yes, it’s built-in on the Nexus phones. It was a big deal with the release of 4.2 and has a fairly unusual interface. Radial menus for most control functions and a strange focus indicator. It’s a decent app, but I tend to fumble with it when trying to use it. The radial menus and icons are harder to figure out at a glance than they need to be and the control I want is never on the menu I go to first.

Ok, not a huge fan, but one nice feature in the Gallery app is a new set of built-in photo filters that are on par with just about any other camera app. Combined with Android’s impressive sharing capabilities, it lets you edit some great pictures without installing anything else.

galaxy glitch

Camera Zoom FX

This was the first alternative camera app I bought for my Galaxy Nexus. I bought it for the built-in effects, but it turns out to be a very capable camera app in its own right. With a bunch of setup options for guidelines, stability indicators, and horizon leveling, it’s already more useful than the built-in app. Add in some additional shot controls like timers, timelapse and voice-activation and you’ve got a stew goin’.

How are the effects? Delicious. You can grunge up any decent photo and make it look like you’re shooting a $10 Lomo Diana without the embarrassment of actually handling one.

sale

Vignette

Apparently this is one of the most popular Android photography apps according to the Android Photographers group on Flickr. I tried it and it’s decent. I find some of the control settings a little hard to get to though, buried in the settings menu. If I need exposure compensation, I don’t want to leave the camera’s live view to do it.

Nice effects though and good level of control if you can dig into it.

construction at the river

 

Shot Control

If there were a camera app for nerds this would be it. Every control right there on the screen. There are so many controls, that the developers made a curious choice: The live view from the camera is in a corner of the screen. This real-time resizing comes at the cost of performance. It’s slow. Yes, there are lots of controls there to fiddle with. There are probably going to be times when I pull this out because I need a very specific bunch of settings. God help me when that’s true.

Snapseed

Hey, remember Snapseed? It used to be for iOS only and it’s by the very capable crew at Nik Software. Then they shipped it for Android. And then Google bought it. You can tell because it has a G+ icon in the top strip.

Don’t let its checkered past confuse you though. This is one of the few apps built by a company with a pedigreed history in producing professional image editing software. The controls are specific and very finely tunable. You should be able to produce some great photos with this. Only problem? It’s doesn’t have camera software builtin so you’ll be relying on one of the others to take the actual shot.

Flickr

I like flickr. It’s no secret. Their app has finally gotten some love as well.

The app ain’t bad, but the built-in effects are slow. You’re better off using one of the other image editors and using flickr to upload to flickr. It also shows up as a sharing option in the Android sharing menu for smooth, comfortable convenience. Nice!

ProCapture

A late addition from the Android Photographer group. Just installed this and it looks like a very capable camera app. I’ll have to play with it a bit but it might just be a thing.