I, Developer


Is Ruby Dying?

Written by John Moses on December 21, 2013

I have been working with nodejs alot lately and have been discussing with coworkers if nodejs is taking steam away from ruby at all. I think the popularity of the language is an important talking point when selecting a language and framework for a new project.

I think a graph on the release date of gems over time could help determine an answer. The front page of rubygems only shows data on the most popular, but I am really interested in seeing recent activity. My theory is that if developers’ contributions to different gems is slowing down, then so is the popularity of the language.

Getting the data

After a little searching, I was unable to find the data in the format necessary for putting together a graph. And anyway, I was interested in scraping the site. My tool of choice is the nodejs cheerio library. The gem executable can give us a list of each gem by running gem list --remote. Fortunately, each gem has its own homepage with a nice URL. e.g. Rails can be found at http://rubygems.org/gems/rails

 1 var request = require('request'),
 2     cheerio = require('cheerio'),
 3     bytes = require('bytes'),
 4     sys = require('sys'),
 5     fs = require('fs'),
 6     exec = require('child_process').exec;
 7 
 8 console.log('program begin: ' + new Date());
 9 fs.openSync('out.csv', 'w');
10 
11 exec("gem list --remote", { maxBuffer: 20000*1024 }, processGems);
12 
13 function processGems(error, stdout, stderr){
14     var gems = stdout.split("\n");
15     console.info('total gems parsed: ' + gems.length);
16     gems.forEach(function(gem){
17         gem = gem.substring(0, gem.indexOf(' '));
18         console.info('crawling gem: ' + gem);
19         request({
20             uri: 'https://rubygems.org/gems/' + gem,
21         }, getContent);
22     });
23 }
24 
25 function parseSize(size){
26     size = size.replace(' ', '');
27     size = size.replace(/\)|\(/g, '');
28     size = size.toLowerCase();
29     try{
30         size = bytes(size);
31     }
32     catch(e){
33         console.error('unable to parse :' + size);
34     }
35     return size;
36 }
37 
38 function escape(s){
39     if (s.indexOf('"') != -1) {
40         s = s.replace(/"/g, '""');
41     }
42     if (s.match(/"|,/)) {
43         s = '"' + s + '"';
44     }
45     return s;
46 }
47 
48 function getContent(error, response, body){
49     if (error && response.statusCode != 200) {
50         console.error(error);
51         console.error(response);
52         return;
53     }
54     console.info(response.request.href + ' complete, status: ' + response.statusCode);
55 
56     var $ = cheerio.load(body),
57         gem = $('div.title h2 a').text(),
58         latest = $('div.versions ol li').last(),
59         version = $(latest).children('a').text(),
60         date = $(latest).children('small').text(),
61         size = $(latest).children('span.size').text(),
62         line;
63     line = escape(gem) + ',' +
64         escape(version) + ',' +
65         escape(date) + ',' +
66         parseSize(size) + '\n';
67     fs.appendFile('out.csv', line);
68 }

Cleaning the data

The resulting file is 2.7mb and can be found here. It is not in the format to make the graph I want. The graph I am picturing has the number of releases for that day on the y-axis and the release date on the x-axis. So I need two columns, the first with release date and the second with the number of releases on that day. The following nodejs takes the dumped csv and puts in the format I want.

 1 var __ = require('lodash'),
 2     moment = require('moment'),
 3     csv = require('csv'),
 4     fs = require('fs');
 5     
 6 fs.openSync('releasedate.csv', 'w');
 7 
 8 csv()
 9     .from.path(__dirname+'/gems.csv', { delimiter: ',', escape: '"' })
10     .to.array( function(data){
11         var csv = '';
12         var grouped = __.groupBy(data, function(gem) {
13             return gem[2];
14         });
15         
16         var array = []
17         for(var gem in grouped) {
18             array.push({
19                 date: escape(gem),
20                 unixtime: moment(gem, 'MMM D, YYYY').valueOf(),
21                 released: grouped[gem].length
22             });
23         }
24         arraySorted = __.sortBy(array, 'unixtime');
25         arraySorted.forEach(function(gem){
26             csv += gem.date + ',' + gem.released + '\n'; 
27         });
28         fs.appendFile('releasedate.csv', csv);
29     } );
30 
31 function escape(s){
32     if (s.indexOf('"') != -1) {
33         s = s.replace(/"/g, '""');
34     }
35     if (s.match(/"|,/)) {
36         s = '"' + s + '"';
37     }
38     return s;
39 }

Graphing in R

Perfect! Now to get graphing. My first thought is to use Excel, but when I try I find out that I can only create a graph with 255 points. That is not going to work as I have ~65k so I boot up R. The following two lines of R produce the line chart I want to see and remind me why I like to use R.

1 data<-read.csv('releasedate.csv')
2 plot(zoo(data$Released,as.Date(data$Date,"%m/%d/%y")),xlab="Release Date",ylab="Releases",main="RubyGems Release Date Trend")

The end result is a nice line chart showing the trend I am looking for.

At first I am surprised. It does not appear to be slowing as I had thought. When I think more about it, it makes sense that the developers are still using gems: * The Ruby meetup groups have a devout following and strong leadership * There are several highly marketed learning resources online * Rails makes it super easy to create a web application

What do you guys think? Is Ruby dying? Did you once use Ruby and have now started to use something else? Comments can be found over at Hackernews