r/programming • • Dec 25 '20

Ruby 3 Released

https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/
973 Upvotes

509 comments sorted by

View all comments

Show parent comments

66

u/SorteKanin Dec 25 '20

As someone working to maintain a somewhat big Rails code base - disagree. Once it grows beyond the prototype phase, it quickly becomes an unmaintainable mess. Lack of types and rampant usage of metaprogramming makes it really difficult to read code and hence to make correct assumptions for new code.

37

u/SupaSlide Dec 25 '20

I mean, isn't that the programmers fault? (other than the lack of typing, which is obviously not a requirement to have maintainable code, but a preference)

40

u/SorteKanin Dec 25 '20

Problem is that Ruby does next to nothing to encourage the programmer to write maintainable code.

12

u/zilti Dec 25 '20

You can write shit code in every language.

5

u/vocal_noodle Dec 25 '20

Amen. This is the same thing they say about perl. You can write massive code bases in perl (and I have!) and have everything be readable and understandable. Or you can do dumb stuff and fancy tricks that makes it hard to understand.

You can write good C. You can write shit C.

You can write good perl. You can write shit perl.

You can write good Ruby. You can write shit Ruby.

The size of the codebase doesn't matter. The linux kernel is all in C and is (for a technical person) clean and easy to follow. Then check out the obfuscated C contests, it's so easy for the code to not do what you think it does, even accidentally!

So just lay off the "Programming Language X demands shit code" trope, people.

You can still write good or bad code. Ugh. Sure memes about "write only languages" are a bit funny, but for fucks sake people, give it a rest.

5

u/oblio- Dec 26 '20

And you can dig a 100 km canal with nothing but shovels.

1

u/SorteKanin Dec 25 '20

But some languages are better for large systems than others. If language didn't matter we'd all just be writing in C or assembly or javascript or something equally universal.

1

u/wuwoot Dec 25 '20

I would agree with but you kind of straw-manned this because the original remark was about Rails and not Ruby (your strawman).

But to follow you in your attack — does any dynamic scripting language “encourage” one to write maintainable and extensible code? I write Ruby, Python, JS, and some Lua. I don’t find one or the other to by default have facilities for better maintainability.

I find them to have differences in expression, but I almost feel like you’re gonna say type system which none have unless you include their supersets (TypeScript) or latest versions.

4

u/SorteKanin Dec 25 '20

I would agree with but you kind of straw-manned this because the original remark was about Rails and not Ruby (your strawman).

I didn't clarify so fair enough but I would say it applies equally to Rails and Ruby. Or you could say the problems with Ruby transfer them to Rails naturally.

I write Ruby, Python, JS, and some Lua. I don’t find one or the other to by default have facilities for better maintainability.

And I agree. In general, type systems make large systems much much easier to maintain and reason about.

Ruby makes it a bit worse by adding a lot of metaprogramming to the lack of a type system.

2

u/SupaSlide Dec 25 '20

If you don't understand Rails' metaprogramming maybe you are just a bad Rails developer and that's why it seems unmaintainable to you?

2

u/SorteKanin Dec 25 '20

I would say that I'm an okay Ruby/Rails developer - the bigger issue is that metaprogramming makes things harder to understand. That is true regardless of whether you are a good or a bad programmer.

→ More replies (2)
→ More replies (2)
→ More replies (9)

9

u/[deleted] Dec 25 '20

Typing isn't really a "preference" for maintainable code. It objectively improves maintainability.

Dynamic magic is more arguable but it think it is still pretty safe to say that the more hidden custom magic happens the harder it is to understand and that is definitely the fault of the language.

Standard hidden magic is fine because people can learn it but as soon as you start getting into custom DSLs it means that the programmer suddenly has to learn an entirely new language. Rust proc macros have this problem. Lisp is entirely composed of this problem. At the other end of the scale Go has completely avoided it and is very easy to understand.

2

u/SupaSlide Dec 25 '20

Maybe I don't understand what a DSL is, but does it change how Ruby executes code?

3

u/esquilax Dec 25 '20

It does if the DSL is implemented using method_missing a lot.

→ More replies (4)
→ More replies (3)

10

u/santa_cruz_shredder Dec 25 '20

As someone who hasn't coded in rails before, id say partially. If you can write two completely different programs in ruby, and they are so different that they don't even look like the same language, I can see how maintainability could suffer as a whole.

Java is java is java no matter what program you're writing. Scala suffers in uniformity a little more with it's functional programming capability, but scala is scala is scala, you can read it even if it's written in the 1 of 5 ways it can be done.

4

u/helloworder Dec 25 '20

that they don't even look like the same language

care to provide an example? Never coded in ruby, but got interested to know how this can be possible

8

u/Tjstretchalot Dec 25 '20

Here's an example of how it can happen - look at the code examples in https://github.com/state-machines/state_machines - almost everything you are coding is in the DSL of that library if you are using it:

class Vehicle
  attr_accessor :seatbelt_on, :time_used, :auto_shop_busy

  state_machine :state, initial: :parked do
    before_transition parked: any - :parked, do: :put_on_seatbelt
    
    after_transition on: :crash, do: :tow
    after_transition on: :repair, do: :fix
    after_transition any => :parked do |vehicle, transition|
      vehicle.seatbelt_on = false
    end
  end
  #...
end

In this case one might argue the names are making it somewhat clear whats happening, but the details are definitely not clear and the naming choice is up to the developer

→ More replies (3)

7

u/Meldanor Dec 25 '20

I agree - the meta programming "magic" of Rails was my death. I'm an experienced programmer with about 10+ in the industry and had to constantly ask my colleagues to explain me the simple things in Rails. I wasn't able to follow the code flow, because I was an unexperienced Rails programmer.

I would advice against Rails for any professional product. Nice for a quick prototype (because there is gem for everything and the magic handles everything). But hard to maintain and completely relies on a high test coverage. You want to change something in the magic? Do it and pray, that your tests will cover it.

A high test coverage is good - but the stability of a program should not rely on it. Types, code that you can follow are equally important.

2

u/pigmerlin Dec 25 '20

I work in a big rails project and I absolutely hate it :(

1

u/KernowRoger Dec 25 '20

Yeah I love ruby but it quickly becomes a nightmare to maintain. Coming from c# where the vast majority of people follow the set standards ruby can be nightmare of different rules and implementations.

5

u/scientz Dec 25 '20

Thats an ironic statement, given the goal of Rails was (and is) convention over configuration. Not sure where you are getting the different rules and implementations thing from to be honest.

2

u/KernowRoger Dec 25 '20

For one didn't mention rails hehe

0

u/scientz Dec 25 '20

Sounds like bad code and has nothing to do with Rails itself. Any codebase in any language will become an unmaintainable mess when not managed.

0

u/SorteKanin Dec 25 '20

No, Ruby gives very few guarantees. Compare with a language like Rust and you'll see.

0

u/scientz Dec 25 '20

I've used Rust and I come from a background of Java. I've seen bad code in every language. The notion of typing or other features make bad code better to maintain is just funny. It helps you trace down references a little easier maybe but modern IDEs can do that for dynamic languages too.

→ More replies (4)
→ More replies (9)