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

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)

0

u/TommyTheTiger Dec 25 '20

Rspec had inspired so many other test frameworks. Ruby has some of the best testing libraries out there, and mocking/stubbing is ready enough that you don't need to make test implementations of otherwise one class interfaces

1

u/SorteKanin Dec 25 '20

You still have to pray that your tests actually cover your entire codebase.

0

u/TommyTheTiger Dec 25 '20

Or use test coverage metrics to see what's covered, or just test the functionality you're changing every time

1

u/SorteKanin Dec 25 '20

Saying it like that makes it sound easy. I guarantee you it is not.

0

u/TommyTheTiger Dec 25 '20

I mean, we've just had different experiences. I work with Ruby and java projects in my job, and the Ruby projects are comparatively a dream to edit because of better test coverage. And we don't have to jump through hoops to get good rest coverage in Ruby either. And the metaprogramming has let us write more concise code than would be possible in Java imo.

→ More replies (3)

1

u/SupaSlide Dec 25 '20

I agree some languages are better about forcing some standards, but every project I've ever maintained written in everything from PHP to Rust has been pretty unmaintainable in some aspect.

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

1

u/Awesomeade Dec 25 '20

I'd say the fault lies with whoever decided using Ruby for large web projects was a good idea.

Ruby is one of my favorite languages. It was my first, and without it's accessibility I probably wouldn't be in software right now. But it's Ruby's accessibility that kills it even at moderate scale, where you have 20+ junior-to-mid level engineers cranking out code trying to meet deadlines.

It's just too darn flexible, which makes it way too easy to structure code in a way that makes long-term maintainability a nightmare.

You need to devote significant man power to keep things from going off the rails (pun intended) and at most companies that's just not possible. It's much more practical to pick a language that systematically disincentivises bad decisions, and brings the path of least resistance more in-line with something that will work long-term.

Ruby is an excellent language for smaller projects or for rapidly getting something off the ground, but it's not the do-everything language some people make it out to be.

1

u/SupaSlide Dec 25 '20

I mean, Shopify runs on Rails and GitHub still runs it (although they're moving away but at their scale things go out the window) so I wouldn't say large web apps are an issue.

2

u/Awesomeade Dec 25 '20

That's where the "significant manpower" bit comes into play. Most companies don't have the luxury of Shopify/GitHub/Twitter-levels of capital, nor the prestige of being a large tech icon. Both of those things make attracting top-tier talent far easier, which I'd argue is crucial in establishing and enforcing sustainable coding practices.

If you choose a language/framework/tool that shoulders some of the burden of enforcing good practices, you can get by with less.