Live data from Hacker News

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

softwaredoug.com

171–180 of 193 posts

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

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

> So if I do `sorted_list = my_list.sort()`, my `sorted_list` will be `none`

This is (one of) my biggest gripes with Python. It's utterly inconsistent with its design, and library designers have taken that to mean they also can do anything they want, leaving NumPy vs Pandas to have completely different class vs object stylings for instance. I reach for Python these days only when there's no other option because I'm 100% sure I'll spend 50% more time in the debugger than using Ruby for a similar problem.

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

#172
post #133
post #42

Earlier quoted context omitted.

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?

It is flagged, and it's impossible to downvote it. I wonder if its position is determined by its (frozen?) rating, or by its children rating?

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

#173

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…

If a language clearly states in the FM that something "criminal", in the words of your parent comment, is known to be criminal but they leave it as it is without any clear reason behind it (even recognizing it as a past error they have to carry for backward compatibility), the junior has all the right to think the language is criminal and is against them. In the extreme case, take something like brainfuck. Everything…

I don’t think it’s fair to say integer division is an error, it’s more so a lack of an abstraction of “number” over floats and ints.

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

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

I have, in the past, thought that it might be a good idea to allow `en+d` as a delimiter. So you'd have module A module B class C ennnd Fortunately, I am no longer suffering from whatever fever-induced hallucination brought on that particular deviation from good taste and decency.

I love it! Obviously not a good idea, but I can see where you're coming from and empathise very much!

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

#175
post #14

Earlier quoted context omitted.

I’ve tried so many stacks on side projects and always come back to RoR (with a bit of a grudge). I dislike many things about Ruby, but RoR is extremely hard to beat. Basically, everything you need in a stack is provided or readily available in the community.

Yeah. My usual advice to anyone who asks is "Use Rails unless you have a very good reason not to". Those reasons do exist, but they're pretty specific and don't apply 90% of the time. Of course if we're being really real, the first piece of advice should actually be "Can this be Wordpress?"

Why WordPress? I'll take a simple static website over wordpress anytime.

With wordpress:

- you are now suddenly also a database administrator

- the different people touching the admin interface will break things in subtle ways

- welcome an incomprehensible security nightmare into your life

Yes, wordpress is extremely easy to set up. Maintain? Nope!

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

#176

Earlier quoted context omitted.

Isn’t the double underscores __name would makes the method private?

No, that trick merely renames ("mangles") the method name: https://docs.python.org/3/reference/expressions.html#atom-id... This is very rarely used to try to achieve privacy in practice, not least because it's extremely easy to get around.

Sure it's only mangled. I'm Ruby you can also still call private methods via .send(:method_name).

IMO the goal of declaring something private is to make clear what you consider part of your object's public API and it's safe for others to call. It's mainly to protect callers from shooting themselves in the foot. Private provides no security. Your consumer will know better the actual situation they are in and if it's worthwhile taking the risk that your API might break them in the future or to write additional tests since they are doing something you as the author advise against. Of course it can also help enforce good design within your project. IMO it should be easy to bypass private constraints when a user makes that educated choice

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

#177

Earlier quoted context omitted.

> 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?

I have used all of those, but the design decision still doesn't make sense to me. Two instances of the same type might have absolutely nothing to do with each other in my domain.

def equals(other)

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

#178
post #60

Earlier quoted context omitted.

Ruby conventionally separates methods which modify the object from ones that don't by appending an exclamation mark to the method name. So `sort` returns a new sorted list, whereas `sort!` modifies the original list.

Strictly speaking the exclamation mark convention is for things that are "dangerous", in some sense. Modifying in-place is one sort of dangerous, but there are others, Process.exit! being one notable instance where the "modifying in place" thing is a bit of a stretch, and not really the thing you care about.

Thanks for the added information.

I'll argue that `Process.exit!` does modify the state of the program in place (which isn't the typical thing one thinks of when thinking of values). Without the bang, it's just a function call that throws an error, which can be caught and handled, so the logical state machine is unchanged. With the bang, it replaces the set of states the current program can be in to a single exit node.

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

#179
post #37

Earlier quoted context omitted.

it's a meme (image), so i can't copy it here: https://twitter.com/stylewarning/status/1772795474589987226

Old joke from usenet: > I have reverse engineered secret security algorithms used by the CIA and can break any message they encrypt. As proof, here is the last few lines of an implementation of their encryption function in Lisp )) ))) ))) ))))

It's from here: https://groups.google.com/g/rec.humor.funny/c/HjP_hKi49Ws/m/...

In other archives:

https://www.usenetarchives.com/view.php?id=rec.humor.funny&m...

and

https://www.netfunny.com/rhf/jokes/90q2/lispcode.html

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

#180
post #171
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…

> So if I do `sorted_list = my_list.sort()`, my `sorted_list` will be `none` This is (one of) my biggest gripes with Python. It's utterly inconsistent with its design, and library designers have taken that to mean they also can do anything they want, leaving NumPy vs Pandas to have completely different class vs object stylings for instance. I reach for Python these days only when there's no other option because I'm 1…

This is why you should use type hints and some kind of type checking.

sorted_list: list = my_list.sort()

will raise a red flag with a type checker.

Post reply on HN