
I am guessing 9 out of 10 of you reading the title is prepared for yet-another Rails drama on some obtrusive community members, and because everyone is tired of Rails dramas, I am risking that some of you won’t care to read the article – but I couldn’t resist
. Actually I’d like to talk about usage of (un)obtrusive Javascript – why is it a bad idea to be obtrusive, especially given that (as you will learn from the article) writing unobtrusive Javascript is not harder, and you get the warm, fuzzy feeling of writing nice and clean code!
To demonstrate the differences, I’ll lead you through the creation of a quick AJAXy shout wall both the default/standard (and obtrusive) way, then do the same with unobtrusive Javascript to show you that contrary to the popular belief, you don’t need to memorize the “Tome of Javascript Black Magick Tricks” by heart, use obscure libraries or special coding techniques to achieve clean, unobtrusive code. The shout wall is simply a form for posting a new message, and a list of messages below it, like so:

Note: If you’d like to follow along, please use the provided pastie links – do not try to cut & paste multiple lines from the page (single lines are OK), as it will be b0rk3d.
rails obtrusive-shout-wall
cd obtrusive-shout-wall
script/generate resource message
t.string :author
t.text :message
rake db:migrate
default_scope
rder => 'created_at DESC'
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag :defaults %>
<%= yield %>
body {
background-color:#FFFFFF;
color:#333333;
font-family:"Lucida Grande",verdana,arial,helvetica,sans-serif;
margin:0 auto;
padding:0;
text-align:center;
width:960px;
}
#messages {
text-align: left;
margin-left: 80px;
margin-top: 50px;
}
#message-form {
text-align: left;
}
#message-form dl {
margin:10px 0 0 80px;
}
#message-form dd {
color:#666666;
font-size:11px;
line-height:24px;
margin:0 0 5px 80px;
}
#message-form dt {
float:left;
font-size:14px;
line-height:24px;
width:80px;
text-align: left;
}
#author {
margin-right: 640px;
}
#message {
width: 600px;
height: 200px;
margin-right: 194px;
}
.message {
margin-bottom: 20px;
}
.first_row {
padding-bottom: 10px;
}
.message-meta {
font-size: 12px;
}
.author {
color: #FF5050;
font-weight: bold;
}
.new-message-label {
text-align: left;
padding-top: 30px;
margin-left: 80px;
}
#submit-button {
float : right;
margin-right: 195px;
margin-top: 10px;
}
def index
@messages = Message.all
end
Enter new message!
<% remote_form_for :message, :html => {:id => "message-form"} do |form| %>
We are showing the form for the messages and list the already exiting messages below the list.
Note that we are using the _remote_form_for_ Rails helper to create an AJAXy form. This is already obtrusive, since if you observe the generated HTML, you will see that the form has an onsubmit parameter with some horribly looking code attached to it.:

def create
@message = Message.create(:author => params[:author], :message => params[:message])
end
page.insert_html :top, "messages", :partial => 'message',
bject => @message
page.visual_effect :highlight, "message-#{@message.id}"
Here we insert the “messages” partial, using the just created @message, and throw a splash of yellow fade into the mix for good measure. Easy peasy.
Here I am presenting only the steps that are different from the above – i.e. if step 3 is skipped, use the one from above.
rails unobtrusive-shout-wall
cd unobtrusive-shout-wall
curl http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js > public/javascripts/jquery.js
curl http://www.malsup.com/jquery/form/jquery.form.js?2.28 > public/javascripts/jquery-form.js
curl http://view.jquery.com/tags/ui/latest/ui/effects.core.js > public/javascripts/effects.core.js
curl http://view.jquery.com/tags/ui/latest/ui/effects.highlight.js > public/javascripts/effects.highlight.js
and replace
<%= javascript_include_tag :defaults %>
with
<%= javascript_include_tag 'jquery' %>
<%= javascript_include_tag 'jquery-form' %>
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag 'effects.core' %>
<%= javascript_include_tag 'effects.highlight' %>
in the layout file.
def create
@message = Message.create(:author => params[:author], :message => params[:message])
render :partial => 'message',
bject => @message
end
$(document).ready(function() {
$("#message-form").ajaxForm({success: handleNewMessage});
function handleNewMessage(response, statusText) {
$("#messages").prepend(response).effect("highlight", {}, 1500);
}
});
I don’t think so that this code is particularly more complicated or hard to understand that the RJS one. Everything is inside the ready() function, which means that it’s only run once the document is properly loaded. Then we declare that “#message-form” is an AJAX form, and that upon successful submission, the handleNewMessage() method should be called. And if that happens, we add the response (which is the return value of the “create” action) to the “#messages” div, just as we did in RJS. Then we apply the yellow fade! w00t!
(You can check out the code used in this post from it’s github repository).
As you can see, the only real difference between the obtrusive and non-obtrusive version is in the last 2 points (downloading and including the jQuery header files can be easily solved with Rails templates): instead of leaving the rendering part to Rails, we return the response as a string and dynamically insert it from jQuery. With about the same effort, we kept all the Javascript code in application.js, which is much cleaner this way (you can open up 1 file and check out all the JS/AJAX behavior in one place), especially after introducing a lot of Javascript functionality into your code – in other words, for the same amount of work we got something much better. Please try to keep this in mind when you are working with Javascript and Rails the next time – believe me, it can save you from a lot of pain!
]]>
I surely don’t have to introduce last week’s Ruby/Rails earthquake to anyone by now – it has been covered by a boatload of blogs (including this one), analyzed, argued over, rebutted, reddited, dugg and whatnot – suffice to say, it’s time to move on. It was a rather unpleasant drama piece, but fortunately it shed light on some problems the Ruby/Rails communities are facing, and (besides the ensuing trollfest and pointless arguing) it had a pleasant side-effect: a handful of people started to discuss how things could be made better, creating a small (and growing) but determined community: RailsBridge!
RailsBridge’s mission is “To create an inclusive and friendly Ruby on Rails community” (check out details on the homepage). Everyone is welcome to participate – with ideas, suggestions, design, code, new project proposals or just about anything that would make Rails a more open and accepted technology and community.
It’s very important to understand that we are not trying to form yet another oh-my-god-we-are-so-awesome Rails group of uber-hackers which looks down on everyone not in it’s ranks – for two reasons, at the very least:
Surely, this is quite a venture – our mission statement sounds great, but everyone can do the talking on just about whichever Gordian Knot out there, be it world hunger, world peace or friendly Rails. We’ll have to demonstrate that we mean serious business, and that’s why we need you – everyone’s ideas, insights and help matters! Check out the RailsBridge homepage to learn more about what are we up to and how to get involved.
]]>
While I know the title is both asking for trouble (because of the now anecdotal original article with a similar title) and flamebaity, please read on – my goal is not to get some great stats but rather to know your opinion about the situation and discuss the possible solutions of the problem.
I would not like to re-iterate what has been said on several blogs, just to summarize: Matt Aimonetti, member of the Rails Activists, gave a presentation at GoGaRuCo which contained sexually explicit images (according to some – I am not here to judge whether that’s true, and it doesn’t matter anyway, as you’ll see in the rest of the post).
I am not really discussing whether it’s appropriate to have images of nude chicks in your presentation at a Ruby conference (I think it’s not, it’s unprofessional etc. – but that would be a matter of a different post Update: Someone summed this up in the article’s reddit thread nicely: If you’re a Rails programmer, or a Ruby programmer, and you don’t decry this sort of thing, you have no business calling yourself a professional. It doesn’t matter how large your website is, how easy it was to write, how much better it is over PHP or ASP.NET or J2EE; by definition, you do not belong to a professional community. That’s all there is to it.
It’s incumbent on every Ruby programmer to either reject this sort of misogynistic sewage, or accept that you’re never going to advance the promotion of Rails in the public perception because members of the community still think it’s edgy or cool to put pictures of strippers in their public presentations.
And here’s a hint: if your decided reaction is to talk about how unimportant this is, how much it doesn’t matter, or how much it doesn’t offend you personally, you probably don’t understand professionalism at all.) because sadly, I think there are far bigger problems here than that – shedding light on them is the real purpose of the article, not talking about pr0n at GoGaRuCo again.
I have been living in India for 2 months last summer, working on a Rails startup. Maybe I am odd or something, but I knew that I had to remove my shoes when entering a Hindu temple, and _no one had to convince me (what’s more, I didn’t even think about it for a second) wether this is the right thing to do, why is it so, whether I should do otherwise etc_. This is a similar situation – I just don’t do X when speaking at a conference, if I suspect that X makes feel even one person in the room uncomfortable, whether because of his gender, race, nationality, Ruby/Rails skills, penis size or what have you – _regardless whether I think it’s fine for me, my wife, for other members of the community and/or the majority of the room_.
The trick is, how does a *hindu* feel when I enter a temple in footwear (even if that is perfectly acceptable in my country, culture, family, friends) – it’s perfectly irrelevant how do *I* feel in the given situation. Using the previous paragraph, try to apply this to a Ruby/Rails conference.
Until this point in the story, I see no problem at all, and could even agree with the guys asking “what’s wrong with you, don’t make a fuss out of nothing” – the pictures Matt used are non-problematic in my book, and he had no idea they are problematic in anyone’s book – theoretically it could have worked, but the point is, *it did not*. Some members of the Ruby community got offended, and here our story begins.
One of the real problems is that after this has been pointed out, Matt still keeps answering “As mentioned many times earlier, I don’t think my presentation is inappropriate.”. As I mentioned two paragraph above, it doesn’t matter what do you think, unless of course, you don’t care about offending some members of the community. In that case you should not try to apologize at all. However, if you are trying, reciting “I don’t think my presentation is inappropriate” will not put and end to the discussion. It just doesn’t work. Why can’t you just simply apologize, admitting that this was a bad move (because it offended some, not because porn, sexual images or whatever in presentations are bad, per se) and finish the discussion?
However, in my opinion that’s still not the worst part of the story, or to put it differently, some members of the Rails community still found a way to make things worse, by applauding to all this:

OK, you say, we are all used to DHH’s style, this is just how the guy is. That’s (kind of) cool, but I heard that most of the Rails core team (and obviously Matt himself) has the same opinion – and that’s a much more serious problem, because it means that a Rails activist, backed by DHH and other Rails core members finds all this OK, despite of the fact that numerous people in the community voiced their opinion otherwise.
This is not about being a closed-minded prude, shouting for police and suing everyone using sexually explicit images in a presentation. This is not even about women, as I have seen both males and females on either side of the fence. This is about mutual respect – I don’t agree with you, but respect your feelings. Or not, as demonstrated in this case.
So Rails continues to be the most socially unacceptable framework – associated with arrogance, elitism and whatnot in the past – now add pr0n images in presentations. Thankfully RailsConf is held in Las Vegas, and that should calm down all the people who associate Rails with all this crap
. The real problem is that people associate you with the tools you are using – think Cobol, PHP, Java… or Rails. By being part of the Rails community people associate me with Railsy stereotypes automatically, which aren’t nice at all right now.
I hear you, dear creme-de-la-creme Rails (core) member, I know you don’t give a shit, and you think this is all prude babbling – because your hourly rate is more than some of us earn in a day, and you’ll be sought after even if Rails will have a much worse image than it has now. But 99.9% of us are not in the ‘circle of trust’ and would be happier if Rails would not be constantly associated with a ghetto.
In case you are wondering what does the acronym stand for, it’s “Matz is Nice And So We Used to Be Nice”. Unfortunately, the stuff I don’t like about the Rails community is sneaking into Ruby too, it seems, as the above case demonstrates. Besides this, the count of aggressive comments and reactions on various blog posts is really disturbing to me. Please (at least Rubyists) try to avoid being contaminated by all this shit and stop thinking you are cool because you can swear on a forum (always in anonymity). You don’t have to be a douchebag just because you are a Rubyist / Rails coder, as surprising as this might sound to some.
I think “incidents” like this and getting more and more antisocial members are inevitable by-products of growth in a community. The questions is, whether, and if, how, do we stop them. The problem is that it seems to me the Rails “top management” doesn’t want to stop them (what’s more, even encourages them) in the first place (please prove me otherwise – maybe I don’t see the full story – I’ll be the happiest to admit that I am talking bullshit).
I have to admit I have no clue what would be the right move – burying our heads in the sand and pretending everything is fine is not. Please leave a comment if you have an idea or anything to add.
]]>
As promised, here’s a quick post about the FOWA Dublin videos which have been uploaded recently – including the most anticipated Doing a Start Up in the Real World (a.k.a. ‘Fuck the real world’) talk by David Heinemeier Hansson. If you watch only one video, make sure it’s this one I just got back from a wonderful Scotland on Rails 2009 so will post my experience later today (or whenever I’ll be able to catch up with all my chores – spent almost 1.5 week in England + Scotland so my TODO list is huge

I hope this is a joke. A bit sounds like it, but it might be still true. I am really hoping it’s not!
The news (“Twitter Unveils New Premium Accounts“) is spreading like wildfire on twitter right now, making it impossible to even guess who retweeted who, but that doesn’t really matter anyway. What matters is that everyone in twitterverse is talking about it right now. I really do hope it’s just a scam, because I don’t like the idea at all… here’s why:
I have a ton of other points, but the more and more I think about it, I seriously think this is a SCAM. I really love twitter and hope they’ll have a solid business model and will make a ton of money sooner or later, but please not this way. I am not even against premium accounts, or just paying a sensible monthly fee – would surely do that – but please stay with the roots and don’t promote elitism. Khtxbai!
]]>
Let me start with a bit of background – as a Rails developer for almost 3 years now, this was obviously not the first time I heard about David, 37signals, their Getting Real principles, business practices etc. – however, this was the first time I have seen him live, delivering a great talk. And it made a huge difference.
If you happen to know me, you probably know that I am not a guy who gets ecstatic because someone is an alleged rock star, ninja, pirate or zen master, even if he happens to be author of something as significant as Ruby on Rails which I think is the greatest piece of software since Prince of Persia. I had my own reservations wrt David (a slew of blog posts about him suggest that he is kind of a controversial character to say the least: the potty-mouth Dane, the F-bomb terrorist who always has a curse or two up his sleeve for good measure, brings on the vitriol first and ask questions later etc. etc.) After seeing him perform live, I am quite sure that most of these negative comments are either taken out of context, coming from the sour grape camp or are just plain wrong. Sure, David is not a grail knight when it comes to defending his stance – that’s one of the reasons why he keeps building kick-ass stuff like Rails or Basecamp. He totally pwn3d the stage from the very beginning, and even if I wanted to be very critical, I just could not see that he is the douchebag suggested by his critics.
It also became clear to me that DHH != (only) Rails. While he is often primarily described as the author of the Rails framework, that’s a gross oversimplification of the big picture. I think Rails is “just” the side effect of David’s passion to create web apps in a getting real way. Above everything else, he is a guy with a vision who gets things done, no matter what does it cost – e.g. writing a web framework in Ruby (the language he found the most “getting real” style when he needed to implement Basecamp).
OK enough rambling – here is the summary of the talk (I certainly could not get everything, but I am trying my best)
* “We don’t have 200k RSS subscribers because of my deliciously swirly hair” – a central question (asked also during the Q/A session): how on the earth did Basecamp and other 37signals products become so popular? All of a sudden, they emerged from nowhere! As David points out, it was not that ‘out of the blue’ as it looks like. When they started with Basecamp, they already had 2000 subscribers on their blog, Signal vs Noise, so they built a channel which through they could advertise themselves.
This advice meshes with one of my favorite points from Getting Real which goes something like “Just start doing something”. Really. Start blogging. Creating/contributing to open source software. Get on twitter. Let your voice be heard! You probably won’t have thousands of listeners right away, that’s OK – it takes time. But you can start today!
* “Fuck the real world” – probably the tagline this speech will be remembered for. Taken out of context, DHH critics have yet another flickr snapshot where they can demonstrate arrogant F-bomb usage, good for nothing. Bullshit. It was designed and “dropped” perfectly, kicking off the whole talk! David’s advice is to stop listening to “advice” which goes like “yeah, this is a great idea/concept/whatever, but it will not survive in the real world”. Sure, Rails didn’t look like a great idea when Java and PHP have been the bee’s knees. Today no one (except the hard-core sour-grape Java/PHP/COBOL fanboys) would argue that it made a big impact on how web software is developed (call it web2.0 if you like). David said that none of their current apps passed the “real world” (in the sarcastic sense) test – and look where they arrived.
* “I didn’t start coding when I was 6, but 21, and Jason (Fried) started business school later too” – David de-bunked the myth that you have to be a “natural” to accomplish great things. True, quite a few of the IT related success stories start with “I got my first Sinclair ZX Spectrum/Commodore/Atari/Amiga when I was 4, started coding in xyzBasic at the age of 5, roocked fooBasic at 7 etc. While this is all great, and certainly a big help if one happens to become a professional coder later, it’s certainly not the only path to victory. There is no such thing as “starting out too late”. Just make sure you start today.
* “Forget the _advice_ that you shouldn’t build too simple software” – “Good bye to bloat”, “Simple, focused software that does just what you need and nothing you don’t” are rules 37signals are living by, not just pretending. If you check out their award-winning software, used by over a million people today, you’ll notice that despite of their age (several years) they are still simple pieces of focused apps. That’s one of the secret sauces of 37signals: if it works for them, why shouldn’t it work for you? The point is to create something usable, not bloated.
* “Would I pay for this app?” – a great reality check they are asking themselves all the time. If you wouldn’t pay for such a product, why would anyone else?
* “Running your own business = the power to say no – You should be able to say “no” and stick to your vision rather than trying to add all the bells and whistles required by the customers. Note that this does not mean you should refuse / reject all the requests – some of them are really great, but eventually *you* have to decide which ones to keep and which ones to boot (because they just don’t fit into your vision).
* “startup is a category I hate – you have to build a business” – another great point. It’s so trendy to found start-ups today, it almost sounds like a game for grown-ups. (It’s not, I founded two of them myself and it was the hardest part of my professional life so far. Compared to a startup, regular freelancing / contracting feels like a walk in the park
). You have to plan for long term, have real goals, start making money as soon as possible (vs. wait for google or another Silicon Valley dude with a lot of money), get real. It’s not a game, it’s a business.
* “You don’t need rock stars, but a rock star environment. Your employees are not stupid” – argues that the environment your company is in matters more than the individuals. With a great company culture where you respect and trust your employees (e.g. 37signal employees get a company credit card, with one policy – use it reasonably! wow) your team will live up to their full potential. By creating and nurturing an atmosphere of growth, you won’t have to micromanage everybody and everything – don’t treat your employees as idiots, because they are not.
* “An idea is so small part of a business that it’s almost a rounding error” – So true. I have so many ideas right now, that it would take months to prototype them – but that would eventually become an endless process, because during prototyping I would get new ideas, etc. Ideas are cheap, everyone has them. The question is whether you have the skills and perseverance to make them happen.
* “you have to build massive popularity slowly” – Probably my most favorite point of the talk. As a small business owner, startup founder and entrepreneur I found out on my own skin several times that it’s relatively easy to start something – be it a startup, a blog, an open source project, a client assignment, a relationship/marriage/organization/company/habbit/just about anything. The trick is to keep pushing with the initial vigor (at least) once you reach the plateau – for a long time, until the breakthrough comes (you finish your project, your blog gets picked up, your startup is featured on techcrunch, etc.) That’s one of the main things that sets successful ventures apart from non-succesful ones. Everybody has ideas. Everybody can start. A few of them can finish because it takes time and perseverance. You have to believe in yourself and your idea to make it through, as long as it takes.
Unfortunately this summary can’t capture the atmosphere of the talk – as far as I can tell, the room was on fire, everybody was charged up and motivated by this speech (I can’t imagine who wouldn’t be). For me it was worth the price of the conference alone. Massive thanks to David!
]]>
I have seen blog posts/tweets raving about the conference – in a paradoxical way (given what I just wrote in the above paragraph) I can mostly agree with those posts too. The trick is whether you are judging the conference solely based on the content (in which case I can agree with the above blog posts) – or as a whole, including venue, wifi, organization, socialization, before and after parties, freebies, extras, all the bells and whistles. Using the latter method (and I see no reason why one should not) the conference was mediocre IMHO – a few thoughts why:
* (almost) no wifi – After all, a conference centered around the web full of nerds with iPhones, notebooks and other wifi-hungry devices needs no wifi right? Wrong. (OK, the reality was more complex than that: there _was_ some kind of “home wifi” but in practice that meant constant hunting for the signal which broke randomly after a few minutes)
* crowd – A huge crowd (or too little space, if you put it like that) right from the very beginning; Arrived 30 minutes before the actual start, to experience an episode from the life of herrings in the lobby on my own skin, without the slightest idea of why couldn’t we enter the auditorium or what are we supposed to do (other than brewing in our own sweat and looking around to see more puzzled herrings)
* the way the uni sessions were delivered – no microphone; very noisy from outside; people running around all the time, causing constant distraction;
* no announcements of talks – (like someone running out to the foyer and shouting ‘hey guys we are starting in 5 minutes!’) – half of the people still in the foyer, resulting in slow, continuous trickling into the auditorium, again causing a lot of distraction (probably less distracting the closer you sit to the stage, but at the upper end it was really annoying). The doors were open for some reason, so constant murmuring from the foyer.
* No freebies – for this price, at least a coffee or two (and maybe I am not too demanding to add something like snacks/muffins/mineral water?) would have been nice. Ridiculous prices at the bar (well, quite normal compared to Dublin – 2-3 EUR for a tea, 4-5 EUR for a coffee, 5-6 EURs for a pint of Guiness, you get the idea)
* seats – people standing around; though there were theoretically enough seats, de facto about a dozen or more people have been standing around all the time, which felt weird to me, even though I managed to get a seat somehow during the whole conference.
* no sockets – If you were lucky enough to sit close to one of the few (ok, make it a dozen – for 400 ppl!) sockets in the wall, you could recharge your laptop. Otherwise, you have been out of luck.
* a huge rush – I had the feeling that the organizers wanted to pack as much action into one day as possible, which theoretically sounds great, but IMHO it didn’t work out that well in the practice; I missed the beginning of two talks and one full talk after the lunch break because the breaks were barely enough to accomplish anything, be it buying snacks/coffee, use the toilet (1 working toilet for hundreds of guys – great idea) or to grab a proper lunch at a restaurant.
* it was overpriced for what we got – (or we got too little for an OK price) – c’mon, 400 people at an average price of 150 EUR, is 60,000 EURos, + sponsors like Sun and Microsoft, and not even a fucking cup of cofee? We organized EuRuKo in Prague last year for 20EUR / dude, had Matz, the creator of Ruby as well as a roster of other Ruby celebrities, conference t-shirts and a slew of other conference souvenirs, industrial strength wifi, catering (several tea/coffe/snack breaks, hot food for lunch) for 2 full days, free coffee and beverages, and even some free beers (cheers for Brightbox) all this in the heart of Prague. I repeat it again – for EUR 20!
* Little room for socialization (both in physical and abstract sense) – no before-event party (e.g. compare it with Scotland on Rails – three weeks to go, but I know about almost all the attendees, when and where are we going for a whisky (pre-, during- and post-conference), who is staying where, arriving when, going for a sightseeing tour with an option to join them etc. All the organizers did to make this happen was they set up a google groups mailing list and a twitter account, updated with great info every now and then, enabling the attendees to augment it with their own stuff (e.g. when are we going to have a boatload of whisky))
OK, this is not entirely an organizational problem, but still, all the conferences I went to so far addressed socialization in some way.
* after-party – Some of the guys were raving about the after-party – well, I think it was poorly organized too. I went there on time, and had no idea where the FOWA-party “crowd” is – I have seen random micro-bunches of probably-FOWA attendees scattered around the huge (otherwise excellent) Dandelion bar. Asked a few of them about the party, they were just as clueless as myself. Ok, so I left to grab something to eat to the nearby TGIF, but the situation got even worse when I came back. The dispersion of probably-FOWA-micro-bunches-or-lone-rangers went up significantly, so after a few minutes of strolling around I left. Maybe I was just unlucky and popped up at times when everybody was at toilet / had a quick smoke outside or whatever, but some more info (an A4 sheet of paper with ‘we are here’ perhaps) wouldn’t hurt.
Wow – re reading what I just wrote makes FOWA Dublin look really bad – but unfortunately I don’t know what should I remove from the above. These little (or sometimes not so little) things really added up, and fscked up the whole atmosphere. A little more organization and polishing would have solved 80% of the problems.
I am going to summarize a few of the talks I enjoyed in a follow-up post – now I am too tired for that – spent 6 extremely exhausting days in Dublin so need to get some sleep first!
]]>
Update: As several guys pointed out in the comments, Tim’s remark which basically pulled the trigger was sarcastic – I guess have to re-calibrate my sarcasm meter. So you need to replace “Tim” and whatever he said with a different guy and his random quote. There are plenty of them out there these days, so the choice should be easy This rant was in the works for quite some time – I ditched it at least two times already, convincing myself that there is no use to get into language wars and similar nonsense… but people didn’t let the issue go (i.e. that Ruby jumped the shark / it started to suck for some reason etc – most recent example being a tweet by @timbray) so get ready for some grandiose rantbling!
Srsly? By what measure? Actually when did it start? Why exactly then? Again, by what measure? What does ‘over’ mean at all? Says who?
I am currently reading “The Black Swan: The Impact of the Highly Improbable” from Nassim Taleb. There is a section describing Tim’s logic perfectly:
“By a mental mechanism I call naive empiricism, we have a natural tendency to look for instances to confirm our story … – these instances are always easy to find. You take past instances that corroborate your theories and treat them as evidence… I can find confirmation for just about anything, the way a skilled London cabbie can find traffic to increase the fare, even on a holiday”
… or the way Tim can find a bogus evidence for Ruby’s alleged decline, whatever that means. I am wondering where have the current “ruby jumped the shark” guys been 3 quarters ago when Ruby books have been on a roller coaster riding up with the speed of light?!?!
Guess what, I am guilty of naive empiricism too: I wrote an article stating the opposite of Tim’s tweet, based on similar, but opposite O’Reilly data (i.e. Ruby book sales on the rise). Why? Because I have been a Ruby/Rails zealot back then already, that’s why! And I *wanted* to see Ruby on the rise, and did not really care whether my claims were objective (I *wanted* to see that they were objective – meta-naive empiricism FTW!)
Another great example of naive empiricism is the ‘CDBaby: from Rails to PHP‘ vs ‘MuxTape: from PHP to Rails‘ 2-part saga: the funny thing is that both Derek and Luke argue very convincingly and charismatically about the exact different side of the same coin: why the move from framework X to Y has been the best idea since sliced bread, how it saved their ass, pushed productivity to the ends of the earth… arriving at a total opposite conclusion using the same reasoning.
Another bogus reasoning I hear a lot: Python is used in google so it’s > Ruby! Unfortunately enough for the guys treating this fact as a royal flush , Ruby is used in NASA, by some of the smartest folks in Ruby-land. So what?! Does this mean Ruby > Python (or at least is equal to gogle <=> NASA)? Not at all (In my opinion Ruby > Python actually, but 1) this is a personal preference thing 2) it has nothing to do with google vs NASA 3) is a topic of a different rant, which possibly won’t be written as I grew tired of lang wars fought with flame throwers).
Or take github: currently 31% of the code living there is Ruby (and you can’t really argue that by now, github matters – it’s not just a hobby project of 2 guys tired with their original startup any more). So according to this measure, everyone start learning Ruby!
but Tim argues instead:
This is the second part of @timbray’s rather questionable tweet… and here is why:
Comparing the need for Ruby workforce to the C# one is like comparing the need for planes to that of cars. No correlation.
C# is usually used…
Ruby/Rails is the total opposite… it’s usually used…
Both lists could grow unbounded if I cared to come up with more points.
So Tim is essentially saying ‘no need for agile teams cranking out top notch (usually web-based) software fast – everybody jump on the Titanic (the safe 9-5 world of enterprise apps in one of the cubicles of BigCO).
Sorry, but this is utter BS. There will be always a need for lean, agile, quick teams. Following this logic, you should abandon the Python/Django ship too. And btw guess what – the Titanic sunk in the end, no matter how safe it originally was.
It’s not clear to me where is Rails (and a slew of other widely used frameworks/software produced in Ruby) in Tim’s picture. The thing is that Ruby is tied to Rails just like the US economy is tied to just about everyone else’s economy around the world. If Rails prospers, so does Ruby – a kick-ass r41lz h4xx0r is a kick-ass Ruby h4xx0r with knowledge of Rails after all.
However, it looks like there is need for Rails coders: Tom Mornini, one of the founders of Engine Yard, the leading Ruby/Rails hosting states that good Rails developers are very scarce. And while Rails developers will be a scarce commodity, Ruby developers will be too.
This is the original part of the rant, from the time when more “ruby/rails sucks” articles popped up in a quick succession, followed by a grandiose trollfest on various social sites, and eventually meta-ranting (my personal favorite).
I am a bit confused after reading all this outburst: I seriously think ‘fun’ vs ‘mainstream’, ‘imperfect’ (or even ‘buggy’), ‘slow’ etc. are orthogonal problems. Why should be Ruby less fun than it ever was because now it has more acceptance / users / enterprise penetration and/or it’s slow / 1.9 is not a big deal / it leaks memory (fill in the other pain points from the rants)??! This just doesn’t make any sense. Ruby is fun _and_ it has some problems to address. These two are not contradictory statements at all. It’s immense fun to be with my 2-year old daughter, though she is sometimes hard to handle – so I should say it’s no fun anymore?!?
“Ruby isn’t fun any more *for me*” is a totally different claim from “Ruby isn’t fun any more” (in general). I don’t give a shit if Ruby isn’t fun any more for *you*, but please, don’t describe it as community- or language-wide phenomenon. kthx.
You like python? Great! Putting bread on the table coding in Java? Cool. You’d like to play around with bleeding edge stuff (clojure/scala/erlang etc.)? All the better.
Ruby is slow? The syntax is obscucre? You don’t like Rails/DHH/fanboys/TextMate/Ruby/arrogant douchebags/whatever? Ruby is not fun for you (any more?)
Too bad, so sad – however, this doesn’t alter the fact that Ruby *is* immense fun for me, and a whole community of people, and no ranting will change that, no matter how hard you are trying.
I am not even arguing that Ruby is better than X – I am far beyond that point already (after having my share with some Java vs Ruby flamewars). I am just arguing that people should stop tweeting / blogging about nonsense underpinned with ‘evidence’ just because they want to see the world that way.
]]>
I wanted a reliable way to find out a few things about my twitter account (for example which of the users I am following are not following me back) – unfortunately the third party apps out there are not always very reliable, do not exactly do what I want/as I want so I decided to check out how easy it is to hack up a more advanced query using a Ruby twitter API wrapper. It turned out that it couldn’t be easier!
There are several gems wrapping the Twitter API out there – I started to use the ‘twitter’ gem from John Nunemaker and I am perfectly happy with it so far. John did a great job supporting all the features offered by the API – it’s a different question that the API, like twitter itself, is quite minimalistic. For example I have not found a way to get all my followers/friends easily (drop me a comment if I am missing something) so I monkey-patched this into the module in a generic way:
module Twitter
class Base
def all_entries(method, options = {})
all_entries = []
next_100 = self.send method, {:page => (current_page = 1)}.merge(options)
while (next_100.size != 0) do
all_entries << next_100
next_100 = self.send method, {:page => (current_page += 1)}.merge(options)
end
all_entries.flatten
end
end
end
for example you can call connection.all\_entries(:friends) to get all of your friends, given that you set up a connection to your account (I found only a method which returns your first 100 friends – didn’t spend too much time with the documentation though – agin, drop me a message if I overlooked something).
I have added a bit of syntactic sugar to be able to call connection.all\_friends instead of connection.all\_entries(:friends):
module Twitter
class Base
alias_method :throw_method_missing, :method_missing
def method_missing(method_name, *args, &bloke)
if (method_name.to_s =~ /^all_.+/)
all_entries(method_name.to_s[/all_(.+)/,1], args[0] || {})
else
throw_method_missing(method_name, *args, &bloke)
end
end
end
end
Here we ensure that only method calls that start with all\_ are handled by all\_entries, the rest is throwing a method\_missing since we are not interested in handling those messages.
Now it could not be easier to implement the function I originally intended to build: list of users who are not following back.
class Array
def names
self.map{|u| u.screen_name}
end
end
module Twitter
class Base
def not_following_back
all_friends.names - all_followers.names
end
end
end
That’s all there’s to it (I am not a big fan of monkey patching core classes btw ; but in this case, adding the names() method to the Array class just made the method I intended to originally implement much cleaner so I rolled with it).
Note that since subtraction is a non-commutative operation, all\_friends.names – all\_followers.names is not necessarily the same as all_followers.names – all_friends.names.
This is how the final code looks like:
require 'rubygems'
require 'twitter'
connection = Twitter::Base.new('yourname', 'yourpass')
class Array
def names
self.map{|u| u.screen_name}
end
end
module Twitter
class Base
alias_method :throw_method_missing, :method_missing
def method_missing(method_name, *args, &bloke)
if (method_name.to_s =~ /^all_.+/)
all_entries(method_name.to_s[/all_(.+)/,1], args[0] || {})
else
throw_method_missing(method_name, *args, &bloke)
end
end
def all_entries(method, options = {})
all_entries = []
next_100 = self.send method, {:page => (current_page = 1)}.merge(options)
while (next_100.size != 0) do
all_entries << next_100
next_100 = self.send method, {:page => (current_page += 1)}.merge(options)
end
all_entries.flatten
end
def not_following_back
all_friends.names - all_followers.names
end
end
end
p connection.not_following_back
You can download/check out the code here – do not try to copy & paste it from the text as it will be b0rk3d.
In part 2 I’d like to set up a small Sinatra app showing the above users in a list – displaying their avatar, screen name and real name, plus a link to remove them if you decide so.
]]>
I spent the first 2+ years in Ruby-land without even knowing about the probably most underused (and underrated) keyword of the language: redo. Even after I came across the first example and liked it immensely, I could not come up with another use for it, so I threw it to the bottom of my toolbox. Then I found another example, and another one – so I came to the conclusion that redo might be a valuable keyword in your Ruby arsenal after all – it is one of those things which you rarely need, but if you need it, it’s a perfect solution which would be cumbersome to replace with other constructs.
I am sure everyone is familiar with redo’s cousins: next and break. While next and break allow you to skip an iteration, resp. skip the rest of the remaining iterations altogether, redo does not skip anything – it ‘restarts’ the same iteration. In other words, while next transfers control to the end of the iteration block, redo ‘jumps’ to the beginning of the block. Let’s see an example, where redo is used to recover from an input error (code from “The Ruby Programming Language”):
puts "Please enter the first word you can think of"
words =%w(apple banana cherry)
response = words.collect do |word|
print word + "> "
response = gets.chop
if response.size == 0
word.upcase!
redo
end
response
end
The trick is that whenever the user enters an empty string, the block is restarted with redo, asking the same ‘question’ until the user enters something that makes sense to the system.
As of now, Ruby does not support tail recursion optimization, so you either have to write the function in a non-recursive (i.e. iterative) way yourself, or suffer the consequences of a full stack… or use redo!
I recently came across Magnus Holm’s article on this problem. Magnus provides an elegant solution using redo:
define_method(:acc) do |i, n, result|
if i == -1
result
else
i, n, result = i - 1, n + result, n
redo
end
end
def fib(i)
acc(i, 1, 0)
end
Magnus even worked around a redo perk: “The redo statement restarts the current iteration of a loop or iterator”. That means he couldn’t define a method with “def”, since that neither involves a loop nor an iterator. Maybe a less esoteric way relying on the same fact would be to use a lambda:
def fib(i)
acc = lambda do |i, n, result|
if i == -1
result
else
i, n, result = i - 1, n + result, n
redo
end
end.call(i, 1, 0)
end
Here is a Ruby golf riddle, which I have no idea how could be made this short (42 characters) without redo (via coderrr):
"Generate a random string of length 4 or more consisting of only the following set of characters: a-z, A-Z, 0-9"
Here is the winner, Magnus Holm‘s solution (The name sounds familiar? Right, the previous example was from him too – he understands the power of redo for sure
).
(0..9).map{rand(?z).chr[/[^_\W]/]||redo}*""
The above solution might not be instantly crystal clear – so let’s break it down a bit:
While one might argue that golfing examples are contrived by definition, I don’t always agree: the [/[^_\W]/] is a neat trick to get numbers/letters from a string only, as well as the use of redo is valid and non-contrived.
As demonstrated above, redo can be used in a variety of situations to produce an elegant solution that would look much more cumbersome without it. Of course all the usual stuff applies: don’t overuse, abuse etc. etc.
If you have any other interesting cases for redo, leave a comment – I’d love to see some more