Wednesday, June 27, 2007

My First Metaprogramming

I just did my first metaprogramming in Ruby and it got my heart beating fast, thinking about the possibilities.

module ApplicationHelper
ApplicationController.class_eval do
layout "standard-layout"
end
end

This makes all ApplicationControllers use the layout "standard-layout", defined from a central location. The source of this string could be anything from a cookie to preferences stored on a model object, and obviously one would probably not apply it to ApplicationController indiscriminately; but the concept is fun :)

Anoter example would be for a routeless static content controller:

class StaticController < ApplicationController
def method_missing(action)
render :action => action.to_s
end
end

This basically emulates having a method defined for any that is called and renders a template of same name using the rhtml file in the views directory. Again, maybe not the best way to have static content, but it's a fun idea.

That is one thing that scares me about metaprogramming--without discipline and a concept of what's best vs. what's cool, an app can become hell very quickly.

Tuesday, June 26, 2007

Grails (Groovy on Rails)

Last night I attended the MN Ruby Users' Meeting. The topic of interest for me was Groovy on Grails, a Rails-inspired framework for the Java platform based on Spring, Hibernate, Ant+Ivy, SiteMesh and of course Groovy.

Groovy is a dynamic language that compiles to Java byte-code (unlike JRuby in its current state), and some of its most interesting features are closures and its ability to be used as a DSL. It also appears that there is a DSL for Ant, which I would guess is very Rake-like.

The advantages of using Grails over Rails are real: many companies have existing Java infrastructure that they can not afford to simply throw out or run side-by-side with another infrastructure--not even Google will run Rails. There may also be the requirement of transactional (JTA/XA) support, or the need to interact with legacy services using via ESB. As I've explored before, some of these things can indeed be used from Rails using the Java/Ruby Bridge, but that solution does not "seem" like it would hold up well in a high volume application (I've never done any stress testing, prove me wrong); though this still adds the burden of running two infrastructures side by side.

So why not just stick with Servlets or Struts? As Scott Vlaminck put it in his presentation: the "let's knock this this shit out" attitude of the Rails community is coming onto the radar of 'enterprise' project management, and they want a piece of the uber-productivity pie that Rails boasts.

Now if only we could convince them to use the time they'd save to give their developers five day weekends, or 150% raises :)

Monday, June 25, 2007

Tickler Action File

A post on LifeHack today described a possibly more efficient variation of a Tickler file. Rather than sorting by day, they suggest sorting by action. I agree completely and just started using a similar approach last week. I use Outlook tasks with the Categories field, and a Group By in the view. The result looks like this:


It supports multiple categories (works the same as tagging), due dates, reminders and attachments. I can attach emails by reference or by value, and even "assign" the task to other via email if I need to. The copy machine also supports scanning documents to e-mail, which fits into the mix in perfectly. So-far it's working out quite nicely.

Rails with SQLite

It is ridiculously easy to setup SQLite with Rails. So, I recommend it for n00bs just experimenting with Rails over PostgreSQL. My choice to try it out was based mostly on the fact that I have a locked down workstation at my job, and that PHP ships with it installed by default [1][2] (so it must be decent). It's to be determined whether I would run any class of production application using it for primary storage, but with Migrations it doesn't really matter since the DDL is not DBMS specific.

Update:
I ran into this issue and had to change ownership of both the db file and the containing directory to www-data.

Tuesday, June 12, 2007

Working With Money Using Floating Point Numbers

While it seems like a n00bish lack of knowledge on my part, today I was told by a colleague that working with money using floating point numbers is Bad, mmm-kay. Curious and skeptical, I did a quick Google search and learned why this is true. It turns out that the IEEE 754 specification for floating point numbers makes them a poor option. Don't get me wrong, this is not a flaw or oversight on their part--floating point operations are designed for use with large number where magnitude and speed are more important than precision. One can think of them as "a computer realization of scientific notation." I can blame only myself :)

I thought this would be common knowledge among CS graduates, but was surprised to learn that many I know had no idea. Perhaps people have just not made the connection between what they learned in school (anything?) and the application of money. Even at my job, the commercial framework we use has a Money implementation that uses double (64-bit floating point) values internally. This is being addressed by a colleague :)

As far as other languages such as PHP and Ruby are concerned, I was not able to reproduce the results given in the Java article with a 1:1 port; they do, however, use floats internally for decimal calculation. I have experienced similar issues in the past with PHP, and the PHP manual does warn against using floating point numbers where any sort of precision is required (which I had never read before).

As an alternative to floating point values for working with decimals, Java (and here) and Ruby offer BigDecimal implemenations, and PHP offers BCMath.

Monday, June 11, 2007

Project Management as a Social Issue

Just because I've been busy for a while and haven't had time to write, here's some blog-o-spam for you; comments on an article I read today.

Here's an interesting article I came across on Reddit. It basically talks about how all the information needed to decide that a project is off track is in the heads of developers and testers, but due mostly to social or political factors and partly to methodical shortcomings (overall bad communication), it never makes it up the chain. Rather than relying on a rigorous process and reports, gathering the information can be as simple as the project manager periodically asking people for their thoughts on the project's goals--concerns they may have, etc. But of course the manager has to be receptive to concerns of people and willing to do something about them (even if it means changing from proverbial "green light" to "red light").

I've seen other good stuff from this blog as well.

full article: http://coderific.com/blog/post/590

Saturday, June 02, 2007

Hacking on the Facebook Platform

I've been toying with the Facebook Platform the the past few days and am impressed by it thus far, minus the lack of documentation and usage examples. I created a base class to extend applications from in order to get a feel for how application are structured. It is based after the only coherent piece of documentation I have been able to find, here. I will publish my code soon; in the mean time, here is an example:


class FacebookApplication {
...
function get_friends_with_app_installed() {
$fql = "SELECT uid from user where uid in (SELECT uid2 FROM friend WHERE uid1=".$this->get_client_id().") and is_app_user=1;";
return $this->get_client()->api_client->fql_query( $fql );
}
}

class LookMiiUpFacebookApp extends FacebookApplication {
...
function splash() {
echo "lookmiiup splash";
print_r( $this->get_friends_with_app_installed() );
}

function set_info() {
$wii = strip_tags($_REQUEST["wii"]);

$facebook = $this->get_client();
$user = $this->get_client_id();

$facebook->api_client->profile_setFBML("Wii Number: $wii", $user);
$facebook->api_client->feed_publishActionOfUser( "got a new Wii number", "$wi
i" );

echo "wii: $wii";
}

function handle_request() {
static $allowed_methods = array(
"set_info"
);

if( in_array( $method, $allowed_methods ) ) {
$params = array();
call_user_func_array( array( $this, $method ), $params );
} else {
parent::handle_request();
}
}

}

$fbapp = new LookMiiUpFacebookApp( $appapikey, $appsecret, $appcallbackurl );

$fbapp->require_login();
$fbapp->require_installation();

$fbapp->handle_request();


The added value is the ability to more intuitively (in my opinion, anyway) create an application that requires login/installation and setup the handler methods. I plan to use it, with Smarty for FBML generation, to integrate LookMiiUp into Facebook.

Friday, June 01, 2007

Where are the comprehensive enterprise test suites?

Note: this post is a work in progress.

For the past several weeks I have been thinking a lot about automated testing as part of the development process. While I have had faith in software testing for some time, I guess I have never really had a reason; the systems I worked on prior to my current position were minuscule and honestly, the tools used were overkill and most effort put into testing was wasted. That isn't to say that small scale applications do not need testing. The problem is, the majority of small scale applications do not have the infrastructure to make testing an integral part of the development process, rather than an after thought in the release process. That delivers tests that are patchy at best, and really only deliver superficial results. Perhaps this in itself is a case for Ruby on Rails.

While I was initially very skeptical about Rails, I am slowly becoming a believer. But better than believing, I am thinking that it has promise. What's turned me into a believer is a combination of observation and experience--the haphazard testing situation of HM, discussions with fellow senior HM developers that allude to the situation being equally as bleak in similarly sized applications, a pile of resumes I reviewed which showed an utter lack of testing experience, the lack of available end-to-end testing tools for .NET and Java, etc. All of these things embolden the out-of-box testing strategy of Rails.

While I haven't done any research on the matter, I sense a large void in serious testing tools in "enterprise" platforms (both Java EE and .NET, surprisingly). There are some great testing tools for Java, and I'm sure equally great tools for .NET, there is a lack of a comprehensive suite like that of Rails.

I think the issue with .NET is the junior role that is assumed of developers. While the bulk of developers are junior, I have found in my short stint as a mentor that they can do anything as long as there is a comprehensive API and/or procedure for them to follow. And the issue with Java EE is simply the fact that tools like DbUnit, Selenium, JWebUnit, Cactus, etc are all open source and there have been few attempts to glue them together into a coherent testing strategy (one notable exception is DDSteps).