3

I have found that the use of camel case both reduces readability and reuse on some scenarios so far when working with RubyMotion. While I understand how it is, on the outset, helpful coming from Cocoa over to keep this convention, it seems to me that it would be both more productive and wise to use underscore word separation as per standard Ruby convention. Is there a way to already do this or is there another way of attacking this issue?

ActiveSupport supports this conversion. I see something from BubbleWrap that has camelize and underscore methods, but obviously it's not really aimed at this particular use case.

It seems as though if this is not something that the RubyMotion folks will provide themselves, perhaps we could write a wrapper method so that there is a way to trigger a precompilation pass through to make this conversion?

ylluminate
  • 12,102
  • 17
  • 78
  • 152

2 Answers2

1

I've written inflectors that do this kind of thing and using them automagically makes me really nervous. If you're really wanting to use inflectors, look at the motion-support gem. It contains camelize, underscore and a bunch of other keen stuff. You'll notice that these inflectors allow for overrides where the defaults just don't work. That's the problem case. Where it doesn't work.

Inflectors work based on heuristics. Most good heuristics cover the bulk of known cases; exceptions exist. It's the exceptions that will really kill you. (Note. The ones I cooked up and added to motion-support were based on English language grammar rules. You can imagine how difficult localization would be!)

If you are thinking that RubyMotion should automagically do this conversion, I think many programmers would find that counter-intuitive because they would have typed in: tableView(view, numberOfRowsInSection:section) and somehow screwed it up. The error message might read:

table_view:number_of_rows_in_section: *** You made some mistake ***

This would not map to the code as written.

I don't think you want your build tools renaming your objects and/or methods without permission and how would RubyMotion know which to rename and which not?

Steve Ross
  • 4,134
  • 1
  • 28
  • 40
0

There is a gem for that: https://github.com/jamonholmgren/viper

It's nice to have an option which case you choose. However I would consider the future of the project. For instance, imagine your project becomes successful and you hire more Objective-C developers who would work on this project with you. It will be easier for them to port it to Objective-C (or Swift) if case is familiar to them. Some of the junior developers who don't know Cocoa well will struggle Googling for the right answer.

I ended up mixing up cocoaMethod(calls) with my_own_ruby_method(calls).

Ivan
  • 874
  • 10
  • 32