Skip to content

Instantly share code, notes, and snippets.

@rentalcustard
Created November 3, 2011 14:25
Show Gist options
  • Save rentalcustard/1336608 to your computer and use it in GitHub Desktop.
Save rentalcustard/1336608 to your computer and use it in GitHub Desktop.
Checks for specific classes in Ruby and Java projects

My contention is that Ruby developers are more likely to use Object#is_a?, Object#respond_to?, and Class#=== in their code than Java developers are to use "instanceof". Here is some anecdotal evidence supporting this contention. It's not easy to compare the two for a number of different reasons:

  1. Java projects tend to have a lot more code
  2. It's hard to decide which projects are comparable to others
  3. It's hard to search for uses of Class#===, which is most often used in case statements.

Nonetheless, here are some numbers which probably mean nothing.

  • SLOC: 385182
  • Lines containing 'instanceof': 1400
  • Proportionally: 0.39%
  • SLOC: 138628
  • Lines containing 'is_a?/respond_to?': 936
  • Proportionally: 0.68%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment