Archive for May 2009

Sony CEO “doesn’t see anything good having come from the Internet”

I just read an excerpt from an interview with Michael Lynton, the CEO of Sony Pictures. To quote him,

I’m a guy who doesn’t see anything good having come from the Internet. Period.

He backed up this statement by arguing that the Internet feeds the mentality that people “can have whatever they want at any given time”.

For the typical person, day to day use of the Internet is fairly trivial. Read the news, check Facebook, play a game, look up a BBQ chicken recipe, check Facebook again. While this may be true, you don’t have to think too hard to determine that the near instantaneous access to information offered by the Internet has had a more than trivial effect on our lives. Apparently, however, the comforts created, the improvements to quality of life, and even the lives saved as a result of this innovation are negated by the negative impact of piracy.

I personally don’t see how someone can make a statement like that, unless he completely misspoke or is just completely ignorant of the reality of things. Does he really think that the Internet has created such a huge problem that all of the good stemming from it is not worth mention? I’ll accept that the Internet has caused more problems then it has solved when Michael Lynton can’t afford a golden toilet seat. Until then I’m going give the same amount of merit to the opinions of Sony CEOs as I do to: people who claim aliens abducted them, people who don’t believe in medicine, and people who communicate with the dead. I draw this comparison based on the fact that their opinions and statements are all grounded in about the same amount of reality.

Source

Happy Birthday To Me

BWI, blogging while intoxicated.

The Artificial Nature of Website Value Estimators

It is common knowledge that web site value estimators are horribly inaccurate. If you don’t intend to use their results to market your website however, it is still fun to see what value they assign to your site. Most likely we’ve all taken one of these estimators for a test drive. Today I did just that, using this domain and I discovered that this site is worth 1,714 USD. I highly doubt, however, that I can go and find someone willing to pay that much for this site, not that I would do such a thing, nor am I claiming that this site doesn’t have worth.

One reason I doubt this is for the simple fact that this site was designed by me, its full of my writing, and every aspect of it is designed to suit my purpose. Even the domain name is derived from my last name. There is another reason, however. Two days ago, using the same estimator and the same domain it spit out a much different number: 78. Did my website suddenly explode over the last two days? The answer is yes and no. A short time after I used the estimator I released two wordpress plugins back to back. This resulted in a large spike in traffic. This spike, however, will wear off in a few days. Though I will likely see an increased level of traffic from what it was before this happened, it won’t be as high as it was on release day.

So what does this mean? The estimator most likely picked up on the elevated amount of traffic over the last few days and judged the value of this site based on that (and other factors of course). Never mind that maybe only a dozen people will read this article, and never mind that only two days ago the estimate was two orders of magnitude lower, I can now turn around and sell this site for a thousand bucks.

Before you get too excited about the value one of these things assigns to your website you should remember that they employee a discrete algorithm. This algorithm obviously cannot determine the value of the content of your website. In the real world, the content of your website plays a much larger role in determining its value. While it is important to take other factors into account, leaving out the content factor makes any estimate worthless.

Inheriting Code

If you’ve been a programmer for any amount of time you’ve more than likely had the honor of inheriting someone else’s code. This might be in a corporate scenario, or you might just be modifying an open source program. Either way you’re experiences though varied are probably marked with few comments, poor syntax, and obscure methods. This might be something you can tolerate, but personally, I am a code perfectionist. I find it difficult to code in new functionality or modify existing functionality without reworking the code to suit my tastes. This can easily go from moving a few braces around to doing a full overhaul.

Unfortunately I can’t offer much advice to those who are stuck in a situation where they are digging through terrible code; honestly all you can do is be patient and buy a stress ball. I can, however, offer some tips on good coding practice that might prevent you from ruining someone’s day.

Tabs and Braces and Spaces

Also known as whitespace. There are few things more frustrating than staring at code that isn’t organized. The number one thing that deters me from helping someone with a programming question is looking at their code and seeing things like this:

$x = 0;
while($x < 10)
{
if($x==3){echo 'This is terrible code';}
else
{
echo 'hello';
}
x++
}

To begin with, the only time braces should not be on a line of their own is when they are preceded, or followed by a conditional statement:

//OK... this method id my personal preference
if($x == 1)
{
	echo 'hello';
}

//OK.. probably the most common
if($x == 1) {
	echo 'hello';
	/*
	.
	.
	.
	*/
}
else {
	echo 'goodbye';
	/*
	.
	.
	.
	*/
}

//OK.. I'm not a fan but its acceptable
if($x == 1) {
	echo 'hello';
	/*
	.
	.
	.
	*/
} else
	echo 'goodbye';
	/*
	.
	.
	.
	*/
}

//NOT OK!
if($x == 1) { echo 'hello'; /* . . . */ }

Moving on, code nested within braces or within the body of a conditional or other control flow statement should be indented:

//OK
for($i = 0; $i < 10; $i++)
{
	echo "hello \n";
	echo $i;
}

/**
* OK,
* Some people don't like this method, but as long
* as it is only a single line its fine with me. Make
* sure you leave an empty space following the
* final line.
**/
if($x == 1)
	echo '$x = 1';
else
	echo '$x != 1';

//NOT OK
while($x < 10)
{
echo $x;
$x++;
}

Now we come to spaces. Operators and their operands should always be separated by a space. UNIX shell scripters can make an exception to this of course, but otherwise you should space things out:

//All of these are OK
$x = 10;
$y = 5;
$z = $x + $y
$z *= 2;

//These are not OK
$x=10;
$y=5;
$z=$x+$y++;
$z*=($z+$x)--; //I can't even tell you with this is equal to

Duplicate Functionality

The only thing worse than editing your terrible code, is doing it twice. If you find yourself using copy and paste, or otherwise coding the same functionality multiple times, for the sake of anyone reading your code please stop. Not only is this going to translate into a bad experience when it comes time to update your code, but its also likely that whatever mistakes you made the first time you wrote the code were duplicated.

Yesterday I installed a WordPress plugin. The plugin performed well, and for the most part I was happy with it. Of course, however, there were modifications I needed to make (including as it turns out rewriting the code to make it conform to the XHTML standard). Once I opened the file to make the changed I was horrified to discover that there were literally zero functions or objects. If something needed to be done twice, the code was copied. Unfortunately the writer of the plugin forgot to close a div, which is an honest mistake. What isn’t an honest mistake, and should be punishable by death by CRT monitor thrown at you, is taking that code, and copying it three times (error included) to perform the exact same task.

Manageability

That same file I just mentioned contained over 5000 lines of code. I don’t care how large of a project it is, your code should never exceed 1000 lines. Of course, in this case, the programmer decided not to use any functions so there was no logical way to break up the file. If you, on the other hand, are not out of your mind, any significant amount of code you create will contain many functions. Most likely those functions can be categorized and placed in separate files. If you want to get fancy you can even use some objects. The important thing is that the code you write isn’t in blob form.

The same concept applies to individual lines of code. Once again refer to the plugin I had the displeasure of modifying, the longest line in that file was 549 characters long. If I can’t see an entire line of code with scrolling on a widescreen monitor then there is a problem. Really, even using a fullscreen monitor you should never have to use the horizontal scroll. There is nothing wrong with using the return key in the middle of a line of code.

//NOT OK
$animalCount = array('cat' => 5, 'dog' => 2, 'bird' => 7, 'mouse' => 3, 'badger' => 0, /* we don't need no stinking badgers */ 'chicken' => 4);

//OK
$animalCount = array(
			'cat' => 5,
			'dog' => 2,
			'bird' => 7,
			'mouse' => 3,
			'badger' => 0, //we don't need no stinking badgers
			'chicken' => 4	);

Comments

The final portion of my rant regards commenting your code. This is something we’ve all been guilty of at some point. I don’t care how well written your code is, most likely I can’t tell what it does at first glance. If you define a function, write a few words about what that function does. If you do something that seems out of the ordinary, at the very least write down that you did that intentionally.

I wrote some code a few days ago and it contained a switch statement. I intentionally did not use a break in one of the cases because the following case needed to be performed as well. To someone glancing at the code, however, this would seem like a bug, they would add a break statement and introduce a new bug when they thought they were fixing a bug.

Use comments!

Seamless WordPress bbPress Integration

If you’ve ever installed bbPress you know that it supports several different levels of integration with an existing WordPress blog. By default you can integrate cookies, users, and even have access to WordPress functions. After all of this, however, the user will still experience two independent applications. Most likely the themes you are using were not made with each other in mind. This doesn’t have to be the case, and if you’re willing to get your hands dirty you can get your bbPress installation to look and feel as if it is entirely a part of WordPress. Here is an example of what this looks like: Example.

To begin, you will need to install (or modify) bbPress with full WordPress integration. This means cookie, database, and functional integration (add require_once(‘path/to/wp-blog-header.php’); to your bb-config.php for functional integration). I did this with WordPress 2.7.1 and bbPress 1.0 alpha, however, if you prefer to use the stable version of bbPress, you can find information on how to do this Here.

Once everything is installed its time to get your hands dirty. To go further we’re going to have to make a few changes to the code. Locate your theme directory. I used the default Kakumei theme. Keep in mind that a large portion of your bbPress theme is going to be stripped out (header, footer, sidebar) so don’t spend to much time selecting a theme. After you locate the directory of your current theme, you’ll need to do a search and replace through every .php file in your theme. There are several files so I suggest you use a program to do this for you; Notepad++ allows you to search and replace across multiple files.

You’ll need to do two searches:

Find:

bb_get_header();

Replace with:

global $is_bb; $is_bb = true; get_header();

get_header(); will cause bbPress to use WordPress’ header as opposed to its own. I added the additional code global $is_bb; $is_bb = true; you’ll see why later. You’ll need to do the same thing for the footer as well.

Find:

bb_get_footer();

Replace with:

get_footer();

Now that that’s done, upload the files and take a look at your forum. You should see the body of your forum embedded inside your wordpress theme. You should also notice that your forum looks pretty terrible. Don’t worry we’ll fix this in the next step.

What we need to do next is tell your wordpress theme to use your bbPress stylesheet if we are viewing the forum. This is where that additional code I added comes in. In your WordPress theme’s header file add the following lines before the first stylesheet is linked (ie before the first <link rel=”stylesheet”…):

<?php global $is_bb; if($is_bb) : ?>
	<link rel="stylesheet" href="[path to bbPress theme stylesheet]" type="text/css" media="screen" />
	//add additional stylesheets if needed
<?php endif; ?>

Make sure to replace [path to bbPress theme stylesheet] with the path to your current bbPress theme’s stylesheet.

If you look at your forum now, you’ll probably see a terrible mess. This is because your WordPress style sheets and your bbPress style sheets conflict. If you didn’t use the default theme you’re on your own for altering your bbPress stylesheet. Make sure you remove any elements that are directly conflicting with those in your WordPress theme (ie header, sidebar, footer elements). You’ll also want to look out for any position, and float attributes. You may also need to remove the width attribute for your forum body.

If you did use the default theme or the blue version of the default theme, you can use the stylesheets that I’ve already altered. I don’t promise that they are bug free, but they’re working well for me so far.

Kakumei
Kakumei Blue

Make sure to rename them to style.css.

Now that you’ve altered your stylesheet, everything should look good. You arn’t done yet, however. Most likely all of your bbPress navigation (ie login, admin panel, logout) buttons are gone. If you correctly integrated WordPress cookies login and logout shouldn’t be a problem. To replace any links that were lost, code them directly into your WordPress theme, using the $is_bb variable to only display them on the forum.

Good Luck!

Update:

There is an issue with slashes being added to edited posts in bbpress. I think this is being caused by both wordpress and bbpress escaping content and then only bbpress unescaping it. In any case this is how I fixed it (its a bit of a hack) in bbpress 1.0.2:

  • You’ll need to edit the file bb-includes/functions.bb-template.php (I think in earlier versions its called template-functions.php).
  • Locate the function definition get_post_text. In bbpress 1.0.2 it looks like this:
    function get_post_text( $post_id = 0 ) {
    	$bb_post = bb_get_post( get_post_id( $post_id ) );
    	return apply_filters( 'get_post_text', $bb_post->post_text, $bb_post->post_id );
    }
    
  • Change it to:
    function get_post_text( $post_id = 0 ) {
    	$bb_post = bb_get_post( get_post_id( $post_id ) );
    	return stripslashes(apply_filters( 'get_post_text', $bb_post->post_text, $bb_post->post_id ));
    }
    

I’ve also heard of an alternative solution. All you need to do is comment out the following line in wp-settings.php:

$_POST   = add_magic_quotes($_POST  );

In wordpress 2.9.2 it is on line 632. I personally have not tried this solution and I'm a little weary of it; it might have some unexpected side effects (namely POST data not being escaped, possibly exposing you to SQL injections).

If anyone has a solution that does not involve editing core files I would be very interested in hearing about it.

Feedback

After the release of SimpleMail I immediately experienced a problem that I imagine is shared by many developers: lack of feedback. Though I greatly appreciate all of the comments, suggestions, and bug reports (especially the bug reports) I know that for every one person that experienced a problem and reported it, five people experienced a problem, uninstalled the plugin and never thought about it again.

I found myself constantly worried about the bug reports I was not receiving, and in fact there were bugs that had existed since the original version that went unreported until recently. This was a learning experience of course and I have since taken steps to ensure that any application I release in the future is more robust. In addition to this I think that having experienced all of this I am must more likely to report issues I am having with any piece of software. I strongly encourage anyone reading this to do the same.

As I mentioned this was a learning experience, so I’ll offer some tips to developers so they don’t make the same mistakes I did:

  • Test your applications in multiple environments
  • Maintain portability in your code
    • Read the documentation for whatever feature, function or library you are using to ensure that it will work on whatever platform you expect it to
    • Don’t use language features that are not necessarily enabled or available to all users (ie PHP short tags)
  • Make providing feedback easy
    • Add a link, button, or form to your application that either directs the user somewhere where they can provide feedback or allows them to send feedback from the application itself

EverythingDev

As I mentioned in a few previous posts, I am interested in finding tech writers and starting a group blog. The site is now up, though it is somewhat lacking in content (partially because I am still searching for writers).

You can find information on how to apply to be a writer on the site: EverythingDev.com

WordPress Plugin: AdShare

I’ve just released my second plugin.

This one I created more out of necessity rather than interest. As I mentioned in a previous post I’m interested in finding tech writers to work on a group blog with me. The purpose isn’t to generate ad revenue, but it couldn’t hurt if we did. In the interest of fairly distributing any ad revenue, I wrote a plugin that displays ads based on the author of the current post. And that’s the story behind AdShare…

Give it a try and tell me what you think.

UNIX Life Lessons

Quoting my professor:

When a parent forks a child it waits for it to exit.

If you don’t find this funny it is because

  1. You arn’t familiar with UNIX
  2. Your sense of humor isn’t that of child

Looking for Writers

I’m interested in starting a programming and development blog. Rather than going it alone as I am with this blog, I’d like to have a few writers working with me to generate new content. I will be providing the domain and hosting (I’m in the process of setting up the new site now). Requirements are as follows:

  • Strong writing and communication skills (in English)
  • Interest in web development, programming, or computer science
  • Able to post new content semi-regularly (I’m stressing new here, I’m not interested in copy and paste jobs)
  • Able to provide a sample of your writing

Notice that I don’t require you to be an expert in any particular field. If you are in the process of learning a new skill and want to write about your experiences that is fine. Some experience, however, is necessary. Contact me if you are interested.

By the way…
The reason I am setting up a separate blog is so that I can focus more on personal projects and activities on this blog.