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.
Ruby vs. Python comes down to the for loop (2021)
91–100 of 193 posts
Re: Ruby vs. Python comes down to the for loop (2021)
#92What 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…
Re: Ruby vs. Python comes down to the for loop (2021)
#93This 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…
Re: Ruby vs. Python comes down to the for loop (2021)
#94Earlier 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…
Re: Ruby vs. Python comes down to the for loop (2021)
#95First 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.
Re: Ruby vs. Python comes down to the for loop (2021)
#96Earlier 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’…
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)
#97First 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…
>>> 1//2
Re: Ruby vs. Python comes down to the for loop (2021)
#98First 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…
Re: Ruby vs. Python comes down to the for loop (2021)
#99Earlier 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.
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)
#100Earlier 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.
> (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.