This post is more like a request for discussion thread than a normal 'informational' post. First some history.
In the company I work at, we use many different languages, but mostly based on the Java (JVM) ecosystem (Java, Groovy, Kotlin, etc.) and Ruby ecosystem (Rails, etc.). Most of the teams work with one language/ecosystem, but once in a while we collaborate on some code work in a different language than our daily work. That is fun, challenging and very good for learning new patterns and code styles.
I usually work within the JVM ecosystem (mostly Kotlin), and feel very confortable there. The standard library is great, there is a lot of learning content available for such a new language, and it is possible to build on the shoulders of a giant (Java) in terms of libraries and performance.
Whenever I collaborate and write Ruby code, I feel a little bit powerless. The first thing I do when I open a project which is not my daily code base, I scroll around the directories and files, and look around.
Then, when we start working on the problem at hand, we open the corresponding files and start editing. The first thing I do is Ctrl + click two times:
- Find all the usages of the class/function we are working in (get to know the context of the work);
- Find the definition of a referenced class or variable (what are we working with).
This does not work in Ruby (and many other interpreted languages), as any piece of code can call any other piece of code. Even methods (Ruby does not seem to have properties) can be added dynamically. Things like dependency injection are not really a thing (http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programming).
This leads me to the following set of questions I would like to ask the community.
- How do you find out about usages or definitions of models in code that you did not write, know little about but have to refactor for some reason?
- Apart from test coverage, how do you make sure you do not break anything when changing something else? Even with test coverage: do you unit test every property call?
- How do you store knowledge in the code about some model, like which properties mean what, which are required during construction, which must exist together etcetera? Ruby is object-oriented to its core (https://www.ruby-lang.org/en/about), so encapsulation is important. I fail to understand how to encapsulate something that any other piece of code can extend or modify.
Hopefully this lets me get a better feeling on how developers can work with interpreted languages like Ruby. Thanks in advance for the discussion!