Software engineer, Open Source indie developer, speaker. Author of Hanami, a full stack web framework for Ruby.
On the eve of RailsClub 2017, on which Luca will be one of the speaks, we questioned him about his job and his views on Ruby development.
What’s your programming background? It looks like you should have some programing experience before Ruby. How did you come to Ruby universe?
I started doing programming when I was teenager at high school. Then I’ve started my professional career about 15 years ago. I was a webdev, writing in Java which was horrible for me. I did that just for a couple of years and it was painful. Then I switched to Ruby because of rails. It was revolution at that time. It made web development less painful. since then, the Rails pre-1.0 era, my main language is Ruby. I also learnt Go and few drops of Elixir which is interesting for me whereas Go is what I use in production at work.
Do you think Ruby is a better OO language than the others?
If we look at OO way of the things, in Ruby it sounds more natural for developers and it is better object oriented language. In my opinion, Java is like an unenhanced version of C. In Ruby, for me, at the beginning, the mind-blowing fact was that everything is an object. Even numbers. It takes some time to understand at the beginning, but then it makes sense and then it unleashes a lot of tricks regarding polymorphism — like passing around the objects that “quack like” an Integer, for instance. It provides a lot of flexibility for method signatures you are designing and also the implementation you can be focused on. On the other hand I think that ruby missed an opportunity of having the interfaces. Because you can’t define which behavior you want to accept for the method. It could be really useful for you as a library maintainer. That is a missing part. I hope someday it will be fixed. Also, I don’t think the libraries implementing “the missing parts” will determine the real future of Ruby. These new features will work once they are a part of the language core. And of course it must be done right.
What in your opinion are the strongest or the weakest parts of Ruby? Is there life in Ruby besides the Rails?
The strongest part historically is the solidity of Rails. The fact that Rails had become huge platform. It is important not just in Ruby ecosystem but also for web development as a whole.
You may notice that when Rails came in, you may notice the huge level of adoption for the language. It gave Ruby the credibility. But the worst part is that Rails took over Ruby entirely. That created a monoculture in my opinion. There are programmers, that only know Rails, but not Ruby as a language. There are gems that assume that you use only Rails platform. It is something that can damage the language. You should expect problems when you try to work outside Rails with, say, Hanami or systems automation. So Rails in my opinion is major good and bad for a Ruby community.
Now more about goods and bads. I think it is the greatest time for a Ruby ecosystem. Look at good parts. If you have a 5-8 y.o. rails app, good news for you — apart from some upgrading rails problems, you’ve got covered because original recipes of the framework stay unchanged for more than a decade. But at same time I think that ecosystem and language that does not evolve and knows only one way of doing things will eventually fade. But there are good things about it that happening now. Think of Hanami which riches 1.0 this year, more and more apps running in production. Think of ROM which riches, I think, 4.0. Think of Dry-rb, the set of tiny libraries for things like data manipulation et cetera. That is basically the good news. If Rails is good for you as a developer — Rails has the solidity that you need. If Rails doesn’t suit you — you have alternatives.
You wrote Hanami. Why do we need yet another web framework?
There are a lot of web frameworks in Ruby ecosystem, but in general, they are just the clones of Sinatra. Hanami is different in a sense it doesn’t repeat Sinatra. It adopts ideas that are good in Rails along with others we have to adjust. My point is, even if you stay with Rails forever, take a good look on Hanami or other ruby frameworks and learn from them.
What would you point out as the most useful gems/ideas in ruby?
I still have to mention “rom” and “dry-rb” because it is interesting blend between FP and OOP. Especially for “dry” libraries. They are really interesting and I think everyone has to look at them. Not just for hype but because it helps a lot to understand about immutability and deterministic objects. It’s important to make the things in a way so for the given input you have the expected output.
What in FP in your opinion is worthy of an object-oriented rubyist attention?
Immutability and composition. Not necessarily in pure functions. You can have a look how things are done in Elixir. My idea is to blend together FP and OOP. I’ll give one example of that, Function Objects. It’s an object that accepts an input and returns output as a function but also have some kind of state or has a way to call it in a way that doesn’t require all that state and dependencies to be passed around. And at the same time by definition a function object does one thing and does it well — that’s for single responsibility. Thus combining composition and immutability, it is always predictable. Those are the concepts still open to discussion and experimentation. This is something that I want to present at RailsClub. It’s about the future — the new way of doing webapps with Hanami.
So, what your talk at RailsClub will be about?
I will speak about the blending of OOP and FP. How has it been an intuition in Hanami 1.0 series. For instance, Actions. Actions are objects which expose just one method that takes input and returns output, the HTTP response serialized with Rack specification. We have validators that act similarly. The idea is to take a look of what we have right now and standardize it as behavior for 2.0. Trying to build a webapp for each use case, for each feature that you have in your webapp — it’s like a pipeline of functions combined together. Where you take an input, you validate, coerce, manipulate, process and then return something to the user. That is something I what to present. I want to standardize the set of objects that we have. It goes beyond MVC. Because in MVC you get a request for a controller, you do bla bla bla, you don’t know what goes inside. Everyone wants to define their own workflow there and then return a response. Inside of that layer, our goal is to have a pipeline of data transformation. If you want to describe what webapp does, it basically takes data input, eventually process it in the database and returns data output. If you think about those data transformations, you have it step by step. If previous step was successful, you continue. Otherwise, you handle the exception or an error the previous step returned. It has to be standardized in my opinion.
What resources would you suggest to both newcomers and experienced rubyists?
I suggest Sandi Metz book “Practical Object-Oriented Design in Ruby”. Because if even she doesn’t speak about functional programming, it is important to understand the object oriented part. It’s not natural to just turn Ruby into a functional language, you have still to take all the good parts of Ruby well described in that book. Another book is “Exceptional Ruby” by Avdi Grimm. It’s a short book, basically questioning why in Ruby ecosystem we use exceptions to signal errors. Exceptions should be for exceptional events like “database is gone”. But not for other stuff like database check violation. For example, in new programming languages like Go and Elixir, you never see exceptions, only errors. That makes virtual machine less heavy if you use errors not exceptions. Also, it keeps your code more natural. It is short but solid book about one concept that changed my mind. I also invite readers to check how things work in functional programming and what we can borrow from there. I don't have any book suggestion for that, I just learn Еlixir via their guide. It is good to get a sense what’s going on outside the ruby community.
How would you encourage developers to join Open Source?
It is matter of giving back. For example, Rails, which is open source project, is free in terms that it costs nothing but it helps people earn money. It’s just a matter of recognize the value that it has for you as a developer, for you as a company and give back. It doesn’t mean that you have to spend whole week working on open source. Just help others from time to time. For example, I started the hanami with 30 minutes a day. I’m a big fan of baby steps. Open source doesn’t have to be second job for you. Be open source oriented rather than just a contributor. For instance, you can add some worlds to outdated documentation. It will take 5 mins, but it is very precious for the community. If you find a bug, open a github issue. Also, speaking of the selfish part, contributing to popular projects is great for your CV. You learn to work asynchronously, it is the future of our job, in my opinion. You learn to be patient, you learn the philosophy, you learn how to fit in different setups and visions. It will help you to adapt to the next job and will help you to know Ruby better. You will learn how to read someone else’s code. Long story short — you will learn a lot of skills that makes you really good candidate for your current company. Or, it with help you to find better job if you are bored with the current. It not only helps you to be a good programmer but also gives you a set of skills around programming that helps a lot.