Programming

On that moron feeling

Posted by Dallas on July 18, 2009
Programming / No Comments

This is a re-post of a blog written by Brent Simmons http://inessential.com/2009/07/17/on_that_moron_feeling. I am re-posting it as it is a great post.

I was a moron five years ago. Five months ago, even.

I’ve heard this from other programmers, so I don’t think I’m alone. They look back at old code they wrote and say, “What idiot wrote this crap?”

I used to wonder if this feeling would ever go away — as if I’d just get to the point where I’m super-awesome and that’s it.

But over the years I’ve learned to rely on this feeling. Were it ever to go away, then I’d be worried like hell. It would mean I’m not learning and not improving.

So, yes, I’m proud to have been such a moron so recently.

Getting Pretty Lonely

Posted by Dallas on July 02, 2009
Programming / No Comments

Post by Daniel Jalkut of Red Sweater Software – http://www.red-sweater.com/blog/825/getting-pretty-lonely. Reposting since Daniel’s site is currently overwhelmed.


This very post is delivered to your browser or news reader by the famous and fabulous WordPress blogging system. In my work as the developer of MarsEdit, I am exposed to countless blogging options, each with its own strengths and weaknesses. And yet, I stick with WordPress because it strikes a balance of power and ease of use which feels comfortable to me. Not to mention that Joseph Scott and others are tirelessly working to improve its API.

WordPress is licensed under the terms of the Gnu Public License (GPL) which, in a nutshell, stipulates that you are free to use the software however you like, but if you make changes and distribute those changes, then you must share those changes under the same terms. This simple, radical restriction means that you are prohibited from taking a GPL project and incorporating it with a closed-source project.

Violating The GPL

Violating the GPL is easy. All you have to do is write some code, intermingle it with some GPL code, distribute a changed copy of the original, and refuse to share your contributions. Bam! You’re toast. Assuming the original authors discover your violation and decide to pursue a resolution.

Once a violation occurs, it might be settled privately, or could escalate to legal court procedures. But the most obvious form of resolution is for the author of the changes to release their code to the public under the terms of the GPL.

Depending on how much code you “mixed” with the GPL code, this could mean only a small portion, or it could mean the entire source code of your project. This so-called “viral nature” of GPL is what scares the bejeezus out of companies, large and small, who fear the consequences of having to give up their own intellectual property to the public.

The terms of the GPL sound pretty simple at first read, but due in part to the epic consequences of a violation, there has been a great deal of debate and uncertainty about what legally constitutes a violation. Most of the debate seems to boil down to two questions:

  1. What counts as a change to the original product?
  2. What counts as distribution of those changes?

If you can legally justify that your additions to a GPL project either don’t change or derive from the original product, or haven’t technically been distributed, then you are not subject to the restrictive terms of the license.

Take GIMP, the popular GNU-licensed image editing application. The application supports plugins, analogous to the types of plugins you might find for the commercial, closed-source application Photoshop. A savvy developer may argue that a plugin doesn’t meet the criteria of changing the original application, because the original application still runs in its unaltered condition whether the plugin is there or not.

But promoters of the GPL take the position that plugins, by nature of being loaded into the same code space as other GPL code, do constitute a modification of the original, and are therefore subject to the terms of the GPL. As far as I know this is not a question that has been well-tested in courts.

Let me take a moment to make this abundantly clear: I respect the rights of authors to license their software under whatever terms they choose, including the GPL. In my opinion, all the legal mumbo jumbo ceases to matter once the original author’s intentions are made clear. So if the author of GPL-licensed code clarifies to me that it cannot be run on Sundays, then their GPL means it cannot be run on Sundays. But this is one of the problems with the GPL: its terms are not often understood, even by the authors of GPL-licensed code.

WordPress Themes & Plugins

WordPress supports two explicit forms of extension, each of which may affect the appearance and functionality of the product. Themes tend to work as a “skin” for the appearance of a blog, while plugins tend to introduce completely new features. Since plugins in WordPress are analogous to GIMP or Photoshop plugins, it would stand to reason that they would also be covered by the terms of the GPL. But what about themes?

Themes have been controversial in the WordPress community, as a few commercial business models have sprung up to take advantage of bloggers’ desires for high quality themes at an affordable price. One approach is to distribute “free” themes that contains commercial ads. So you might stumble upon the perfect theme for your blog, only to learn that the glaring “Brought to you by Hostess Cupcakes” line near the bottom of your page cannot be removed.

But the terms of the GPL, if themes are covered, would require that end users be granted the legal right to modify and redistribute their own copy of the theme. Zap the sponsorship, reupload to your site, and you’ve got a free, high quality theme with no ugly ads.

Today, Matt Mullenweg of the WordPress project announced his lawyer-supported opinion that themes are partly covered by the GPL:

I reached out to the Software Freedom Law Center, the world’s preeminent experts on the GPL, which spent time with WordPress’s code, community, and provided us with an official legal opinion. One sentence summary: PHP in WordPress themes must be GPL, artwork and CSS may be but are not required.

If you’re starting with the understanding that WordPress itself is GPL, and WordPress plugins are GPL, then it’s not so much extra hay on the camel’s back, to also clarify that its themes are to some extent GPL. But it got me thinking again about my own blog, and about the restrictions the GPL imposes on the kinds of things I can do with the software that runs it.

GPL Stifles Participation

Now for the most controversial point of this article, where I suggest that the GPL does more to harm collaborative development than it does to help it.

For the purposes of this argument, let me reduce all the source code in the world down to three rough categories. I recognize I have omitted some classes of license here, but for the sake of argument, most projects fall into these camps:

  1. GPL code. Changes may be distributed only in other GPL products.
  2. Liberal-licensed code. (MIT/BSD/Apache/etc). Changes may be distributed anywhere. Appropriate origin-attribution may be required.
  3. Closed-source code. May be distributed only by the copyright owner and other explicit licensees.

Now, there are a few people in the world who, for political or philosophical reasons, will only participate in a GPL project. And for compariable yet opposite reasons, there are some who will only participate in commercial, closed-source projects. But I propose that the vast majority of developers will participate in any project that is advantageous to them.

So let’s imagine a representative, run-of-the-mill developer who is working on a project that falls into each of these three camps. If this developer is not radically committed to their own project’s license, they will naturally look to outside resources in order to bolster the success of their own work.

As the developer evaluates communities to participate in, they must evaluate the legal impact such participation will have on their own project. The closed source communities are, by definition uninviting to outsiders. GPL communities are open and embracing of other GPL developers, but generally off-putting to liberal-license and closed-license developers. Only the liberal-license communities are attractive to developers from all 3 camps.

I know what some of the GPL-enthusiasts are thinking now: “leeches don’t count as community.” Many GPL developers take comfort in the fact that their hard work can’t be quietly taken and incorporated into a commercial product, without any payback of time or money to the original project. But you’re piloting an open source project, and the first step of building a community is to get people in the door. Liberal licenses? Whoo-eee do they ever get people in the door.

If you operate from the presumption that great developers love to build great projects, the first step in any successful open source project is to get as many great developers in the door as possible.

It’s Your Party

Yes, this is just me and my crazy theories. I haven’t done exhaustive research to prove that liberal-license communities thrive more than GPL communities. But the anecdotal examples are staggering. The very foundation of Mac OS X, the operating system through which I’m typing, is thanks to the liberally-licensed FreeBSD operating system.

Looking over to the right of my screen, I’m watching this sentence appear in a live web preview as I type, thanks to the WebKit project, whose liberal license makes it compatible with closed source projects such as Safari, as well as open source efforts such as Google’s Chromium project.

For years, the problem of a generic HTTP client library that runs on every major platform has been addressed by libcurl, whose liberal license has caused it to be embraced by countless companies and projects.

The popular Subversion source control system’s liberal license enabled Sofa, a commercial software business to contribute value to the community with its extremely polished, award-winning client application. Meanwhile, the newly popular distributed source control systems presents three major choices: git, Mercurial, and Bazaar. All are restrcted by the GPL-license, and therefore none is likely to inspire development of a Versions-caliber client.

I’ve touched the tip of the iceberg, and yes I’ve neglected to mention some GPL success stories such as Linux, MySQL, and gcc. These communities have thrived to some extent because the passions of the GPL community are strong, but we can’t know whether their success is in spite of the restrictions their license places on participation by the broader developer community.

Speaking of GPL succeses, WordPress is itself an example of monumental success. All of its developers have something to be immensely proud of. But whenever I am reminded that WordPress is GPL, my passion for it takes a bit of a dive. I’m more comfortable with the true freedom of liberally-licensed products. If a liberally-licensed blog system of equal quality, ease of use, and popularity should appear, my loyalties to WordPress would not last long.

It’s your party, and you’re entitled to write the guest list. But take a look around the room: not as many folks as you’d hoped for? Liberally-licensed projects are booming. Speaking for myself, a developer who has been to all the parties, I’m much more likely to pass through the door that doesn’t read “GPL Only.”

Tags: ,

WWDC 2009

Posted by Dallas on June 21, 2009
Apple, iPhone, Mac, Personal, Programming, WWDC / No Comments

I have been back from WWDC for a little over a week now, but haven’t had a chance to say anything about it or post any pictures. (I will post an explanation shortly)

WWDC (Apple’s World Wide Developer Conference, in case you don’t know) was amazing!
This was the first time that I have been able to justify going (it’s not cheap) but man was it great.

I had the chance to meet so many amazing people that I talk to all the time on Twitter, but now I got the chance to meet them in real life.

Besides all the great developers and parties, it was a chance to learn about new and upcoming enhancements to the Mac operating system and the iPhone, as well as learn the best way to do certain things in code, coming from the people that write the language!

Apple also offers what the call labs during WWDC.
Labs allow you to take your code and sit down with an Apple Engineer that works on whatever particular topic you want, and they are there to serve. They will look over code and tell if you how you could have done it better, or they will help you debug an issue you are having, or anything else.

There is so much information flying at you all day that it can be overwhelming at times.

And when the sessions and labs end each day, WWDC does not end….
I have never seen more back to back, double/triple booked parties in my life.
Parties that go until all hours of the morning.

So with sessions and labs all day and parties all night, by midweek you are the walking dead but it doesn’t stop the fun. (and I didn’t even go out every night!)

Around the end of the week Apple throws a big party and this year had the band ‘Cake’ come and perform.

Overall it was a GREAT time and I can’t wait until next year, yet it is always nice to come back home to family as well.

We are talking about Nancy coming along next year and being able to tour San Francisco while I am in the sessions.

My WWDC 09 Photos – http://www.flickr.com/photos/kdbdallas/sets/72157620059169940/

SDC10044

Tags: ,

Coming Soon to a Bookstore Near You

Posted by Dallas on May 05, 2009
Apple, Cocoa Touch, iPhone, Objective-C, Personal, Programming, SDK / No Comments

I have been offered a gig of being the Technical Editor for an upcoming iPhone programming book.

The book is called “Cocoa Touch for iPhone 3.0″ and is being written by my friend Jiva DeVoe and published by Wiley and Sons Publishing.

You can visit the current pre-emptive webpage for the book at: http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470481072.html

I was previously a Technical Reviewer for the programming book: iPhone SDK Application Development, 1st Edition

It will be interesting the see the differences between being a technical reviewer and a technical editor.

Tags: ,

Submitted to App Store

Posted by Dallas on March 06, 2009
App Store, iPhone, Programming / 1 Comment

A while back I wrote another iPhone application that was mainly for myself, but the business side of me said, “If I wanted this app enough to write it, chance are there are people willing to pay a couple bucks for it.”

The down side of this was that I had to develop the application a lot more.
Instead of just having to be “enough” for me, it had to be complete enough to sell and for people to be able to easily use.

So I finished up making it great.
It was done and it was SEXY!

The problem…
The sexy part was the part that connects to your computer, and that part was Mac only.

I did not like the fact that it was Mac only because I knew it would really hurt sells.
So I bit my lip and went about redoing that entire section.
I wanted something that would feel familiar with but that was at least just homely looking instead of looking like a nasty skank.
The problem was that the way to do this was a pretty big undertaking as there was nothing standard for the iPhone and the doing a one-off is a huge task (hence why there is nothing out there).

Finally I found another developer who was in the final status of doing a one-off himself, and he agreed to let me have access to the code.

SWEET! Here was my answer, right? right?

So I went and integrated the code.
Problem was that the code was not complete, but that was alright because I still had a bunch of little things to finish up and I was under the impression that the other code would be finished shortly.

So I finished everything up, but still no updates on the other code…
CRAP!

So I started looking into the code to see if I could find where the problems were, but like I said before, this is a BIG undertaking of code and I had no insight of the under workings of that section.

However now all my code was done, so I needed this last part done.

Off and on I would spend a day or two digging into the code, and hitting up the developer for any word on updates.

Now 2 months after I finished my end, I was still in basically the same spot and still no word on anything anytime soon.

Finally last night I said, “screw this”, and I decided to go with the Skanky version for now, knowing that I could always go back if/when the other code gets finished, but just sitting here was doing no one any good.

Earlier today I finished the coding aspect of the new setup.
Then I just had to do a screencast help video and do all the paper work type stuff on the App Store.

Then it was off to the races!
Application SUBMITTED!

Now it’s just time to hope that it gets through the Apple review process, and quickly.

Oh and to be honest, this new way probably isn’t really Skanky, but it just kind of feels that way to me after my original design.

KidFlix in Review

ChocTop

Posted by Dallas on March 01, 2009
Cocoa, Objective-C, Personal, Programming, Programs / No Comments

I have been finalizing the beta for iDeskCal 2.0 and in the process came across ChocTop.

ChocTop is a system for rapid mac software DMG packaging.

In setting it up and using it I found that it lacked a feature I wanted.
Mainly the ability to specify that it should you a Debug build instead of the standard Release build that you would usually use.
The reason for wanting a Debug build is simple… I am packaging up a Beta.

So even though I don’t know Ruby (which is what ChocTop is written in) I set foot to add this feature.
Luckily like most computer languages I was able to understand it enough to understand what was going on and enough to add this new ability.

Once I was done and used it myself, I sent it back into the developer and he has already integrated it into the repo version of the code.

If you are a Mac developer checkout http://drnic.github.com/choctop/

Log all accessed methods in Objective-C with DTrace

Posted by Dallas on February 07, 2009
Cocoa, Cocoa Touch, DTrace, iPhone, Mac, Objective-C, Programming / No Comments

I have recently been debugging some Objective-C and Cocoa/Cocoa Touch code.

Not being familiar with all the code and with a TON of methods being accessed in milliseconds, my attempts at stepping through the code just wasn’t working, as clicking ‘Step Into’ as fast as I could keep up and over an hour of stepping through I was still not even close to figuring out what I needed to know.

This lead me to the thought of logging every method that was accessed and then I could step look through it and skip around as needed.
However with 60 some odd files and say maybe 20 methods in each file, that would take a lot of NSLog’s.
I started looking around and was pointed to bbums blog about doing something similar.
However it still would take adding some code, plus I couldn’t get it working right with the iPhone.

This lead me to wonder about DTrace.
After a recent podcast from Scotty at the Mac Developer Network, featuring Colin Wheeler talking about DTrace, I have been very interested in learning more about DTrace.

The difficult thing I have been finding is that since DTrace was originally written for Sun, it is hard to find info related to MacOS and more so Cocoa.

I then found a video from Colin about using DTrace with Cocoa and XCode.
http://www.viddler.com/explore/Machx/videos/8

I wasn’t able to get what I wanted working, so I hit Colin up on Twitter and then talked to him a bit in email and he pointed me to the Golden Solution!

The solution is:
objc$target:::entry{}

So I took that and created a DTrace script.
You can grab it here:
http://kdbdallas.com/wp-content/uploads/2009/02/logallmethodsd.zip

To run it open Terminal and run:
sudo ./logAllMethods.d -p PID

Of course replacing ‘PID’ with the PID of your running program and remembering that for DTrace ‘sudo’ is required.

Also note that this works for iPhone programs running in the iPhone Simulator.
Just look for the PID of your iPhone app within Activity Monitor once it’s running in the simulator.

Be careful as depending on the program it can spit out a TON of data VERY quickly.

Running this against Adium for only a fraction of a second gave me a couple hundred lines of output.

The output looks like this:

tesseract:Desktop dallas$ sudo ./logAllMethods.d -p 4371
dtrace: script ‘./logAllMethods.d’ matched 71222 probes
CPU ID FUNCTION:NAME
0 59398 -retain:entry
0 34684 +retain:entry
0 32061 +idleAllMovies::entry
0 32062 -idle:entry
0 34707 -retain:entry
0 32914 -_usingVisualContext:entry
0 32878 -_resyncNaturalSize:entry
0 31935 -loadState:entry
0 31972 -naturalSize:entry

Hopefully this helps someone out there.
Just remember always use the info I post for good.
(or if its for evil make sure it profitable and then send me a cut)

Once again, special thanks to Colin Wheeler.

Tags: , , , , ,

White Indeterminate Progress Indicator (AKA: White NSProgressIndicator)

Posted by Dallas on December 28, 2008
Cocoa, Objective-C, Programming / 1 Comment

If you have ever wanted to use a Indeterminate Spinner NSProgressIndicator on a dark background you have probably been upset to find that there is no way to get a white spinner.
That is where WhiteIntermProgIndicator comes into play.
WhiteIntermProgIndicator, is based off of AMIndeterminateProgressIndicatorCell by Andreas at Harmless Cocoa.

Screenshot:
whiteintermprogindicator

Download: WhiteIntermProgIndicator.zip

Tags: , ,

Mac/iPhone: Show Available Usable Disk Space

Posted by Dallas on December 27, 2008
iPhone, Mac, Objective-C, Programming / 7 Comments

If you have an application that allows users to upload content to the app, you might want to show the user how much space is available for them to use.

This is especially true on the iPhone where it is not as easy for the user to quickly check if they have enough room to upload a given file.

You may also want to check if there is enough space before you start the upload, so you can inform them that the file wont fit.

That brings you to the task of figuring out how much free space there is, and more importantly how much free space is left that you as an unprivileged program can access.

The following code is based towards the iPhone, however all that would be needed to change it to be used on the Mac is the location you are checking for free space, and the setting of the label.

NOTE: The below “shown” code is old. The updated code is in the zip file at the bottom

#include <sys/param.h>
#include <sys/mount.h>
NSString *sizeType;
 
float availableDisk;
 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 
struct statfs tStats;
 
statfs([[paths lastObject] cString], &tStats);
 
availableDisk = (float)(tStats.f_bavail * tStats.f_bsize);
 
if (availableDisk > 1024)
{
	//Kilobytes
	availableDisk = availableDisk / 1024;
 
	sizeType = @" KB";
}
 
if (availableDisk > 1024)
{
	//Megabytes
	availableDisk = availableDisk / 1024;
 
	sizeType = @" MB";
}
 
if (availableDisk > 1024)
{
	//Gigabytes
	availableDisk = availableDisk / 1024;
 
	sizeType = @" GB";
}
 
diskSpaceLbl.text = [[@"Available Disk Space: " stringByAppendingFormat:@"%.2f", availableDisk] stringByAppendingString:sizeType];

This will give you something like the following:

availablediskspace

UPDATE:
I have gone a step further and made this into an easy to use class, that works out of the box with the iPhone and the Mac.

FSStats.zip

Tags: , , , ,

Pi Presentation: SQLite

Posted by Dallas on December 04, 2008
Cocoa Touch, iPhone, Objective-C, Programming, SDK / No Comments

Last night I gave a presentation at the Phoenix iPhone Developers Group (Pi) on SQLite.

I am posting the presentation and sample code here for anyone who is interested.

Please note that this is by no means the “proper” or only way of doing things. This is simply one way of doing it, and is for reference purposes only. The code uses the FMDB SQLite Wrapper.

Example Code: (example.zip)

Keynote Presentation (sqlite-presentation.zip)

Tags: , , ,