Monday, July 28, 2008

Rubygame

to actually install it on Hardy, I grabbed the following packages via apt-get:

libsdl-ruby1.8 (probably not necessary, but might be useful if I needed an extension)
libsdl1.2-dev
libsdl-gfx1.2-dev
libsdl-image1.2-dev
libsdl-mixer1.2-dev
libsdl-ttf1.2-dev (this wasn't available for Hardy, so I did a package search and installed the package from Dapper)

Thursday, July 24, 2008

OGRE, ogre.rb

Were I a better man, I would have just hacked the gem installation to want the most recent stable version of OGRE. For the moment, I'm playing nice.

The current stable OGRE gem is 0.2 (and is named ogre.rb), and it wants ogre-1.4.4, which you can get reasonably easily by following the OGRE source installation directions and string-substituting appropriately. 0.3 is unstable and I was unable to install it on 64-bit Hardy.

I also needed to install osi-1.0.0, which is available on sourceforge. http://downloads.sourceforge.net/wgois/ois-1.0.tar.gz?modtime=1182593947&big_mirror=0 The installation procedure for that is directly analogous to the installation steps in the ogre install docs.

Additionally, I needed to muck around in the gem directory itself in order to be able to run any sample code. Specifically, plugins.cfg and resources.cfg needed to be moved into the gem root and resources.cfg needed /samples prepended to the path. The plugin folder needed to be /usr/local/lib/OGRE, although I think that I only needed to edit that because I had previously edited it on some wild goose chase.

With that, I was almost able to run the samples, but it resulted in a black screen that just wouldn't die. (Q, esc, C-c, CAD all failed) Turns out that I needed to adjust the settings: RTT Preferred Mode of PBuffer did the trick. (samples needed sudo to execute successfully) Exiting the rendering was accomplished via Q and arrow keys plus my touchpad allowed to to pan and zoom.

I'm not convinced that OGRE is intrinsically the way to go, but it certainly is getting the most attention from the Ruby community (the ruby irrlicht bindings are over a year old, and almost certainly out of date by now), and it seems like it would have a pretty strong symbiotic relationship with pyOGRE. Also, Google likes it enough that they gave it Summer of Code(rs). Rubygame seems like it might be too low-level, and Shoes doesn't seem capable enough at the moment.

As an interesting aside, Perl is apparently the best language for OpenGL development, running fully as fast as C. This raises a fairly compelling argument to have a compiler for a scripting language with a higher-level interface to OpenGL to target Perl for OpenGL apps. I may look into that project, as it seems potentially sexy as all hell.

The advantages that Python can currently cite for graphics dev over Ruby are largely documentation advantages, although Blender is also potentially a moderately big deal. Pygame is also probably somewhat more mature than Rubygame. That said, the incentives for using Python as a SDL API apply at least as strongly (and probably more so) to Ruby, so it still seems like a good route to go down if you want to do rendering/game dev using a high-level language.

If I end up using it seriously, I'll try to correct the heinous lack of docs.

Wednesday, July 23, 2008

Routing hell

The path to routing hell in rails is paved with the usage of any links or redirects that don't use the
{:controller => foo_controller, :action => foo}
syntax.

url_for is heinously broken if your application is running on a subdomain, as are the more concise text routes.

That's actually not strictly accurate: there are application routing schemes for which url_for will not be broken. if all of your urls look like
some_site.com/subdomain/thing
you'll be fine.

if you have some_site.com/subdomain/thing/foo
the urls generated by url_for will have /thing prepended, which is 7 kinds of not good.

If it was /subdomain/thing, you'd be fine. Probably.

The additional advantage of avoiding routing hell by using the {} options is that it will tend to keep your config/routes.rb very minimalist.

Tuesday, July 22, 2008

ActionGmailer

Fast and easy if you know how to do it, a gigantic PITA if you don't. Here's how I did it with rails 2.0.2

install the tlsmail gem.

in environment.rb:

require 'rubygems'
require 'tlsmail'

Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.googlemail.com" ,
:port => 587,
:domain => "imap.googlemail.com" ,
:authentication => :plain,
:user_name => "you@gmail.com" ,
:password => ""
}

Wednesday, July 16, 2008

Net:HTTP gotchas

Net::HTTP.new is generally not what you want because it doesn't actually establish a connection.
Net::HTTP.start does, and seems basically strictly superior, although having both is probably nice for some niche.

The argument to Net::HTTP.start (or new) shouldn't have a preceding http://

If it does, you'll get this error.

SocketError: getaddrinfo: Name or service not known
from /usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
from /usr/lib/ruby/1.8/net/http.rb:560:in `open'
from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
from /usr/lib/ruby/1.8/timeout.rb:48:in `timeout'
from /usr/lib/ruby/1.8/timeout.rb:76:in `timeout'
from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
from /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
from /usr/lib/ruby/1.8/net/http.rb:548:in `start'
from /usr/lib/ruby/1.8/net/http.rb:440:in `start'
from (irb):45


And then you'll go on a wild-goose chase around the internet, look at sample code for Net::HTTP in chapter 3 of the poignant guide and realize why it was breaking. And then write a blog post about it.

Thursday, July 10, 2008

Getting Started With Rails

Actually beginning as a Rails programmer right now is a little bit wooly: the documentation is pretty spread out, so you basically need strong google-fu or a mentor. It looks like the 3rd edition of Agile Web Development with Rails comes out in October (http://www.pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition) which will almost certainly make it a lot easier.

For now, the best bet seems to be to read through most of the second edition of Agile Web Dev. so that you understand some Rails theory and practices. (basically, parts I and III) Then, follow along with one or more Rails 2.0 tutorials: I used Akita's to make the transition from 1.x to 2.x after about 6 months of inactivity. (http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial) Your mileage may vary, so feel free to consult other tutorials.

After that, the docs/api at rubyonrails.org are probably going to be your best friend, particularly in conjunction with Agile Web Dev.

Tips for newbies:

You really, really want to be using Ubuntu to develop Rails apps. The initial setup can occasionally be a bit of a headache but a quick expedition to google with any errors you're having will almost certainly result in the solution. The Ubuntu community is amazingly good and there are some pieces of software that will hit there significantly before they will on OS X, the other candidate for serious Rails dev. Using Windows for Rails dev seems to be filled with naught but pain.

A lot of people in the Rails community are yammering about how great Postgres is. It's probably not for you, unless you've used it before. MySQL is much more batteries-included and will probably be more than adequate for any app you're writing early. Database issues are just things you shouldn't have to worry about yet.

Heroku is a pretty good early hosting solution, unless you already have a Rails-compatible host. I don't like using them as a development platform, but that's largely personal taste and a toleration for sysadmin-y things.

Learn Ruby. No, not Ruby for Rails. Learn Ruby. Other than drive/intelligence the single biggest commonality I've observed among great Rails developers is that they know how to use Ruby well. Thinking as a functional programmer is tremendously helpful, so at least look at functional languages (I recommend Scheme) and practice programming Ruby with a functional style. Higher Order Perl is a pretty useful exercise book, even though it's not explicitly intended for Ruby. It will make your code better. Or at least suck less.

Wednesday, July 9, 2008

Java (arguably an exception to the 'mostly')

There's a reasonable chance that I'll end up writing some amount of Java for LocaModa. I was a little nervous about this at first because it doesn't exactly have a sterling reputation, at least in the circles I run in. Q likes it, though, and Mas seems to think it's at least ok, so I decided to go inspect the documentation. Mas pointed me towards the docs on Sun's site, which initially scared me quite a bit. Navigating intuitively from their home page, it appeared as though learning Java would cost $760. Googling on "sun java docs", I was able to find the free tutorial. () I decided to read the section "How Will Java Technology Change My Life?", primarily because reading analogous things in their respective documentation made me think that Perl and Ruby were pretty cool and that Python had a bit of a chip on its shoulder. (Learning Python was very focused on the 'advantages' of Python over Perl)

The sell here is very clearly targeting people who are coming from C, or a level of developer hell similar to C++, probably the beast itself.

Point-by-point:

*Java's start-up time is massive compared to that of Perl, Python, Ruby or Scheme. It is, at best, as speedy to get installed and write 'Hello, World!' as C, but that's assuming a lot. (that the developer is not using an OS with a C compiler already installed and fails to consult wikipedia)

*Java code is bloated. It may well be 4x as concise as C++, but it is massive compared to any of the above non-C languages and for some cases appears to be more verbose than C. The Java 'Hello, World!' is at least as long in terms of lines and has many more things for the novice to understand. While this is not strictly verbosity, it has the same mind-cluttering effect.

*Garbage collection is not exactly teh uniquely Java tech, and I have a difficult time believing that a language that verbose and structured is useful for learning good programming practices. I learned good programming practices by writing bad code. (long Perl scripts with no subroutines) I don't think that doing something correctly from the start gives you a proper understanding of why a particular method is correct: you need to screw up in order to know why the wrong way is wrong.

The alternative is to just accept the argument-from-authority, which is fundamentally opposed to the hacker ethos.

*Development time in Java is probably faster than it is in C++. It appears to be radically slower than Ruby dev time, at least for web apps.

*Platform dependencies: this is literally just a library issue. Library strength is a somewhat dubious selling point, because it just takes time and effort to catch up. At some point, Ruby (largely) caught and passed Perl and Python in terms of library strength.

*Write once, run anywhere: this is probably actually moderately nice for some cases, and is much less informationally selective than basically all of the previous arguments.

*Ease of distribution: no real opinion on this, probably true, probably a good thing.

The best argument for using Java is almost certainly that it is currently an industry standard. This is a pretty dubious means of selection because it requires you to believe in the durability of the status quo and individual programmers have proven somewhat disruptive of that.

Imagine telling a PHP programmer 4 years ago that they would lose web dominance. Or telling a COBOL or FORTRAN programmer in their hey-day that their languages would become moderately obscure punch-lines.

This argument is not fundamentally new, but it probably saved me from hemorrhoids or an aneurism.