Live data from Hacker News

Ruby vs. Python comes down to the for loop (2021)

softwaredoug.com

131–140 of 193 posts

Re: Ruby vs. Python comes down to the for loop (2021)

#131
post #116
post #40

Earlier quoted context omitted.

I think you’re mistaking C-style syntax for what modern C languages have adopted and become. How many C style context even really exist today? The block separation by single characters is ok. Using (), [] and {} to separate things makes things easier on the compiler, but it’s probably down to personal preference whether you like that syntax or not. I certainly vastly prefer the more simplistic approach where you don’…

> I guess {} is better than BEGIN END, but maybe not in terms of readability. AFAIK, {} lacks initialization and finalization blocks, like a sql statement without transaction wrapper. Example is awk: https://www.gnu.org/software/gawk/manual/html_node/Using-BEG...

I don’t think it’s a fundamental property of single-char open/close delimiters. Like, try-with-resources, or scala/kotlin/groovy/etc-like blocks do let you specify specific initializers xor finalizers, but one might as well create a language with ` { } with (FINALIZE)` syntax.

Re: Ruby vs. Python comes down to the for loop (2021)

#132
post #126

Earlier quoted context omitted.

> Similarly I prefer Pythons indent to {}’s. Which can technically make your code harder to read I started out having a similar opinion to you, and have completely flipped. 1. There's very little advantage to the whitespace option apart from aesthetics. Depending on your coding style, you gain 0-2 vertical lines. 2. Meaningful whitespace makes it more difficult to write code that writes code. Is it possible to manage…

I don’t mind the {}s too much, maybe the primary reason I dislike them is actually more to do with the fact that I’m Danish and I’ll need to press option+shift+7 to make a { on my Mac… or similarly annoying combinations depending on the machine/OS. I think I once had a windows laptop where I needed to press FN + something. Anyway, when your language adds extra letters to the keyboard ÆØÅ in my case then they have to…

I'm European, I lived in Denmark for pretty long, and I found it a great quality-of-life improvement to switch to ANSI keyboards, or at least to an ANSI layout.

By defining a compose key, you can type á, é, å, ø, ß, §, plus many other symbols, with relative ease, while still having all keys in the right place to program.

For instance, using Emacs with any ISO layout is much harder.

Re: Ruby vs. Python comes down to the for loop (2021)

#133
post #42

Earlier quoted context omitted.

[flagged]

Ah, a brilliant idea, design all languages so people who only know C can make small changes to existing Ruby code without getting confused. Definitely don't want to enable different abstractions or models of computation. Are these core principles in codebases you mentioned mostly "how to write stuff using C paradigms"? After all, "the Real Programmer can write FORTRAN in any language"

Why are so many people interacting with this at all instead of downvoting to oblivion? What kind of post comes from an anal_reactor?

Re: Ruby vs. Python comes down to the for loop (2021)

#134

The whole premise here IMO is quite flawed. In real Ruby code I almost never use a for-loop. I can't think of a single use base for it. You always use .each or one of the other methods like .map or .select. while loops might get used, but I'm not sure I've ever seen a for loop in Ruby on any of the projects I've worked on with the exception of PRs from people who are brand new to Ruby Edit: much more interesting woul…

> Python's are (to be bizarrely) accessible by instances of the same class (like I can use your heart because we are both human?)

Have you never used C#, C++, or Java?

Re: Ruby vs. Python comes down to the for loop (2021)

#135

This is because Ruby inherits it's approach to flow control from Smalltalk, while Python comes from a C/Algol-like heritage. In fact, Smalltalk takes this much further, such that basically all flow control (including if-then-else) is handled as message sends (e.g. if-then is just a message sent to the Boolean object taking a block as it's argument). The downside is the syntax can feel a tad clunky. The upside is incr…

> The upside is incredibly simple and consistent language grammar I hope you don't mean Ruby (I haven't investigated Smalltalk grammar). Ruby grammar is atrocious due to string interpolation stuff. Nothing to do with handling loops or conditionals, but still... Ruby is not at all an example of a language with good grammar. Unfortunately, it's surprisingly rare for popular languages to have good grammar. If you look a…

Smalltalk grammar fits into a postcard.

https://richardeng.medium.com/syntax-on-a-post-card-cb6d85fa...

Re: Ruby vs. Python comes down to the for loop (2021)

#136
post #21
post #19

Ruby always seems so appealing. Can anybody tell me how the Ruby ecosystem looks like w.r.t. - (Desktop) GUI - Natural language processing I would really like to learn Ruby, but I can only justify the effort if I can use its ecosystems for some private projects, and I often have been burned by languages not offering too much in those two areas. And speed-wise, as I understand, Ruby is the same ball-park as Python?

Ruby is only relevant because of Rails, and if those two things are your use-cases then you’ll be better off with Python

Rails is hardly what I would call Ruby’s selling point. Not even the top 5.

Unfortunately the ecosystem suffers from rot because it was a language for trend-followers at one point. But it is still a better developer experience than just about everything else I’ve worked with.

Re: Ruby vs. Python comes down to the for loop (2021)

#137

The whole premise here IMO is quite flawed. In real Ruby code I almost never use a for-loop. I can't think of a single use base for it. You always use .each or one of the other methods like .map or .select. while loops might get used, but I'm not sure I've ever seen a for loop in Ruby on any of the projects I've worked on with the exception of PRs from people who are brand new to Ruby Edit: much more interesting woul…

The article says almost exactly the same things you complain about it not having. In pretty much the same order.

Re: Ruby vs. Python comes down to the for loop (2021)

#138
post #29

What I like in Ruby: Every expression returns a value. In Python my_list.sort() will return `none`. So if I do `sorted_list = my_list.sort()`, my `sorted_list` will be `none`. And I have been shooting a lot in my foot in the beginning. - I love Python now, but not because I find it aesthetically appealing (I prefer Lisps or functional languages) but because it is ubiquitously available, the ecosystem is phantastic, a…

As others have said, you can use:

  sorted_list = sorted(my_list)

sorted() also has a reverse option and a key option to specify the keys to sort by.

And the sort is guaranteed to be stable.

https://docs.python.org/3/library/functions.html#sorted

Re: Ruby vs. Python comes down to the for loop (2021)

#139
post #52

First impressions apply to languages too. A lot of mathematicians went into AI but didn't start out with any programming experience. They dabbled in some languages and gravitated toward the one(s) they found most useful. Paraphrasing Guy Steele [1]: > It's important that when you design a language that does a familiar thing, that you do the familiar thing exactly... it's criminal that you can write 1/2 and get values…

Actually it is more like this:

Python 2.x

>>> 1/2

0

Python 3.x

>>> 1/2

0.5

Re: Ruby vs. Python comes down to the for loop (2021)

#140

Earlier quoted context omitted.

I would argue that the main selling point of using Ruby is Rails, for sure there are a lot of things you do in Ruby, but for sure in 2024 there are more performant alternatives.

Performance is worth infinitely less than the sheer developer productivity of Ruby, at least when used by experienced engineers capable of restraint.

I was only extremely productive with it after adopting Sorbet, but still got by without it at first.
Post reply on HN