Please join me at my new location bryankyle.com

Sunday, February 13, 2011

Scripting Inkscape

tl;dr

$INKSCAPE/Contents/Resources/bin/inkscape in.svg -e out.png -D -h 100 -w 100

SVGs, like all other vector graphics formats are scalable and work well for any sort of graphic that needs to scale well to different resolutions. So if you have an image that needs to displayed at many different sizes vector graphics are a good bet.

Vector graphics take much more overhead to render than do raster images. Since raster graphics are simply an array of bytes in memory that represent each pixel of the image they are relatively simple for a computer to perform operations on. Vector graphics on the other hand are usually stored as a series of drawing operations: draw a rectangle, fill it with a gradient, clip it with circle, etc. Because these operations have to be executed in order, sometimes drawing over the same pixels a few times they can be slower. Hence, vector graphics applications, such as Inkscape, have a rasterizer in them that takes the output of the SVG and converts it into a raster image. You might think of a vector graphic as a recipe, or the source code, for a raster graphic.

Using Inkscape to rasterize images can be a chore since you have to open manually adjust the size of the output graphic and filename for each different size that you want to generate. Luckily inkscape includes a command line rasterizer that you can script!

On the Mac, the actual executable is within the Inkscape.app bundle in Contents/Resources/bin/inkscape. You can invoke it from the terminal with options to control the height and width of the output graphic, it's name as well as a few other options. Running inkscape --help will list all of the available options. The ones we're concerned with are: -e, -C/-D, -h, and -w. -C is used when you want to export the drawing and -D when you want to export the entire page. The difference between the two being that exporting the page will export everything including white space around your drawing and exporting the drawing will trigger Inkscape to find the smallest rectangle that includes everything you've drawn (which might be smaller than the page) and export that.

To export the drawing contained in "Scenery.svg" to a 100x100 PNG called "Scenery.png" you would use the following command in Terminal:

$INKSCAPE/Contents/Resources/bin/inkscape Scenery.svg -e Scenery.png -D -h 100 -w 100

Where $INKSCAPE-APP is the location of Inkscape.app.

Since rasterizing SVGs is something you might be doing frequently you can always write a script to run the above command with different sizes and output names. If you want to get fancy you could even automate the process using Make or another build tool.

Thursday, November 18, 2010

The Playbook

RIM recently released a video "previewing some of the cool stuff [they're] doing with the Blackberry Playbook browser." From the video, it certainly looks like the Playbook wipes the floor with the iPad. It loads pages faster. It supports "dynamic" content, by which they mean Adobe Flash. It passes the ACID3 test. Of course the video is incredible, they'd be fools to release a video that wasn't. But after thinking about it for a little while, I came to the realization that it wasn't really that amazing at all.

This video is showing a speed comparison between 2 devices. Yes, they're both tablets but it's not really a fair comparison. The iPad has been shipping to customers for about a year. Since Apple doesn't rev the hardware between releases that makes the hardware at least a year old, if not older. As for the Playbook, there's no official release date yet. All we've so far is early 2011, which means sometime between January and March. Assuming that the Playbook's hardware specs have been nailed down, the video is comparing a brand new device with one that's a year old. Of course the new one's going to be faster, no surprise there.

The sites that RIM picked for the demo were obviously not chosen at random. Clearly these were sites that they knew would show off the features of the Playbook. Almost any site would loaded faster and performed better on the Playbook given that it's newer. Similarly, the Playbook claims that it has better ACID compliance than the iPad. Both devices, as far as I know, use WebKit. Safari on the iPad is just using an older version of it. Maybe we'll see better ACID compliance out of Safari on iOS 4.2 which should be released in the next week or so.

While the video was certainly impressive at first glance, after some thought it's really not that amazing at all. In fact, it leaves a lot of open questions. What's the battery life like on the Playbook? Sure the device appears faster and supports flash, but if you can only use it for a few hours what's the point? How smooth is the UI? Where are the Apps? I'm sure RIM has a good answer for all of these questions, I just wish they'd stop releasing marketing material and just ship the damn thing and let it stand for itself.

Tuesday, October 26, 2010

Do Smart IDEs Cause Dumbening?

The other day I read an interesting blog post from Luke Palmer the other day titled IDEWTF. In the article Luke discusseshow IDEs appear to be falling behind in the state-of-the-art compared to creative tools like Photoshop, Premiere, AutoCAD, etc. Luke's main point is that as developers we should be able to create and use the best tools for our craft. IDEs should be much more advanced than they currently are. While I agree with his point in spirit, I'm not sure that making our IDEs do more is the best thing for developers.

In 2003, a study (pdf) was conducted by a psychologist named Christof van Nimwegen. In the study 2 groups of people were asked to play a logic game. The game involved transfering colours balls according to a set of rules. One group was given a piece of software that assisted them in playing the game. For example, the software would highlight moves the player could make at a given point in time. The other group was given software that was not helpful -- it would not highlight permitted moves.

In the beginning, the group that was given the helpful software was able to solve the problems faster than the group that had the non-helpful software. However as the study progressed the group that was given the non-helpful software became much more proficient. In the end, the group using the non-helpful software was able to solve the puzzles using fewer extra moves, and produced fewer dead-end states where no more moves were possible.

The two groups were brought back in 8 months later to re-run the tests and try a different, but similar, logic puzzle. The group that had initially used the non-helpful software hit the ground running, so to speak. Not only were they able to solve the puzzles faster than the group using the helpful software but they were able to adapt their knowledge to the second puzzle.

This study suggests that helpful software, or software that offloads complexity from the user onto the software, makes us reliant on it. This doesn't say that it's a zero-sum game in which by the IDEs getting smarter the developers must get dumber. Far from it. I believe that we need to strike a balance between HAL 9000 and Notepad.

If the IDEs become too smart, and coddle the developer too much the developer will learn to rely on it. Automatic correction of syntax, imports, exceptions, etc are not in and of themselves bad. They certainly improve productivity. But the developer then learns to rely on their presence, like a drug. If the developer ever tries to work with a language that doesn't have the kind of tooling their used to they will pay a huge cognitive price up front, something that might be enough to scare them away.

So where do we draw the line? Which features improve both long term and short term productivity, and which cause dependence? I think the line is right between those features that do something automatically for the developer and those that provide advice. A feature that does something for the developer effectively offloads the cognitive complexity from the developer to the software; the developer is freed from having to think about it -- at least that's how they see it. With features that simply provide advice to the developer the IDE is allowing them to be more productive without having to pay a long term price.

An IDE like Eclipse has many of types of features. The classic example of an automatic feature is "Quick Fix". When Eclipse notices that something is wrong with the code that it can fix, it allows the user to tell the IDE to fix the problem for them. Developers that are experienced without the IDE will probably understand what it's doing. They would have been able to make the correction themselves without the help of the IDE. To them, this automatic feature is simply a way of improving their productivity. For the less experienced developer however, its mode insidious. Because the user doesn't understand what the IDE is doing, or why it needs to the user becomes more dependent.

Eclipse also has a variety of features that are designed to assist the developer. Call Hierarchy, and Class Hierarchy are two great examples. The developer still needs to understand what these features are used for; the tool simply gives the user advice, quick information that helps them make a decision or explore a code base. These features still cause a sort of dependence, but since the developer understands what the tools are for, and why they need to use them the dependence is less insidious. Without these tools the developer can still do her job, but productivity might be affected. In contrast with automatic tools where the developer wouldn't be able to do his job.

So, do smarter IDEs cause dumbening? You be the judge.


Footnote: I know "dumbening" is not grammatically correct. The word comes from a Simpsons episode where Lisa worries that she's losing her intelligence and writes in her journal:

Dear log. Can it be true? Do all Simpsons go through a process of dumbening? Wait, that's not how you spell dumbening... waaait, dumbening isn't even a word!

Wednesday, October 20, 2010

Predictions Report Card

So Apple held their much anticipated Back to the Mac event today. Since I made some predictions, I thought I'd follow up to see how well I did on my first attempt and predicting what was going to be shown.

To recap, I made the following predictions. I'll address each of these in turn.

  • Sneak peek of OS X 10.7, to be called Lion
  • New OS will have more user facing features
  • New OS will have over-the-air syncing with portables
  • OS will be seeded to developers shortly
  • OS will be generally available around WWDC '11
  • New release of iWork
  • New release of iLife
  • New MacBook, MacBook Pro and MacBook Air
  • Minor speed improvements for new models
  • SSD becoming standard equipment
  • USB 3.0
  • No Blueray
  • No iPad

Sneak peek of OS X 10.7

Sure enough, Apple did announce a new version of OS X today. As expected the new release is called Lion. I got this one right. It was a gimme, but I'll take it.

New OS will have more user facing features

In the announcement today Apple talked about a few new things that they were adding to the OS X 10.7. These included Mission Control, Launchpad, and Full Screen apps. These are clearly user facing features but since I was extremely general with my prediction I'm only going to give myself a half a point.

New OS will have over-the-air syncing with portables

Apple didn't make any announcements about whether over-the-air syncing would be available. Even as I was writing that prediction it seemed a little far-fetched to me. That sort of announcement really only makes sense at an iOS/iTunes announcement, not a Mac event. I missed this one.

New OS will be seeded to developers shortly

Apple didn't make any announcements regarding when the OS would be going out to developers. Since it could be released any time I'm going to hold off on saying whether or not I got this one.

OS will be generally available around WWDC '11

According to Apple, OS X 10.7 is on track to be shipping during the summer of 2011. WWDC is typically in June which puts it in (the beginning) of summer. Since I was more specific than Apple, and these dates tend to slip I'll only give myself a half a point on this one.

New release of iWork

There was no announcement regarding a new release of iWork. I flat out missed this one.

New release of iLife

A new release of iLife was announced. I got it.

New MacBook, MacBook Pro and MacBook Air

This one's tricky. While a new MacBook Air was announced there was no mention of revving the MacBook and MacBook Pro line. I'm going to give myself 1/3 of a point for that one.

Minor speed improvements for new models

Sure enough, there were speed improvements for the MacBook Air line. +1 for me.

SSD becoming standard equipment

Again, SSDs are standard equipment on the MacBook Air. I got it.

USB 3.0

No USB 3.0. No points for me.

No Blueray

As expected, there was no Blueray announcement. But since the MacBook Air doesn't have an optical drive I'm not going to count this one for or against me.

No iPad

No new iPad was announced. +1 for me.

Conclusion

In total I made 13 predictions. Of those one is pending an outcome in the next few weeks and one I've rationalized away leaving me with a total of 11 predictions that I can grade myself on today. According to a completely impartial jury I got 6 and a 1/3 out of 11 right. That's better than half. Not bad for a first timer.

Monday, October 18, 2010

Predictions for Wednesday

Apple has a Mac press event coming up on the 20th of October. Usually, I don't do this but I thought I'd take a stab at some predictions for the event. So, without further ado, here's what I think we'll see.

Sneak Peek of Mac OS X 10.7

The invitation that was sent out to the press for the event includes a picture of a lion peeking out from behind an Apple logo. Given that all releases of Mac OS X are named after large cats it doesn't take a genius to put two and two together. Clearly a new version of the operating system will be previewed, and its name will be Lion.

The last release, Snow Leopard, was mostly about the plumbing. Lion will need to have more user facing features. I'm willing to bet we're going to see some better integration between the Mac and Apple's portable devices: iPad, iPhone and iPod. The new OS will probably include over-the-air syncing with mobile devices and some new APIs to support it. As for other features, I don't have a clue.

I don't think the new OS will be released at the event. Apple seeds a few releases to the developers before shipping it publicly. This will be a preview only, the developers will probably get their copies within a few weeks and the new OS will ship around WWDC '11 next year.

iWork and iLife

The last release of both iLife and iWork was in 2009. Usually Apple likes to release new versions of its productivity software at the beginning of the year, but seeing as the last release is almost 2 years old it could use an update. Plus, with Microsoft due to release Office 2010 soon it makes sense for Apple to release its competitive software around the same time, hopefully to knock the wind out of Microsoft's sails in the consumer market.

New MacBook, MacBook Pro and MacBook Air Portables

According to the MacRumors.com buyer's guide all of the portables have been out for about 6 months. In the case of the MacBook Air much longer than that. I'm guessing we'll see speed bumps across the board, SSDs becoming a standard component and USB 3.0. With Apple supporting high-def video through rentals and purchases in the iTunes Store I don't see Apple including a Blueray player.

No iPad

I don't think we're going to see an update to the iPad. iPad was first announced late January 2010 and didn't start shipping until March. That means the 1st generation iPad hasn't been shipping for a full calendar year yet. With the holiday season coming soon and a well oiled supply line on the device it doesn't make sense for Apple to announce a new one and canabalize its holiday sales.


This is the first time I've ever done a predictions entry, and usually I don't pay much attention to what's going on. So don't quote me!

Saturday, October 16, 2010

How To Deal With Customers

I was at a local computer store this afternoon and I overhead a conversation between who I believe to be the owner and a customer. I didn't hear the whole conversation since I walked in half way through, but the part that I did hear I found startling.

The customer was ranting and raving about how much he hated the computer that he had brought in. He was livid about how it constantly lost data, crashed and generally didn't do what he wanted. He kept saying that he was going to try a Mac because of all of the problems.

Instead of talking the man down gently and being generally agreeable the owner decided to get into a verbal fist-fight with the customer. For every knock the customer had against his computer the owner had something to say about it.

"It just turns itself off after an update!" "It doesn't just shut down, it give you 5 minutes to save what you're doing!"

"The screen doesn't work right." "These things work fine. If yours isn't working it's probably a faulty card or something."

The owner kept trying to give the customer reasons that he should stick with a Windows PC.

"The Mac has 1 trillionth the amount of software." "I don't care. It's not a toy, it's a tool. I don't need lots of software, I just need something that allows me to get my work done!"

The icing on the cake came towards the end of the conversation when the owner said, and I quote: "90% of the world can't be wrong."

In this case, I think the customer was angry when he walked in the door. He was looking for a fight. Clearly the owner doesn't have children. If he did he'd have realized what the customer was doing to him. Instead of fighting with the guy, he should have just agreed with all of his points and suggested that he do try a Mac. The customer had already made up his mind that he wanted to try one.
When the customer asked questions that he didn't know the answer to he should have picked up the phone and called one of the Mac stores in town. That would have diffused the situation and earned him some emotional currency. He could have even gone as far as to ask one of the stores if they do rentals or have a try-before-you-buy program. That customer didn't come in to buy anything, he came in for some help. So help him.

If the customer did ultimately decide to go with the Mac, he'd only have good things to say about the store. He'd refer business over to them if anyone asked and was in the PC market. In the age when brick and mortar stores are close to extinction any way that you can distinguish yourself from a faceless web site and earn some emotional currency is worth the price. Yes you might lose a sale, but you'll just have earned some in the future.

Monday, October 11, 2010

Nil Advice

Recently I wrote that one of the things I really like about Objective-C is how it handles nil-values when calling methods. It certainly makes for code that's easier to read however it does have a downside as mentioned by Daniel Jalkut of Red Sweater software. In Don't Coddle Your Code, Daniel writes:

It s also worth noting that LaMarche s defense of nil ing out instance variables hinges on the presumption that messaging nil is safe. True, messaging nil will not cause a crash. But is that safe? Not if it changes the behavior of your code in unpredictable ways.

He goes on to demonstrate his point with some contrived but applicable code:

if ([mDiplomat didReturnGestureOfPeace] == NO)
{
    [[NuclearWarehouse nuclearMissile] launch];
}

Daniel's point is this:

The biggest disservice you can do to your users is to allow them to run code that has unpredictable behavior. The whole point of programming is to make computers accomplish tasks in predictable ways.

I think he makes an excellent point. To paraphrase -- and I'm sure C++ developers will agree -- just because you can do something doesn't mean that you should. This language feature is a boon for those that understand how to use it effectively and design interfaces that work well with it.