Live data from Hacker News

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

softwaredoug.com

121–130 of 193 posts

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

#121

Earlier quoted context omitted.

0 is also the behaviour of C and of pretty much any serious programming language.

I've always suspected that Pascal and Haskell were not serious programming languages, thank you for confirming my suspicion.

> I've always suspected that Pascal and Haskell were not serious programming languages, thank you for confirming my suspicion.

I wouldn't really group Pascal and Haskell together (unless we're playing rhyming games).

One of those had serious market penetration, a whole industry behind it and was one of the dominant choices for applications languages ... for maybe two full decades (including Turbo Pascal all the way through to Delphi).

I mean, right now, Delphi is still orders of magnitudes more popular and in use than Haskell, which is used by .... pandoc, maybe?

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

#122
post #38
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…

Python has a `sorted` function which will return a new sorted list. I agree with you about the general inconsistency though.

Python’s weird mix of OOP but also global methods like `sorted` and `filter` is very weird to me. (Not to mention list comprehensions.) In Ruby, control flow pretty much always moves from left to right as you add successive method calls.

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

#123
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 would be the contrast to list comprehensions in Python and the somewhat associated crippled lambdas.

Another interesting one is Ruby's private methods being not accessible by other instances of the same class whereas Python's are (to be bizarrely) accessible by instances of the same class (like I can use your heart because we are both human?). I always justified this difference in my mind with Ruby object despite being of the same class potentially having different methods due to metaprogramming at runtime. But it's probably just due to the languages' respective ancestors.

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

#124
post #71
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…

> it's criminal that you can write 1/2 and get values nowhere near one-half This is a foolish argument and Guy Steele should know better. What makes 1/2, which has an accurate floating point representation, any more important than 1/10, which doesn't? Every novice programmer, every single one, trips over floating point, and pretending that floating point numbers match our intuition from mathematics doesn't do anyone…

I suspect that the real answer to this should be that the representation should remain as a rational until it can't. Forcing it into either float or int at the point of entry is the mistake.

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

#125
post #100

Earlier quoted context omitted.

Scheme, Common Lisp. Neither Java nor CL were intended for the novice; I'm sure Mr. Steele had Scheme in mind.

I think there is also a gotcha there as you get a ratio in Common Lisp and not a floating point number. > (print (format t "1 divided by 2 is ~a and its type is ~a" (/ 1 2) (type-of (/ 1 2)))) > 1 divided by 2 is 1/2 and its type is RATIO I don't think there is a simple solution. Numbers are harder than they seem and you just need to know what happens in the particular language you are programming in.

Arguably that's not a gotcha. It's (probably) his point.

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

#126
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’…

> 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 take the space from other things and since {}’s are rarely used they were one of the “obvious” choices.

On the flip side I don’t think the curley brackets add much to the readability.

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

#127
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…

> it's criminal that you can write 1/2 and get values nowhere near one-half.

that's sort of ridiculous. Would he be more ok with the output 0.48? what about 0.51? Ironically, in the age of LLMs and non-deterministic output, maybe he would.

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

#128

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…

[deleted]

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

#129

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…

> Ruby's private methods being not accessible by other instances of the same class whereas Python's are (to be bizarrely) accessible by instances of the same class

Not sure what you mean here; Python doesn't really have private methods.

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

#130
post #40

Earlier quoted context omitted.

[flagged]

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’…

> Which is part of the reason behind the huge popularity of Go in Asia

I don’t get your point - what does Go do uniquely here?

Post reply on HN