Strict typing is good mkay
Posted by Cliff
I’m currently in the final stages of a refactor and I thought I’d just share this little tidbit on why strict typing is a good thing in AS3, especially when working in an agile environment where things can change quickly as requirements unfold and mutate.
Let’s say you’re working with data via AMF, and you have a Project value object with the properties ‘id’, ‘name’ and ’status’.
public class Project {
public var id:Number;
public var name:String;
public var status:String;
}
In no time at all the rest of your code will be littered with references to these properties, and obviously if any of these properties changes during refactoring will be instantly picked up by the compiler. No biggie refactoring those. But there are instances where changes can slip under the radar.
For example (examples are always good), take a look at this snippet:
private function on_result(event:ResultEvent):void {
this.status = event.result.status;
}
See the subtlety? In this instance, event.result is an
Object, which is dynamically typed. Therefore accessing erroneous properties will not be picked up by the compiler, and this ultimately leads to subtle, frustrating bugs and loss of hair.
To avoid this, ensure you type cast dynamic objects to their appropriate types before accessing properties thusly:
private function on_result(event:ResultEvent):void {
this.status = (event.result as Project).status;
}
Now if the status property is renamed during refactoring, the compiler will instantly pick it up and the world will seem a little brighter.
Building the MySQL gem on Leopard with the macports MySQL
Posted by Cliff
I’ve been running with the Rails MySQL adapter for a while now after failing to build the native MySQL gem under Leopard. The problem, I thought, was that I’m using the Macports MySQL, and it turns out I was right. If you attempt to build the MySQL gem and you get an error like this:
Building native extensions. This could take a while...
ERROR: While executing gem ...
(Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.
ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
Gem files will remain installed in
/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
Then you’ll need to add a couple of things to your Gem command line to get it building:
If you’re just installing or updating the gem, try this:
sudo gem install mysql -- --with-mysql=/opt/local/lib/mysql5 --with-mysql-lib=/opt/local/lib/mysql5/mysql --with-mysql-include=/opt/local/include/mysql5/mysql
If you’re updating all your gems (this one caught me out), then try this:
sudo gem update -- --with-mysql=/opt/local/lib/mysql5 --with-mysql-lib=/opt/local/lib/mysql5/mysql --with-mysql-include=/opt/local/include/mysql5/mysql





