Tuesday, May 6, 2008

Posting code made easier (for everybody else reading your blog!)

I've noticed something while reading my daily blogs, a lot of code is just unreadable because most blog systems (blogger looking at you), screw up indentation, unless you wrap it in a pre tag (opening and closing are both required. This makes it readable for your readers! I've left comments on the blogs that didn't know this, and now they do.

This message is primarily for the Google Summer of Code students, but is useful to the programming community as a whole. When you post code, wrap it in a pre tag and be sure to close them when your code example is complete.

4 comments:

Ben Wolfe said...

I can't seem to use the pre tag in your comments. How am I supposed to post code snippets to your blog?! :-)

I get an error when posting this text if I don't use the < special html character:
<pre>
public void myPreTagTest() {
<--there should be a tab here
}
</pre>

Is there a place to turn on tags other than b/i/a in your comments in blogger?

Robert O'Connor said...

Yes, unfortunately, the powers that be on google's blogger team decided to disallow them in comments. Poor move. This is primarily for blog posts.

Igor said...

I mostly use code2html(http://www.palfrader.org/code2html/) and then I copy and paste the resulting code to my post, it works pretty well if you ask me :)

Robert O'Connor said...

Yes -- wrapping it in a pre tag is the quick and easy way to do it; no need for me to go to another site. Plus on my blog i have syntax highlighting now :)