Live data from Hacker News

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

softwaredoug.com

91–100 of 193 posts

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

#91
post #88

Earlier quoted context omitted.

I feel like everyone making comments along this line is completely missing his point. It's not wrong that 0 is the behaviour of C/Ruby, it's just that 1/2=0.5 is the expected result of much of Python's target audience.

But it's not. In second grade I was taught that 1/2 is 0 (with a remainder of 1). Fractions, real numbers, complex... are taught afterwards.

I don't think the target audience of Python are second-graders, but rather people who have graduated elementary school and realise that 1/2 comes out to 0.5.

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

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

The “end” are better with four spaces of indentation IMO.

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

#93

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…

Could you perhaps write a blog post on what you consider bad decisions in a PL grammar? That'd be interesting to read, esp. for all the aspiring PL developers/makers here.

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

#94
post #27

Earlier quoted context omitted.

[flagged]

What exactly do you think the purpose of having different programming languages is ? The popularity and usefulness of Ruby’s block-based control flow, which you seem to take issue with, is almost certainly largely responsible for the adoption of lambdas in… basically every modern language, not to mention being backported to existing languages like C# and Java. Frankly your hot take is terrible. C was an amazing langu…

And mind you, C's for loop was an innovation: languages before it (and even after) used "FOR var := start_expr [DOWN]TO end_expr [BY constant] DO ... OD" or variations thereof, with constant increment which allowed for much better codegen in a single-pass compiler: it's trivial to remember the increment constant and then issue it later, at the loop's end while remembering a whole expression... not so much.

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

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

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.

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

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

> 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 the indents properly? Yes. Is it more difficult? Yes.

3. IMO, meaningful whitespace is what gimped lambda in Python (as compared to Ruby, where it's extremely powerful and used frequently). I'd rather have lambda + map/filter/reduce than comprehensions. Comprehensions are nicer when the code is simple and worse when it's complex.

I'm curious why you prefer Python's meaningful whitespace over explicit delimiters?

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

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

FWIW that comparison would’ve been identical in Python 2, where to get floating point division in Python would’ve been:

>>> 1//2

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

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

[deleted]

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

#99
post #87

Earlier quoted context omitted.

Okay, I'll bite: how much of this is the responsibility of the language designers versus how much of it is the responsibility of the language user? If I had a junior programmer complain to me about this case, I'd simply tell them "you didn't RTFM", because RTFM'ing before you use a language is not only the professional thing to do, but vital to your accurate and correct use of the language. Sure, language designers s…

Having a full numeric tower and stuff like having 1/2 evaluate to 1/2 (like in Scheme) definitely is the language designer's responsibility.

"1/2" - are these integers or reals?

Shouldn't the correct results be expected for the correct statement "1.0 / 2.0" instead?

This is a user flaw, not a language flaw. Nothing in the "1/2" statement implies real numbers .. ?

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

#100
post #62

Earlier quoted context omitted.

Does any of the programming languages Guy Steele worked with do the former and not the latter? Java certainly doesn't: https://godbolt.org/z/b847KeaGv There's a good reason for this. Computer numbers are not the same as numbers in mathematics. Floating point numbers are not real numbers and ints are not natural numbers.

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.

Post reply on HN