Live data from Hacker News

Why Ruby Is More Readable Than Python

confuzeus.com

61–70 of 149 posts

Re: Why Ruby Is More Readable Than Python

#61
post #40

There's more than one way to write the corresponding Ruby snippet. If I had been writing it, I might have translated it something like this: class BlogPost class This avoids needing to understand what `@@count` means, and lets you use the same syntax as in python: `BlogPost.count += 1`. Or, if I were in a codebase using static type annotations with Sorbet, I'd do something like this[0]. To each their own, write code…

That’s without even mentioning the footguns available in @@count Jez!

Ah sure, this alternate implementation assumes that the BlogPost class is final and never subclassed.

If you plan to subclass BlogPost, the translation is not identical, as the alternate implementation would not keep track of a global count of posts across all subclasses, only of `BlogPost` instances exactly.

Re: Why Ruby Is More Readable Than Python

#62
post #57

The article closes with this thought: > While both languages are much easier to read than say, PHP or Java, [...blah blah blah...] Which leads me to wonder: Have there been any serious studies of the readability of programming language syntactic and semantic conventions? For instance, a good friend of mine (whose day job is working as a software consultant, and whom I imagine would disagree with the author's assertio…

PHP has a bunch of hacks that are here for technical reasons. Function names are inconsistent and terse because they were inherited from C, and there is the historical name-resolution quirk. The prefixed variable names don't bring anything and are not here for any good reason (compared to shell where "naked" identifiers are interpreted as strings). A lot of the object-oriented features had to settle for unusual tokens like backslashes. You might find that the PHP syntax is objectively problematic.

For Java, Rust, etc it's a bit different. I would say that's up to taste. Using "public static" is very verbose but more obvious than @ or _ prefixes.

Re: Why Ruby Is More Readable Than Python

#63
With better unicodes I wish computer language could use fancier characters to express loops, conditionals and in general without using the english language. goodbye to [if, else, switch, break, lastly, each etc..] let us crate a language that uses no letters but unicode symbols to express abstractions. Like emojis.

Re: Why Ruby Is More Readable Than Python

#64
I read through the article waiting the whole time to see that "this is more readable", but I found nothing. Also I'm not sure if the Python examples are so blatantly wrong on purpose or if the author read one Python tutorial beforehand and then decided to write this article. For example this:

> In Python, you will never do post.__str__ for example. Instead, you’ll do str(post)

No you dont. You do the same thing you did with `puts post` in your Ruby example: `print(post)`, which will call `__str__()` method.

> In Python, it’s easy to accidentally write to the count attribute — which can break your program.

To address writing into attribute directly - you can use @property decorator, which will stop you into writing into given attribute, unless you add a setter.

However the main problem in this fabricated example wouldnt be that you can break your program by accidentally writing into an attribute. I'm not sure how common is it in Ruby, but mixing the instance variables together with class variables this way seems like a bad design, and that is what will break your program.

Regarding the Django example - ok that is far from perfect, but comparing a framework which maintains backward compatibility for years with code you write from scratch without worrying about anything is barely a fair comparison.

Re: Why Ruby Is More Readable Than Python

#65

Does Ruby have support for just exporting functions around? All these examples are class based. When I was a Python programmer, we found functions scaled infinitely better over time (with the exception of data classes, unfortunately) for complex business logic especially.

No, unfortunately. This is one thing I've always wished Ruby had.

Ruby is object-oriented, for better or for worse. Similar to Java, you can have static methods, but they have to live in a class (or module in Ruby's case).

Re: Why Ruby Is More Readable Than Python

#66
post #53

Surely there's a correlation between ease of reading and ease of compilation? I'm thinking in terms of avoiding back-tracking in your syntax. E.g.: regices are hard as shit to read, and I don't think that back-tracking helps (ab + c)* Or *+(ab, c) The first says ab, no - it's the union of ab and something, something is c, no - it's one or more of those. The second says one-or-more of the union of (ab) and (c). Why ha…

> regices

Please no. It's bad enough that people insist on using foreign plurals in English, let's not pretend "regex" is some latin word (it's just REGular EXpression).

Re: Why Ruby Is More Readable Than Python

#69

Earlier quoted context omitted.

Yes, you can replace attributes with properties without changing the consuming code. For example: >>> class Foo: ... @property ... def bar(self): ... return "hello from a property" ... @bar.setter ... def bar(self, value): ... print(f"tried to replace bar with {value}") >>> Foo().bar 'hello from a property' >>> Foo().bar = "asdf" tried to replace bar with asdf

I know it's completely subjective and intellectually irrelevant, but wow I think those annotations are super ugly. In Ruby it's all just method calls - properties, methods, user control-flow, everything.

It's a bit of a weird take when attribute definition in Ruby also uses at signs specifically. Which part do you find ugly?

Re: Why Ruby Is More Readable Than Python

#70

With better unicodes I wish computer language could use fancier characters to express loops, conditionals and in general without using the english language. goodbye to [if, else, switch, break, lastly, each etc..] let us crate a language that uses no letters but unicode symbols to express abstractions. Like emojis.

Please no.

Font ligatures are bad enough

Post reply on HN