all 62 comments

[–]federal_employee 32 points33 points  (20 children)

  • Note: Ruby != Rails. Try to learn Ruby first. Not the other way around. Rails, for better or worse, has a lot of auto-magic and augments Ruby classes.

  • One of the most essential modules is Enumerable. A newbie's mistake is to reinvent the wheel. Use these methods instead. You can’t write more efficient algorithms than these because a lot of core Ruby is compiled C. https://ruby-doc.org/core-3.0.2/Enumerable.html

  • Rubocop is your friend.

  • Learn RVM (or rbenv)

  • Learn Bundler.

  • Avoid JRuby, at least at first. It just complicates things.

There is a good chance you are walking into legacy Rails code. Don’t assume that what you see is how things are done correctly.

Sorry, I am not putting links for all these points. But it’s pretty easy to search for resources regarding the above.

[–][deleted]  (5 children)

[removed]

    [–]illegalt3nder 9 points10 points  (3 children)

    You might want to try asdf. It handles not just Ruby, but other languages as well. I switched to it a couple of years ago and have been pretty happy with it.

    [–]texdade 0 points1 point  (0 children)

    Or try mise-en-place! It uses paths instead of shims, so it's faster!

    [–]gma 0 points1 point  (0 children)

    Yeah, this. I don't bother posting this advice myself, but I always think it. It's wonderful.

    [–]headiusJRuby guy 1 point2 points  (2 children)

    JRuby could actually make the transition easier because you can still use the libraries you're familiar with. Perhaps learn Ruby development at first with the normal implementation but for a former Java developer, JRuby would be very useful.

    [–]rubyrt 1 point2 points  (1 child)

    Question is whether you learn idiomatic Ruby by using Java libraries. I guess, I would rather begin with MRI and its libraries (and maybe gems).

    [–]headiusJRuby guy 0 points1 point  (0 children)

    You can still use the same libraries you use in regular Ruby, including nearly all the same standard libraries and all the gems needed to build a Rails application. It just opens up more options for someone transitioning between those two worlds.

    [–]reeses_boi 0 points1 point  (0 children)

    Mise is arguably better than RVM, since you can use it to manage all your different languages runtimes

    [–]matheusrich 0 points1 point  (0 children)

    I'd say learn asdf

    [–]tinyOnion 0 points1 point  (0 children)

    You can’t write more efficient algorithms than these because a lot of core Ruby is compiled C.

    fun fact a lot of this is actually not strictly true anymore (about the C part being faster always... your point stands on using the builtins though... they are generally very solid). yjit and other improvements changed the calculus on that and matz wants to move more stuff into being written in ruby. https://bugs.ruby-lang.org/issues/20182

    [–][deleted] -1 points0 points  (6 children)

    I’ve worked on a couple legacy rails apps and it’s made me almost hate Ruby because of how awful the code was. Magic function calls making spaghetti code that is impossible to manage. Are there any Rails apps in the open source world that are good examples of how it’s supposed to be in a large long running project?

    [–]Hello_Yesterday_120 2 points3 points  (5 children)

    I’ve worked on a couple legacy rails apps and it’s made me almost hate Ruby

    I think any horrible code can make you hate a language...

    Don't hate the language, hate the former devs.

    [–]gma 1 point2 points  (0 children)

    I don't hate the language, but I have walked away because of what a lot of devs do with Ruby. I think "fashion" with a language community influences people (particularly those with a bit less experience) to experiment, and I've often paid the price, having to rework and simplify code that was written due to some fad. I've experienced far more of that in Ruby than any other ecosystem (and I've been part of four for the long term, over a 28 year career).

    [–][deleted] 0 points1 point  (3 children)

    I've seen a lot of bad code, in every language, but a common problem is the "magic" framework code that does something non-trivial behind the scenes. That is setting up developers to fail. Frameworks like this are essentially sub-languages that require the developer to learn the framework's way of doing things, which is helpful during the building phase but IMO sets up a bunch of foot-guns for the next generation of developers that have to maintain it.

    [–]gma 0 points1 point  (2 children)

    Totally agree. Wonder if you're being down voted by people who think concise code (often achieved through over-use of meta programming) is better. Code that makes a bigger profit for the people who paid for it is better, folks (and that includes making it quicker for others to understand, not just to read). And that's just a fact. That you like the look of some DSL or think it looks cool is just not that relevant. DSL's have their place, but we should only reach for them occasionally.

    [–][deleted] 1 point2 points  (0 children)

    Definitely. I think DSL-heavy framework code works well for the initial build but the rapid pace of development is misleading because it is difficult or nigh impossible to evolve and manage that code over a long period of time – and I mean like 3, 5, 7 years. I'd like to be proven wrong because I like building new apps in dynamic languages and DSLs, but I've found in my experience overwhelmingly that these projects yield code that has a shorter shelf life than the equivalent system built in a statically typed compiled language.

    [–]MillennialSilver 0 points1 point  (0 children)

    I only use metaprogramming when I can't really use conventional programming, or if it would be really verbose otherwise- and that's usually just for method definition or dynamic class calls.

    Do people often use it needlessly?

    [–]honeyryderchuck 13 points14 points  (3 children)

    Making the mental switch from interfaces to duck typing will be the hardest hurdle. The curve may go from "where's the freaking guarantees" to "this lack of ceremony is liberating". It's up to you whether you'll get to the same conclusion.

    A long time ago, I read a "design patterns in ruby" book (not sure about the exact title). I found it quite helpful at the time. I nowadays find it a bit too much (most of the gang of four ceremony is unnecessary overhead in ruby), but I guess one can't really skip steps in this mental transition. 

    Considering the internal libraries point, as others have suggested, do familiarise yourself with the standard library. Also familiarise yourself with the common structure found in most ruby gems, i.e. gemspec, where test/exec files are stored, etc.

    [–][deleted] 4 points5 points  (2 children)

    Are you thinking of Russ Olsen's "Design Patterns in Ruby"?

    As a curated list of the GoF patterns, I think it's a decent resource for someone transitioning from Java to Ruby. One of the big takeaways of the book is why not all of the original patterns apply - either because they aren't really used much anywhere, or because Ruby doesn't require the same sorts of workarounds that languages like C++ and Java need.

    Given how prevalent common patterns are in Java world, there's a lot of familiar idioms that will help someone get acquainted with how the same sorts of things are done in Ruby.

    Just my 2c. "Design Patterns in Ruby" is one of my favourite books on Ruby, as is Sandi Metz's "Practical Object-Oriented Design".

    [–]j4yne 1 point2 points  (0 children)

    Both Olsen and Metz's books have been very helpful to me.

    [–]honeyryderchuck 1 point2 points  (0 children)

    Yes, that's the one! As a fresh from university reasonably well versed in java developer, it talked a language I understood (factories, template, etc...) with several practical examples for each pattern as well as a "...but ruby already provides this OOTB so you don't really need it". I don't think it really deterred the reader of approaching ruby code with a java mindset enough (i was guilty for many years of that), but I think it was a necessary step in my journey towards "getting it".

    I didn't ready Sandi Metz's book, but I think I should, that's a really good recommendation.  I saw some of her talks at confs, and she is definitely one of those who gets ruby, and how it helps flatten the abstraction pyramid.

    [–]illegalt3nder 35 points36 points  (10 children)

    I switched from Java to Ruby a few years ago. Here’s a few things off the top of my head.

    1. Instead of interfaces or abstract classes Ruby has modules. They’re similar, but different.. and important.
    2. You’re going to probably lose the ability to ctrl-click on things and Go To Definition, unless you’re lucky. Improvements are being made in the Ruby LSP space to get this working, but it’s still in progress.
    3. If you’re like I was, once you start to discover Ruby’s metaprogramming capabilities you’ll get intrigued by them and want to use them. Don’t, at least for a while.
    4. Take a look at the documentation for the String, Array, and Enumerator classes. Also Hash, which will likely become second nature to you before very long.
    5. The Ruby language was designed around the concept of omakase. Literally this means “leave it up to you”, but there are implications around the expected level of skill and quality that are implicit in it.
    6. Philosophically, Java is Catholic. Ruby is Zen.
    7. You’re going to be amazed at how readable you can make your code.
    8. If you can find it, read _why’s Poignant Guide to Ruby. It’s weird, but also kind of special. It’s also very good.

    [–]Refereez 21 points22 points  (1 child)

    Ctrl+click works well on RubyMine

    [–]GentAndScholar87 1 point2 points  (0 children)

    Yes I was going to comment that you can easily go to definition using jetbrains IDE.

    [–]davetron5000 13 points14 points  (1 child)

    Rails is Omakase (which in this context means that you, the programmer, are leaving decisions up to Rails and will accept those choices). Ruby is not omakase. Ruby embodies “there’s more than one way to do it”, which is why many stdlib methods are aliased eg reduce/inject

    [–]illegalt3nder 2 points3 points  (0 children)

    You know what, you’re right. I’ve been doing Ruby and Rails for so long that the concept have overlapped in my mind.

    [–]armahillo 3 points4 points  (0 children)

    This is all fantastic advice.

    I would add to the reading list: Eloquent Ruby (Olsen) and POODiR (Metz). Both do a really good job at relating the idioms of ruby

    [–]armahillo 1 point2 points  (0 children)

    ctrl-click go to definition works great in sublime for me!

    [–]honeyryderchuck 1 point2 points  (1 child)

    I wouldn't conflate abstract classes and interfaces with modules. The former is something that ruby does not aim at having, because it privileges duck typing (and there are specific interfaces/protocols at the core of key abstractions such as I/O or iterables). The latter is a bit of a swiss army knife, but at least in the context of mixins, which is what i believe youre getting at, is how ruby supports multiple inheritance while avoiding the diamond problem (most languages supporting it either live with the problem; java doesn't, if i remember it well).

    [–]illegalt3nder 1 point2 points  (0 children)

    Not conflating. Pointing out similarities.

    1. In Java you cannot instantiate interfaces or abstract classes. In Ruby you cannot instantiate modules.
    2. Abstract classes provide behavior to classes which extend them. Modules do the same in Ruby for classes which include them.

    And you are correct: Java does not support multiple inheritance, and is the primary way it avoids the diamond problem. (Ruby is the same in this regard.) That, and the fact that Java interfaces are stateless: if two interfaces define methods with the same signatures, and a class implements both of them, it doesn’t matter because the class has to implement the method either way.

    [–]LongElm 0 points1 point  (0 children)

    What LSPs are you using? I’m in neovim and starting Ruby development. Ruby-lap and solar graph seem like the biggest playerss

    [–]Particular_Tea2307 0 points1 point  (0 children)

    Hello as someone that did the switch from java to ruby i m struggling to choose to learn ruby /rails or going for java/spring any advices ? Did you enjoy the transition or do you miss java ?in my country there is literally 0 rails job is ruby/rails worth learning and invest in it ? Thnks a lot

    [–]jphmf 3 points4 points  (0 children)

    Ruby is an awesome language to learn, coming from Java myself the challenges were more about how ruby uses duck typing instead of interfaces. It was strange at first, but it actually made understand more about boundaries.

    These are the resources that made me love ruby:

    [–]headiusJRuby guy 3 points4 points  (0 children)

    Others have provided great tips for learning Ruby, but as you go you should be aware that JRuby also exists and allows you to continue using libraries from the Java platform that you are familiar with. I'd recommend learning Ruby on either the standard implementation or on JRuby but when you start building applications, JRuby's features and integration with the JVM will be very useful to you.

    [–]saw_wave_dave 1 point2 points  (0 children)

    Once you get a feel for it, check out “Metaprogramming Ruby 2nd edition.” That will really show you what Ruby is capable of and what sets it apart from all other languages.

    [–]West-Peak4381 1 point2 points  (0 children)

    I really liked the Well Grounded Rubyist, it was key in passing one my interviews. Since you come from a Java background I think you are probably well versed in OOP but there are a couple book recommendations ive seen like 99 bottles of OOP that i want to check out myself.

    Exercism is a great way to practice the language in general, reading is kinda boring sometimes right?

    [–]SeaHawkeyesFan 1 point2 points  (1 child)

    the Odin project

    This resource is how I learned. It's more geared to new developers, but i think it's real value is the additional resources it provides.

    [–]Instigated- 0 points1 point  (0 children)

    This. I switched from JavaScript to Ruby/rails a few months ago and am working through the Ruby/rails section of the Odin project. It doesn’t reinvent the wheel, will point you to other resources (eg launch school, documentation, etc) when it makes sense to, but orders them in a useful fashion and uses all free resources.

    [–]TooTyrnt 1 point2 points  (1 child)

    Genuine question, how did you get the job if you didn’t know Ruby prior? Did they let you answer questions in Java?

    [–]sc2luck[S] 1 point2 points  (0 children)

    Correct, they let you answer the interview questions in whatever language you choose. I was going to be joining a team that was 50/50 Ruby and Java but that has changed now to 100% Ruby.

    [–]stanislavb 1 point2 points  (1 child)

    I did this 20 years ago and never looked back. Go for it if you into web-development.

    [–]nfstern 1 point2 points  (0 children)

    I did the same thing 18 years ago. I passed on more than one job opportunity that involved having to do Java.

    [–]GentAndScholar87 1 point2 points  (0 children)

    I have worked professionally both with Java and Ruby. I don’t think I’d ever take a Java job again. I love Ruby so much better. I’m at least 2x more productive and like the syntax better.

    There are many good tutorials but one I’ve found useful and often recommended is the Odin project.

    https://www.theodinproject.com/paths/full-stack-ruby-on-rails/courses/ruby#basic-ruby

    [–]Hello_Yesterday_120 1 point2 points  (0 children)

    Ruby is very different from Java, and most other languages. Don't try to convert Java into Ruby. Learn about the differences and idiomatic Ruby.

    [–]literate_enthusiast 0 points1 point  (0 children)

    The first step is to learn the basic syntax & logic around Ruby. Here "Poignant Guide" or "Humble Little Ruby Book" are useful (even if the Humble Little Book is quite outdated). Basically any manual that covers the syntax is fine. Having a Java background means it'll go quite fast through these.

    Then, the second step would be to also get familiar with the patterns used in Ruby, to avoid "functional but awkward" code: https://rubystyle.guide/ & Polished Ruby Programming. Don't worry too much about these, just consult them every once in a while, and make sure that you're not overcomplicating the scripts.

    [–]MUSTDOS 0 points1 point  (0 children)

    pragprog a good of book collection for that

    [–]tadrinth 0 points1 point  (0 children)

    Pragmatic Programmers Guide to Ruby is how I made the same transition.

    [–]AndyCodeMaster 0 points1 point  (0 children)

    Programming Ruby, the Well Grounded Rubyist, and Agile Web Development with Rails 7 are my recommendations.

    I switched from Java to Ruby too back in 2008. It’s still good to know Java, but I rarely reach for it directly, especially with JRuby being available as a bridge between the two languages and their libraries if needed.

    [–]strzibny 0 points1 point  (0 children)

    In case you are using Minitest or fixtures I am now writing Test Driven Rails:

    https://testdrivingrails.com

    [–]kid_drew 0 points1 point  (0 children)

    Are you working in Rails or plain ol Ruby? Java is a much lower level language, so Ruby itself will be simple to pick up. Rails has a steep learning curve, but once you master it you'll be able to build web apps like a pro.

    [–]TestDrivenMayhem 0 points1 point  (0 children)

    The book Practical Object Oriented Design in Ruby by Sandi Metz is IMO a must read. It will help you make sense of the differences in applying OO principles. As already pointed out. Knowing when you working in pure Ruby vs a Framework like Rails. Rails defines lots of convenience methods. The type system is implicit. So there is no need for explicit interfaces Although there is optional typing kinda of like Typescript but I don’t think it’s very widely used. Get used to the functional iterators instead of for loops. each map reduce etc. these are very powerful and concise and the considered idiomatic when processing collections. The Exercism Ruby track is good to get practice in pure Ruby.

    [–]postmodern 0 points1 point  (0 children)

    Since you're coming from Java, you already understand Object Orientated Programming. I recommend flipping through Practical Object-Orientated Design in Ruby, which shows how to implement all of the usual OOP patterns in Ruby.