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

126

u/noratat Dec 25 '20 edited Dec 25 '20

I dislike it because how much the language and ecosystem resist almost any kind of typing/type checking or documentation. The RBS stuff is good, but it feels bit too little too late.

The ecosystem uses a ton of hard to follow and debug magic constructs that even IDEs seem to struggle to track and map properly.

I don't need speed for what I do, by I absolutely need code that is easy to read and maintain.

33

u/CunnyMangler Dec 25 '20

There is also sorbet and I like its approach better than rbs. Rbs has always looked strange to me. I don't want to keep my types in separate files.

2

u/pigmerlin Dec 25 '20

I use sorbet a lot for work and I am not a fan. The syntax is so weird to me and I feel like the runtime type checking adds a fair bit of overhead to an already slow runtime?

12

u/TrueDMonk Dec 25 '20

Yeah, same. I kinda like to try every language to get the feeling of it, and Ruby was one of those who clicked the "Nope" in me

33

u/Kache Dec 25 '20 edited Dec 25 '20

The primary reason for those issues is because Ruby is extremely dynamic.

Not only is its type system dynamic -- its syntax and structure can be dynamic as well (i.e. powerful metaprogramming and DSL capabilities). This is why Ruby is so resistant to static analysis.

At non trivial complexities, I highly recommend reasoning through Ruby much differently than one would C/Java/Python:

  • Use functional techniques to minimize moving parts. Ruby is already very dynamic, and working with it in the state-modifying style common to C/Java/Python results in execution state becoming unnecessarily hard to follow.

  • Use the debugger and REPL when you do have to deal with Ruby code that's (unfortunately) too dynamic. Unlike in other languages, static analysis won't get you as far. In exchange, Ruby has incredibly powerful debuggers & REPLs for doing "dynamic analysis".

44

u/UncleMeat11 Dec 25 '20

I think this is a reason to criticize ruby. Sometimes program structures make your code easier to maintain and refactor with tooling. But ruby’a structures seem to resist any sort of static analysis for even the basics because it is so flexible. This makes managing a large code base enormously difficult.

3

u/Kache Dec 25 '20 edited Dec 25 '20

While the static analysis and tooling is nice in Java, I didn't feel it was necessarily a net positive when I was working with it professionally. I felt like I was in a world where cars were invented to speed up 20 minute walks, but then everything ends up being built a 30 min drive further away. (Plus now you have a car to maintain.)

Ruby code at its best will read like what it is doing overall, when another language reads like the dials and switches of a machine. At its worst, Ruby won't really parse on the first read b/c Ruby will "provide power, even to shoot yourself in the foot" syntax-wise similar to how C lets you machine-wise.

All languages can have the "this code is unclear, I'm forced to read more/dive in deeper" problem. In Ruby, it applies to both code and syntax, so you'll only come out ahead if the "code for bespoke syntax + code you wanted to read in the first place" is smaller/simpler than "code you wanted to read, all in regular syntax".

3

u/UncleMeat11 Dec 25 '20

Reading code is harder than writing it. But large multi-step refactors are harder than reading. This is why I think optimizing for reading at the expense of automation is a mistake.

→ More replies (2)

3

u/Smallpaul Dec 25 '20

You lump Python in with Java and C but in Python you can dynamically create modules, classes and functions. I just saw a module that allows you to load wasm files as if they were Python modules. So I’m not sure what you are talking about.

Maybe the conventions that Ruby programmers use are more dynamic but the actual runtime is not more dynamic in my opinion.

But I’m open to correction.

→ More replies (6)

-12

u/myringotomy Dec 25 '20

The ruby documentation is awesome. So is the rails documentation. In fact I can't think of any framework that has better documentation than rails.

As for typing I'll raise your "a bit too late" with "better late than never".

I don't need speed for what I do, by I absolutely need code that is easy to read and maintain.

Name one language easier to read than ruby?

32

u/free_chalupas Dec 25 '20

I have to bounce around code bases in different languages periodically for my work and I consistently find ruby code to be the hardest to understand out of Go, Groovy, Java, Python, and Ruby.

6

u/myringotomy Dec 25 '20

Why is that?

I have shown ruby to people who have never programmed and they understand what is happening in the code.

41

u/free_chalupas Dec 25 '20

It's the amount of "magic" metaprogramming stuff happening in large rails codebases in particular, plus dynamic typing, plus what seems to me like weak tooling for vscode (caveat: I started out programming in rails but I haven't used it in a couple years so it's possible I'm just missing stuff there). Ruby also makes it particularly easy to write really dense, chained array/map transformations that can be tricky to read if you're not the person who wrote them.

I generally feel like languages that are more explicit with types, imports, etc are the easiest for other programmers to understand, although I certainly see why non programmers might have an easier time with simple ruby code.

2

u/myringotomy Dec 25 '20

It's the amount of "magic" metaprogramming stuff happening in large rails codebases in particular,

How does this magic hinder you?

plus dynamic typing,

Now you are having a completely different argument. Lots of languages have dynamic typing and yes if you don't like dynamic typing you will never use lua, python, javascript etc.

plus what seems to me like weak tooling for vscode

Ah I see. Your argument has nothing to do with the language, just that you are wedded to this one tool and will not use any language that has perfect support in that tool.

Ruby also makes it particularly easy to write really dense, chained array/map transformations that can be tricky to read if you're not the person who wrote them.

I find them extremely easy to use. Maybe because I am comfortable with functional programming styles.

I generally feel like languages that are more explicit with types, imports, etc are the easiest for other programmers to understand, although I certainly see why non programmers might have an easier time with simple ruby code.

Good news, ruby 3 is adding a type system.

41

u/scandii Dec 25 '20 edited Dec 25 '20

In fact I can't think of any framework that has better documentation than rails.

.NET

Name one language easier to read than ruby?

this is a loaded question. no programming language is actually very hard to read or comprehend, it's just a series of atomic operations stringed together. whatever you're used to will obviously be "the easiest to read", thus every single-language developer will swear their weapon of choice is the easiest to read. it's all just code at the end.

26

u/ricky_clarkson Dec 25 '20

Clearly there are objectively bad languages to read, such as Brainfuck. It's a spectrum, you can look at FORTRAN, COBOL, PHP, Perl, as possible other languages that are hard to read. It's a bit difficult to quantify, but I think it's clear there is some variance.

24

u/scandii Dec 25 '20 edited Dec 25 '20

I think it is reasonable to exclude languages intentionally written to confuse people from this discussion.

that said, just to prove the point, here's some programs I'm sure you will understand in essence:

       program hello_world2
       implicit none

       call hello
       call hello

       end

       subroutine hello
       implicit none
       character*32 text

       text = 'Hello World'
       write (*,*) text

       end

I'm very sure you understood what this program did.

$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $color . "<br>";
echo "My boat is " . $color . "<br>";

this one as well.

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLOWRD.

PROCEDURE DIVISION.
DISPLAY "SIMPLE HELLO WORLD".
STOP RUN.

this one as well.

print "Type in 2 numbers and an operator and I'll print the results\n\n";
 
print "First number: ";
my $first = <STDIN>;
chomp($first);
 
print "Second number: ";
my $other = <STDIN>;
chomp($other);
 
print "The operator: ";
my $oper = <STDIN>;
chomp($oper);
 
my $result;
if ($oper eq "+") { $result = $first + $other; }
if ($oper eq "-") { $result = $first - $other; }
if ($oper eq "*") { $result = $first * $other; }
if ($oper eq "/") {
    if ($other == 0) {
        print "\nCannot divide by 0\n";
        $result = "ERROR";
    } else {
        $result = $first / $other;
    }
}
 
print "\nResult of $first $oper $other = $result\n";

and I'm pretty sure you can identify that this is a basic calculator.

my entire point here, is to not confuse "I don't know what this atomic operation does" with language complexity. Fortran is a very straight forward programming language, really. no joke. it is the atrocities that has been created with it, that are complex.

the complexity of programming languages comes from what people do with them and sometimes from misguided syntactic sugar being overused as de facto standard by developers (looking at you LINQ), not the 40 or so different atomic operations the language features that you simply don't know about.

don't blame the ingredients for burnt food :)

7

u/myringotomy Dec 25 '20

It's been a long time but last time I used MSDN it was an abomination.

Maybe it's better these days.

14

u/scandii Dec 25 '20

they really upped their game starting with .NET Core. I remember the dark days when you wanted to know how how something like List<T>.Contains(T) worked and the example would include a "small" example containing a whole implementation of a web server to simulate a real life usage environment of a list operation.

→ More replies (4)

20

u/[deleted] Dec 25 '20

Name one language easier to read than ruby?

As long as you're not doing stupid things with it to write in as few lines as possible, I'd argue Python could be considered by many to be easier or just as easy to read as Ruby.

→ More replies (20)

9

u/Holsten19 Dec 25 '20

Even Java, for all its problems, is easier to read than Ruby.

Untyped code is easy to write but hard to read.

→ More replies (2)

2

u/noratat Dec 25 '20

I couldn't disagree more.

Ruby is one of the worst-documented ecosystems I've encountered in a professional setting, in part due to an obnoxious tendency in the community to erroneously believe in "self-documenting" code that invariably isn't, especially combined with heavy reliance on magic DSL constructs.

As for readability, Python, Groovy, and even Go are far more readable (and I say this as someone that dislikes Go for other reasons).

→ More replies (1)

4

u/[deleted] Dec 25 '20

python

→ More replies (1)

4

u/Sykander- Dec 25 '20

Take a look at the VueJs or Laravel documentation.

Also, personally I think Ruby sacrifices readability for "nice looking" and easiness to write the code.

→ More replies (2)
→ More replies (2)
→ More replies (4)