Letting Perfect Get in the Way

I’ve been contemplating a phrase for a few days now. It applies to writing code, as I do for a living, as well as a whole host of other things… from relationships, to home life, life goals and endeavors… the list goes on.

Don’t let perfection stand in the way of progress.

I know what some people are immediately going to think when they read that. You’re asking me to settle for less than the best, Aaron? Let me say, emphatically, no. In fact, settling is the opposite of what I’m suggesting.

You may have heard of the Lean Startup concept of building a new business or product. I’ve talked about it before. The basic idea is you don’t wait to be feature perfect… you build, iterate, gather feedback, iterate on that feedback and continue the process. That philosophy hedges your bets around building something nobody wants by not waiting for the final, polished product before launching into the world. It relies on the concept that you don’t have to have something perfect in order to release into the wild.

Too often when making engineering decisions in a product, the risk is that you will want to make sure everything is perfect right now. Make sure the classes are all structured perfectly. Perfect object oriented methodologies are in place. Every edge case considered. An entire code-base unit tested.

All of these are extremely important, but they are also things that can be iterated on. Sometimes you can’t write code that relies on code you haven’t yet written yet! So you write shitty code that does the job in order to get ahead, and then return to that shitty code to refactor later.

Sometimes in your personal life, you may find yourself in a relationship that doesn’t have all the ideology of “The One” (Note: What the fuck does “The One” even mean?). That person is perfect in every way. They get your hearts. Understand your twitches. Empathize and support you through all your difficulties and struggles. Yet there’s just a couple things you just can’t stand. Do you give up and move on to the next, expecting next time that you’ll find perfection? Or do you buckle down and realize what you have is pretty damn good and it will be even better than that later on?

Do you let perfection get in the way of progress?

You shouldn’t. You should release, iterate, get feedback and release again. In code. In life.

Sublime 2 Power Tools

This is a very advanced technical article.

For years, as a developer, I used the fantastic Textmate software for writing code. I got used to it. It’s a power editor for Mac OS X and has bundle support (think of bundles as extensions or plugins) that enhance the functionality of the software) for just about every technology, from Subversion to Git to a bunch of things I don’t use in a PHP environment like C/C++ mallloc (memory allocation), Python, Ruby, etc. It’s even got a WordPress bundle!

The problem with Textmate, however, is that active development is slow. Like, extremely slow. Like, molasses slow. After five years of using version 1.5x, an alpha version of 2.0 finally emerged last year. It’s still in alpha. Pace of development is still painfully slow, and what is in the 2.0 alpha version is not ground-breaking compared to what is in the current stable version.

Along came Sublime 2. This is, by far, my favorite text editor ever. I’ve been using it for about six months. It emulates virtually everything Textmate does. Textmate does snippets (think of them as macros). Sublime 2 also does snippets and supports the Textmate style. (Hint: If you’re a WordPress developer, my favorite – and still most commonly used – snippet comes from Mark Jaquith who wrote this snippet to create WordPress widgets on the fly. It works in both Textmate and Sublime 2).

The great thing about Sublime 2 is that it is truly a hacker’s paradise. All the config files are JSON objects, so if you can write JSON, you can configure Sublime 2. None of this namby pamby UI/click/select from dropdown bulldookie. Write your code and mean it. Related is that the master configuration file is extremely well documented and you can override everything in it, not by editing this file, but by providing new values in the user configuration file.

Ok, let’s back up and get y’all up to speed on what I do when configuring my Sublime 2 environment.

Config Files

First, I recommend you look at the entire Default configuration file. Read all the settings and comments and understand all the possibilities you have. Your most comfortable environment won’t be mine. For me, I see the following configuration settings that I’m going to want to override. Keep in mind, I never edit the default configuration file. It gets overwritten on upgrade.

To access this file, go to Preferences >  Settings – Default 1.

Note that I have included the related Sublime 2 default comments along with the settings I wish to override.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// While you can edit this file, it's best to put your changes in
// "User/Preferences.sublime-settings", which overrides the settings in here.
//
// Settings may also be placed in file type specific options files, for
// example, in Packages/Python/Python.sublime-settings for python files.
{
// Note that the font_face and font_size are overriden in the platform
// specific settings file, for example, "Preferences (Linux).sublime-settings".
// Because of this, setting them here will have no effect: you must set them
// in your User File Preferences.
"font_size": 10,

// OS X only: When files are opened from finder, or by dragging onto the
// dock icon, this controls if a new window is created or not.
"open_files_in_new_window": true,

// Characters that are considered to separate words
"word_separators": "./\\()\"':,.;-<>~!@#$%^&*|+=[]{}`~?",

// When drag_text is enabled, clicking on selected text will begin a
// drag-drop operation
"drag_text": true,
}

These settings and their related comments may seem self-explanatory, but in case they are not…

font_size: This setting controls the font size in the editor. Derp.

open_files_in_new_window: As a developer on an 11″ MacBook Air, I hate this setting. As the name suggests, everytime you open a file, it’s going to be in a separate window. This may be okay if you have a ton of screen real estate, but if you don’t… well, I like to have windows open up in a new tab of my editor so I can access them quickly and easily without consuming precious real estate.

word_separators: This is a list of characters that serve as word separators. I don’t mean code word separators. We’re talking about in the editor. I want to be able to click a CSS selector that often comes with a dash in the middle, and highlight/select the whole selector. By default, if there’s a hyphen, only the portion of the word clicked will be highlighted.

For instance, if a <div> has a class="foo", and I click on foo, foo will, by default, be selected. But if that div has a class="foo-bar", then clicking on foo will only highlight/select foo (up to the hyphen) and not all of the, more contextually accurate, ‘foo-bar’. In my user configuration file, I’m going to remove the hyphen, and thus remove this annoyance from my life.

drag_text: This is an edge case setting, but it has bitten me a few times. If you’re in a window in Sublime 2, and you have a block of code selected, when this default configuration is in play, you can drag that text into another window. I can see the use for this, but it’s also thrown me for a loop more times than it’s been useful. I override this to prevent that from happening. If I really want text in another window, I’ll jkust do the traditional copy and paste.

Overriding Defaults

Knowing I want to change these settings, I can write my own JSON object into my User configuration (Preferences > Settings – User):

1
2
3
4
5
6
{
"drag_text": false,
"font_size": 15.0,
"open_files_in_new_window": false,
"word_separators": "./\\()\"':,.;<>;~!@#$%^&*|+=[]{}`~?"
}

Easy Peasey!

Installing Packages

Where Textmate had Bundles, Sublime 2 has Packages. Packages are extremely powerful.

NOTE: Install this first 2. Trust me. And get familiar with this.

There are a million and one different packages out there, depending on what your needs are. Installing a package is as simple as going to Preferences > Package Manager > Install Package. Note that you can also add new external repositories of external packages that Sublime 2 can also search.

Sublime 2 - 4 Pane Grid View
Sublime 2 – 4 Pane Grid View

Summary

Sublime 2, of course, has hundreds of different setups. It kinda just depends on your taste and not being afraid to try things. Because everything is based on text file configurations and settings, everything can be reversed. Don’t be afraid to break things. You can always back out. You can even set it up so that you have multiple files open in the same tab. Set it up the way you want it and go be more productive!

Notes:

  1. Sublime 2 works on Mac OS X, Windows and Linux. All options will be similar, if not identical, to what I’m providing here from an OS X perspective. If you can’t find what I’m referring to, think about where logically it might be in your menus.
  2. Specific installation instructions can be found here.

Fun With Programming Languages

Tonight, a Facebook thread got a little out of control after I posted a status update that I was “mentally bankrupt.” It was a long day working on client work – a project that is just about done but past due.

After some commentary by Facebook friends, we got to writing little scripts that would take a random selection from a group of adjectives and adverbs and put similar phrases together randomly.

What came of this exercise was a fun little jaunt into a variety of programming languages.

PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$adverbs = array(
    'mentally',
    'morally',
    'emotionally',
    'socially',
    'psychologically'
);

$adjectives = array(
    'devoid',
    'bankrupt',
    'empty',
    'hollow',
    'vacant',
    'sleeping with fishes',
    'taking a dirt nap',
    'shallow'
);

echo $adverbs[array_rand( $adverbs )] . ' '
    . $adjectives[array_rand( $adjectives )];
?>

Ruby

1
2
3
4
5
6
7
8
9
10
11
adj = [ "mentally", "morally",
    "emotionally", "socially",
    "psychologically" ]

adv = [ "devoid","bankrupt",
    "empty", "hollow","vacant",
    "sleeping with fishes",
    "taking a dirt nap","shallow" ]

print adj[rand(adj.length)] + " "
    + adv[rand(adv.length)] + "n"

Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import random

def popchoice(seq):
    return seq.pop(random.randrange(len(seq)))

adj = [ 'mentally', 'morally',
    'emotionally', 'socially',
    'psychologically' ]

adv = [ 'devoid','bankrupt','empty',
    'hollow','vacant','sleeping with fishes',
    'taking a dirt nap','shallow' ]

print popchoice(adj) + " "
    + popchoice(adv)

SQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
CREATE TEMPORARY TABLE adjectives (
    adjective VARCHAR (30) NOT NULL
    );

CREATE TEMPORARY TABLE adverbs (
    adverb VARCHAR (30) NOT NULL
    );
   
INSERT INTO adjectives (adjective)
    VALUES
    ('mentally'),
    ('morally'),
    ('emotionally'),
    ('socially'),
    ('psychologically');
   
INSERT INTO adverbs (adverb)
    VALUES
    ('devoid'),
    ('bankrupt'),
    ('empty'),
    ('hollow'),
    ('vacant'),
    ('sleeping with fishes'),
    ('taking a dirt nap'),
    ('shallow');
   
SELECT CONCAT_WS(
    ' ',
        ( SELECT adjective FROM adjectives ORDER BY 1 LIMIT 1 ),
        ( SELECT adverb FROM adverbs ORDER BY 1 LIMIT 1 ) )
    AS RandomStuff;

For PHP Devs, a Twitter PHP Class

At the end of this post, this site is going into a twitter free period of two weeks. I’m sensitive to the fact that we talk about Twitter quite a lot and not always doing a good job of reaching into all of real life like we’d like. So after this post, Twitter will not be mentioned here until June 12. :-)

However, I wanted to get this out the door for devs to knock on and bang out. Awhile ago, I created the dctwits Twitter group and released the generic code. It included a Twitter class created by David Billingham and slightly modified for our use.

A few days ago, I released the WP-Twitterpitch plugin which also used the same class. It’s a very useful class but, to be honest, was a little messy, didn’t support XML and JSON and didn’t have support for all the Twitter API.

So I cleaned it up, extended it, fleshed it out a bit more, brought in Keith Casey as a developer and we’re basically launching the class as a version 1.0-beta today.

I’ll work on documenting things a bit more but there is some basic usage on the site and the code itself is pretty well documented. I need testers to bang on this code and submit issues back, via the Google Code page. Patches welcome as well. And I’d love to see how you use this. You can download direct or via SVN.

When Keith gets done with the DC PHP Conference, we’ll look at pushing it out as stable.

Funny WordPress Plugin Sneaks In

One of the annoyances we have at b5media is when people spell our company name wrong. We’ve even had our own people spell the name wrong. So annoying. :-)

Somewhere along the line last year, this universal plugin snuck into our build. I don’t know where it came from or who wrote it. (whistles) It solves the problem though. :)


1
 

Maintaining WordPress on SVN: Adding Plugins

Thank you for joining me again for this series on maintaing WordPress from subversion. We talked previously about creating an SVN repository and then about importing WordPress into the SVN repository.

Today, we get into customizations. It does us no good to have an SVN repository with WordPress if we don’t change it to be something other than what it is. In this episode I talk about adding plugins (and you can add any file, really) by adding it to the working copy folder and then checking it in.

I also touched quickly on svn:externals, although I note that I goofed in the screencast and typed

1
svn propedit svn:external .

instead of using the correct

1
svn propedit svn:externals .

(note the plural externals).

WordPress Export Base Class

Real quick note to let you know that over the weekend, I released new code that is GPLv2, relating to WordPress export format (WXR). The code and details are here and I’d love to get some input and contributions of other export classes. I’ve included a (yet undocumented) Expression Engine exporter as well and will back port some of my previous exporters to use this class as well.

So, if you’re a WordPress hacker, or if you just want to help people move to WordPress and have some coding skills, half the battle is already fought. Check it out.

Expression Engine WXR Export Class

Earlier, I shared with you a new base class I’m releasing into the wild. While that was a conceptually nice piece of code, and potentially useful, it didn’t really translate in usefulness without some actual code.

As mentioned, I just moved Shai to WordPress from Expression Engine and it required writing a custom export routine. Instead, I wrote the base class in conjunction with this extension class.

This could very well be a very good example for someone wanting to write their own routine. While it is custom to Expression Engine and would look different for other platforms, the bottom line is that the methods in the base class have to be fed certain data.

As with the base class, this is meant for advanced WordPress hackery and is not a plugin nor for rookies. I don’t mean to sound condescending, but it took me years to wrap my head around object oriented PHP and so please don’t ask me. :-)

I can say that if you dive into this code, you will find the roadmap to your own importer. This is fully functional. It works. It’s for Expression Engine, but it works. Your methods should return similar data.

One day I’ll get around to documenting it, but my mind is mush after working on this all weekend. :-)

Update: Oops, forgot where you can download. Subversion it is again:

1
svn co http://svn.aaronbrazell.com/wpwxr/tags/expression-engine/ expression-engine