Java & Ruby

18 January 2024

I’ve been tasked to write plugins for CI platforms and tools including Jenkins, TeamCity and Fastlane. These plugins have to be written in Java and Ruby. I haven’t coded in Java since college, and I probably wrote 20 lines of Ruby in my career.

My impressions as a whole:

  1. Programming languages are about the same (if, forloop, classes, etc.). The environment around the language is what takes time to adapt too: dependency manager, CLI, build manager.
  2. I don’t know how to do things the Java/Ruby way but at the end of the day, the important part is to make the thing work!
  3. We’ll struggle for longer. 1 hour could be a long time to struggle in Python, it’ll take twice as long or more in a new language but it’ll get better after a few weeks.
  4. GitHub Global search is your friend. Look for a similar project, and see what they are using. Look for a class, a package you want to use. Look for a method. Keep digging deeper until you find your answer.
  5. ChatGPT (3.5) is also your friend. Not as much about the program itself but as helping with the language syntax: how to do X in ruby?. I didn’t find it useful with packages/libraries since it gets them mixed up, or over-engineer things that can be done in a simpler way.

and more specific on both languages:

Java

OOP everywhere

Too much OOP is too much. 5 levels of classes to understand the feature I’m looking for. It sure provides a lot of flexibility but in my case I don’t need it. You also quickly get into the trap of over-engineering your code as well.

JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
JsonObjectParser parser = new JsonObjectParser(jsonFactory);
MyObject myObject = parser.parseAndClose(inputStream, MyObject.class);

Code example to parse a JSON into an Object

On the plus side, encountering design patterns like Builder, Singleton or Factory made me want to dig back into these to be able to make better decisions and arguments when suggesting solutions.

Tooling

Tooling (IntelliJ IDEA) is great, it runs smoothly and accessing classes/methods helped me figure out what to use. It makes me consider yet again to switch to VSCode to have a better TypeScript experience.

Documentation

Javadoc is good, but method names are usually enough: getWorkingDirectory(): Returns current runner working directory.. I would hope it provides more a high level of how to use classes together. It might not be Javadoc role, but then Jenkins and TeamCity documentations don’t cover everything. They are pointing to other plugins to build one but these references are usually doing a lot where it would be nice to have it focus on one small feature instead. TeamCity did this with a teamcity-echo-plugin but yet it was hard to find in the first place. I might take some time at the end of the project to set up a couple repository with a dull plugin.

Jenkins and TeamCity

Being platforms that are 13 and 17 years old is impressive. Some pieces of documenation are 10 years old and still apply. A nice change compare to JavaScript world, where everything is outdated after 6 months. I had to change where to look for resources. I had to watch more YouTube videos (Jenkins and TeamCity being heavy on the UI makes it the place to post tutorial), and Github that I mentioned earlier.

Ruby

Syntax

What stand out was omiting parentheses and return values make the code clean, but confusing and hard to parse. On the other end, there are nice functions to differencate require vs. require_relative (Python or Node don’t make a difference). A writer’s Ruby makes a point about Ruby letting people have a “style”, is that a good or a bad thing? I’m not sure. I would be afraid that too many different styles makes it hard to understand code on a larger codebase. But it does bring some humanity and creativity to the code, for hacking I’m 100% for it.

Package/Build manager

I haven’t found a language or package managers that is perfect, and rake/bundle/gem keeps the trend. I didn’t have time to explore more, just run a couple of commands to make it work. I’ll keep this for the next ruby project.

Tooling

rspec is the shit! From these projects, this is by far the best thing I’ve encountered. Having the mock feature already included in the test library make everything so easy with the allow function to quickly stub it.

rubycop is suggesting nice things, especially for a novice like me. It cares about complexity. For example it doesn’t allow too many nested if.

Conclusion

If you would have mention “Java” to me 6 months, I would have made a face 😫 but these Jenkins and TeamCity projects changed my mind. I was pleasantly surprised. It doesn’t mean that I’ll choose Java for my next project but I won’t discard it if I have the opportunity to work on a Java project.

Same thing with Ruby. I didn’t have a prejudice against it but it made me want to explore more the Ruby world and Rails. Especially coming from a Django background.

The main lesson is to keep learning new languages, frameworks, libraries, get out of your comfort zone. It’ll only make you a better programmer.