Archive for the 'programming' Category

no k2 in the WP theme directory…

I went to the theme directory tonight with the sole purpose and intention of voting on the one theme I’ve been more than happy installing (K2, duh) and it wasn’t there! I assume this is because they’re working hard on 1.0, trying to get that out before they add K2 to the throng of themes already up for grabs. (They’re on RC7 now, I think.) Anway, I hope it’s that, and not that there’s some feuding or some other BS reason K2 isn’t listed.

Anyway, then I ended up following some links, and poking around in the K2 google code pages, and remembered that I’d started a thread asking for a particular feature for K2 back in February. I hadn’t visited the issue page in all that time, but there had been some responses, including a developer who said if I made a patch for the feature I was requesting, he’d see that it went in.

So tonight I made a patch. This officially marks the first time I’ve actually contributed (code) to an open source project. I suppose I’ve helped plenty of people on support forums and things before, but if this code makes it in, I’ll be… a geek hero or something.

how to show an excerpt from the first post in a category in wordpress

For ReadComics.org I wanted to show the latest Book Club entry in the sidebar. For those of you who are not familiar with the way Wordpress does its posts, it uses some funky wrapper functions to access (and sometimes print) the entries in your blog. The main wrapper function, and the one that controls most of the stuff on the page is called the_loop().

This might be getting too detailed… You probably just want to know how to do what I did. There’s a lot more details on wordpress.org about using multiple loops on one page, but basically, the technique I used was to specify a new loop by using one of its internal functions called WP_Query directly.

WP_Query() takes an argument that tells it to just get the latest post from the book-club category. That looked like this: <?php $bc_query = new WP_Query('category_name=book-club&showposts=1'); ?> This uses category slug (”book-club” in my case), which you can find by editing your category.

So then you can use the standard functions like the_title() and the_excerpt() in a while loop. So the whole thing looks like this:


<li><h2>Next Comic Book Book Club</h2>
<!-- Get the last post in the book-club category. -->
<?php $bc_query = new WP_Query('category_name=book-club&showposts=1'); ?>
<?php while ($bc_query->have_posts()) : $bc_query->the_post(); ?>
<a href="<?php the_permalink(); ?>" alt="Read more about the next book club meeting." title="Read more about the next book club meeting."><?php the_excerpt(); ?></a>
<?php endwhile;?>
</li>

…and yes, I know the_excerpt() creates paragraph tags, and anchor tags around paragraph tags probably doesn’t validate. Oh well.

Why Postel’s Law is awesome

Caveat: Web standards are good. Everyone knows this. Without standards we’d have anarchy, or anyway we’d be stuck in the late 90s, trying to implement as many versions of our webpages as there are browsers. In my opinion, this does not at all mean that Postel’s law is wrong.

Be conservative in what you send, liberal in what you accept.

Lets start by taking a step back. What made the internet into the thing it is today? What makes it so appealing for so many people, all over the world? I’m willing to venture some of these things had something to do with it: free content, diversity of content, breadth or scope of content, and ease of access to that content. The internet is SO amazing because it is so diverse, and so immense, and so incredibly huge.

Sure, technology is cool. I personally find all the latest trends in programming to be really cool. But the technology that runs the internet is just one very narrow slice of content. It’s no lie: Content is king.

Now why is the internet so huge? How come there is so much content? Well, the answer to that is Postel’s law. Or rather, the answer to that is that early browser developers adopted Postel’s law. Because they made it easy enough to put stuff on the internet that pretty much anybody can do it. And they did do it! And that’s why the internet is so fucking awesome!

Can you imagine how much more frustrating web content creation would be if you saw errors every time you fucked up some html? Yes, for those of us who are web development professionals, it can occasionally be frustrating when the browser doesn’t tell you what you’re doing wrong… but this is an argument for better debugging tools, not for stricter html. I mean, do you really think debugging should be turned on by default? Hell fucking no!!! I know I laugh whenever I see backend error messages on a webpage. Fucking amateurs!

So IMHO it’s only fitting that each new version of a browser, or each new version of a web standard brings with it new pains and frustrations for those of us in the web development profession. After all, it’s our job to make sure this stuff works… We get paid the big bucks for those pixel perfect designs!

But if the browser developers are doing their jobs right (and damn straight the standards people better be doing their jobs right), content creation should only ever get easier. After all, it’s what makes the interweb such an amazingly awesome thing.

F1 Website Challenge

A few months ago, Chris linked me to Sierra Bravo’s F1 Overnight Website Challenge. It’s somewhere between a grownup lock-in, a charity event, and work. The premise is that you (as a developer) sign up to help out a bunch of non-profits spruce up their websites in 24 hours. I thought it sounded like fun, and signed up. I also conned a bunch of my co-workers into doing it too, so we’ve got a team that’s worked together before, and should be able to actually pull something together in the alloted timeframe.

Chris isn’t local anymore, so he won’t be there (too bad, really), but there are a surprising number of other people I’ve worked with who are also doing the event. I’m looking forward to seeing (and competing against) approximately eighty other web developers all at once.

I’ll have my camera with me, and definitely intend to do some flickr uploading while I’m there. (Or if the network is bad, after it’s over.)

Wish me luck!

BigText.org

I spent a bit of time (probably too little) one afternoon this week searching for a website that created ascii versions of text. Instead, I found a command line utility called FIGlet, and approximately 4 hours of dev time later, (including 3 hours after about 11:30pm last night), BigText.org was born onto the internets.

Feedback is welcome/desired. I’m especially curious whether anyone can break it, as obviously security is a concern.

UPDATE: There are many other web-based figlet servers out there. I’m glad I didn’t notice them until now. I probably would have given up.

Typography in Code: A Field Guide to Whitespace, Part 1

We all know what we like and what we don’t like when it comes to whitespace in programming. I can only speak for myself, but here are some elements to consider.

One of the universally accepted natures of code is to indent where appropriate, and this first installment of Typography in Code: A Field Guide to Whitespace will focus on the various incarnations of the all-important topic of (queue thundering god voice) indentation.

Topic: Tabs versus Spaces

This primordial, often invisible question is at the heart of the indentation beast. Like good and evil, right and wrong, vim and emacs — tabs and spaces are diametric opposites, warring factions facing one another across a never-ending epoch in which all our text files are smoking battlefields. One kicker is that both sides use ninja assassins. YOU CANNOT SEE THEM COMING, until… that is… you find them lurking in your legacy code, buried at the beginnings of lines near the ends of your files, like trip mines in long forgotten functions.

This is when you spend hours constructing that one perfect regex to rid your code of the enemy once and for all. (Also, unless, of course, you are one of those odd ducks who likes to see their whitespace characters. I respect you, even if you are crazy.)

Where I fall on this fence: My heart titters for tabs. But I didn’t always believe in them! I admit it, I was once an indentation swing state. But here’s why tabs are king for indenting: Tabs are like using semantic markup. We all (mostly) want code to all indent the same width (no matter what that width is), and a single tab character means that width. You can even change this width (tab stop) with a single command in any decent editor. This alone should be enough for the triumph of tabs over spaces.

Topic: How wide?

Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3. (Linus Torvalds, From Documentation/CodingStyle of Linux, via wikipedia)

This is a trickier beast. I believe in the power of four. It’s more legible (discernible) than two, especially across dozens of lines, and eight is just too wide a gap. With a tabstop of eight, you only get ten indentations before you’re out of 80 column width entirely! This is as opinionated as I get, since four just looks right to me, and I can’t really cite any good reasons for it. Just take it from me: you’re an IDIOT if you prefer anything else.

Yea, and the number of spaces to equal one tab shall be four. No less, and no more. The number shall not be three, and the number shall not be five. Fuck that the number shall definitely not be odd. The number shall not be two, and the number shall not be eight. The number shall be four.

Truthfully, I don’t care what your tabstop is set to, as long as these things are true:

  1. I can set my tabstop to something different and the code doesn’t look all fucked up. This means, yes, tabs.
  2. Never use a combination of tabs and spaces. (Fuck you, default dreamweaver settings.)
  3. Tabs should never be used anywhere but at the beginnings of lines. (This violates #1, but is also a really bad practice for other reasons that maybe I’ll get into in a later article.)
  4. Consistency, consistency, consistency. (WTF BSD, WTF!?)

Extra Credit: Read (and care about) the wikipedia article on Indent Style.

Next topic: How many line breaks look the best: Between Function Definitions, In Functions, Around Comments, and more!