Read about:

picture of me

About Me

My name's Enrico Bianco and I love web technology and open source software. In my spare time, I study Japanese language and culture and produce a podcast about learning Japanese.


Adventures in Ruby: When Constants Aren’t

(Programming)

I just squashed a bug that had me scratching my head for at least a good half-hour or so involving a class constant that kept on getting changed. Here’s the setup (anonymized so that I’m not exposing gooey proprietary secrets):

class WebTransaction
 
  # Base URL for transaction web service
  SERVICE_URL = "http://accountingservice.com/"
 
  def transaction_url
    url = SERVICE_URL
    url < < "VAL1=foo"
    url << "&VAL2=bar"
    url
  end
 
end

The class is meant to represent a transaction being posted against a rather odd web service that actually uses GET rather than POST for posting transactions (bad web service!). In my actual code, the URL parameters appended to the SERVICE_URL base would be determined on a per-object basis but I’ve simplified it here.

Here’s the punchline: SERVICE_URL was changing! Calls to transaction_url would keep on appending more variables to it. If you’re particularly clever with Ruby, you’ve already figured out exactly why. But if you’re scratching your head like I was, here are some hints:

  • In Ruby, constants aren’t. In fact, they’re really no different from variables except for the fact that Ruby detects that variable names in all-caps are probably supposed to stay constant and warns if you try to assign to them.
  • <<, for strings, will append to the end of the string.
  • Ruby strings are mutable. That is, operations on a string variable will usually be done in place, rather than returning a new string. (Method calls, on the other hand, are a different story!)
  • Assigning a String variable to another String variable will assign the reference. That is, the two variables will be pointing at the same object.

Hit the jump to see the solution to this little mystery…
Read the rest of this entry »

Creepy Rails Error Message

(Miscellaneous)

Below is a screenshot of an error I received from my day job Rails app while I was testing it yesterday. I think it might be trying to tell me something…

Could not find workitem with ID=666

Could not find workitem with ID=666


I got this when I was following a link to open a work item that no longer existed in the database. I caught it in time to make a screenshot and circulate to everyone in the office before moving on with my work.

Happy Halloween, everyone! =D

In other news, I’m being asked to look over the Japanese translation of Radiant again, which I will find some time to do in the next week or so. I think I’ve found a new place to record my podcast so I’m looking forward to producing episodes of The Japanese Learner again early in November.

“Where did Enrico go?”

(Miscellaneous)

You might all be wondering where the heck I’ve been the last couple of weeks and why there isn’t yet a blog post on how to do LDAP groups-based RBAC with declarative_authorization and ActiveLdap. There is a branch in my authlogic_example fork for that, but I haven’t had time to write new content for the blog because…

I’m moving. Moving day is tomorrow and I’m still scrambling to get everything ready. The logistics look like they’re going have very little room for error but I think we’ll be fine; we’ve got lots of help!

Read the rest of this entry »

“So… what do you do?”

(Personal Development, Programming)

I think that this is a dreaded question for many programmers and others in fields with a scientific or mathematical bent. How do you explain the full extent of what it is that you do and why it’s valuable without being dismissed as just another creepy nerd? How do you fight the stereotype of unkempt basement-dwellers living with their parents, spending most of their time on the Internet because they’re too socially awkward to interact with people in other settings?

About a week ago there was a discussion about this on programming Reddit. The original poster, a programmer, feels a sense of inferiority because while others can succinctly explain the “awesome” in what they’re doing, he cannot. I sympathize with this sentiment. I love what I do but how do I transfer that passion without drowning the other person in the technical details? It feels like without the finer, technical details, my job description becomes distilled to “I make websites.”

Really? That’s it? That’s what I do for a living?

Read the rest of this entry »

LDAP Pass-through Authentication with Authlogic and ActiveLdap

(Programming)

Today, I pushed a branch to my fork of authlogic_example: with-activeldap.

This branch shows a way of implementing pass-through authentication to an LDAP server using ActiveLdap and Authlogic, with just some small changes to the User and UserSession models.

Read the rest of this entry »

Don’t Be Sad, Be Awesome Instead

(Personal Development)

When I get sad, I stop being sad and be AWESOME instead. True story.”
– Barney Stinson (played by Neil Patrick Harris), How I Met Your Mother

I think that this is an incredibly inspirational line. While it seems kind of silly to take advice from a television show, I think it makes an excellent point: it is the times when you are at your lowest that you must put in your absolute best. Energy spent being worried and sad can and should be reallocated to taking action and facing the very things that are bringing you down.

And really, all else being equal, being awesome is much more, well, awesome than being sad.

Where is why?

(Programming)

“Why The Lucky Stiff”, one of the most influential characters in the Ruby community, has simply vanished. His Twitter account, GitHub account, and most of his websites are gone without a trace.

Why The Lucky Stiff’s contributions to the Ruby community include “Why’s Poignant Guide to Ruby”, a book which many state was the reason they got into Ruby, Shoes, an easy-to-use cross-platform GUI toolkit with innovative online distribution features, and Hpricot, a very slick HTML parser that is also a joy to use.

Some believe that he has decided to move on from software development because his last tweet reads “programming is rather thankless. u see your works become replaced by superior ones in a year. unable to run at all in a few more.” Some believe that his accounts were all hacked. A few others believe that his anonymity has been compromised and that he has decided the destroy the pseudonym.

Wherever Why The Lucky Stiff goes from here, I hope he knows that there are so many of us who looked up to him and have him to thank for knowing the joy that is programming in Ruby. He will be sorely missed.

The True Spirit of Open Source

(Programming)

Very rarely does something completely disconnected from my day-to-day existence annoy me so much that I feel the need to say something, but this is something I feel very strongly about.

Robert Fischer wrote a post titled “Dear User of My Open Source Project” and many of the proggit comments were quite vicious. I noticed that some of these commentators seemed to have the same understanding of “open source”: that an open source project is a product, like any other product, that is simply distributed with its source code. Therefore, Robert is clearly creating and releasing “inferior” products and this behaviour should be punished. Being open source is not an excuse.

If this is your understanding of open source, you have missed the point. Entirely.

Yes, there are open source projects out there that are very well-documented, quite reliable, and have attracted large communities of contributors that tirelessly work to improve every aspect of the software. But by my count, that seems to be the exception rather than the rule. Most open source projects out there are maintained by just one person who scratched an itch and thought the solution might be useful to others. Some of these projects might be lucky enough to have a few passionate contributors. These projects may have some rough edges in their code or their documentation, and perhaps the contributors might be too busy to put on the appropriate polish.

You might think that irresponsible, or even reprehensible. How dare this person release this garbage and pollute the open source community!

News flash: it is these people who drive open source software. Those large, reliable open source projects with all of the sparkle and polish? They became that way because large groups of people found them useful enough that they decided to invest their time in making the project even better. But in all cases, for open source software to progress, people have to be willing to give up their time and energy for free and with no expectation of reward. Open source is driven by pure altruism.

And yes, as a programmer using open source software, you may sometimes have to roll up your sleeves, get into the code, and make the changes that you need. Or perhaps you can find other ways to contribute. But complaining like a petulant child that it doesn’t serve your particular purpose is, frankly, incredibly rude considering that you were given this software entirely for free and given the power to inspect its source code and change it to suit your needs. If that is the way that you’re going to approach these projects, go use something else.

Like Christmas, the true spirit of open source is giving.

Edit: Some one on proggit rightly pointed out that I’ve made a common mistake of grouping “open source” software with “free” software, a subtle distinction that this pagefrom the FSF makes very clear. However, I believe that Robert Fischer’s post and his complaints also referred more to “free” software than “open source” software. Consider, for example, that he prefers to use the WTFPL for his projects, the spirit of which is “I’ve decided to put this out here, and you guys can do whatever you’d like with it.”

This is not to say that all “open source” software doesn’t adhere to the values of “free” software or that all “open source” software necessarily follows the values of “free” software.

A Rails Puzzler

(Programming)

While I refuse to call this “magic”, the following has been confusing me for a long time now and I’ve finally decided to post it to my blog and see if anyone else gets it.

It turns out that ActiveScaffold and YARD don’t play nice together. In particular, if YARD has previously been loaded (say, to define a Rake task for it), ActiveScaffold initialization will fail with the following error:

uninitialized constant Helpers::ControllerHelpers

Using --trace and following the source code, I find out that this is happening during ActiveScaffold’s initialization, particularly at this statement:

ActionController::Base.send(:include, ActiveScaffold::Helpers::ControllerHelpers)

Debugging the ActiveScaffold initialization code yields this baffling result:

>> ActiveScaffold::Helpers
=> Helpers
>> ActiveScaffold::Helpers::ControllerHelpers
NameError: uninitialized constant ActiveScaffold::Helpers

It’s the weirdest thing that I’ve seen since I became a Rubyist and it is blocking me from using YARD to generate the documentation for my current Rails project. Unfortunately, cutting out ActiveScaffold isn’t going to fly because the deadline for initial release is so close and so much functionality is implemented using it already. It wasn’t my choice; if I had my way, I might never use ActiveScaffold ever again.

On “Magical” Ruby and Rails

(Programming)

Giles Bowkett wrote a post which, at the surface, seems to be a harsh criticism of the way that Pythonistas and, in particular, Django developers view Ruby and Rails but is actually much more general — he simply wanted to point out that the entire notion of calling language/framework features “magic” is silly for programmers, who should prefer to be rational than superstitious.

Read the rest of this entry »