Author here, I'd already shared it here. https://news.ycombinator.com/item?id=45644349
Some Smalltalk about Ruby Loops
21–30 of 59 posts
Re: Some Smalltalk about Ruby Loops
#22Earlier quoted context omitted.
Agreed. While I think matz is a great language designer, I loved Alan Kay's philosophy. I'd like some language that is OOP centric in nature, fast, has an elegant syntax and learns from erlang's model (elixir isn't it unfortunately, but some ideas it got right).
If you want OOP than, yes, Elixir isn't it... maybe Pony? Curious what else you don't like about Elixir though besides not being OOP... it's definitely got messaging!
Re: Some Smalltalk about Ruby Loops
#237 minutes of Pharroh Smalltalk for Rubyists: https://www.youtube.com/watch?v=HOuZyOKa91o
Re: Some Smalltalk about Ruby Loops
#24> But Python also looks up methods at runtime. Does that mean Python also does message passing? Not quite. I don't think Ruby's "message passing" is fundamentally different from Python's "method calls". Ultimately, both languages implementations are very similar: both look up methods by name in a hash table and then call them. IMO "message passing" is just an alternative metaphor for what Ruby does when you type `obj…
> both look up methods by name in a hash table and then call them. Except Ruby doesn't? cue `method_missing`. If you take only trivial examples you're not going to see much difference, this starts to show when you involve more advanced situations e.g with inheritance, and then you're drilling into singleton classes. > Ruby immediately calls the method once it's found, whereas Python (generally) doesn't - instead it r…
Re: Some Smalltalk about Ruby Loops
#25Standing on the shoulders of giants, I made this little abomination: https://rikspucko.koketteriet.se/bjoli/goof-loop
It handles 98% of all loops I write, meaning I don't have to manage state (even for things like treating things like circular data). I find it removes many of the stupid errors I make when iterating over data, especially when I need nested loops and conditional accumulation.
I find it so provoking that someone implemented foreach and went "yes. That should be enough for everyone!"
Re: Some Smalltalk about Ruby Loops
#26Earlier quoted context omitted.
> both look up methods by name in a hash table and then call them. Except Ruby doesn't? cue `method_missing`. If you take only trivial examples you're not going to see much difference, this starts to show when you involve more advanced situations e.g with inheritance, and then you're drilling into singleton classes. > Ruby immediately calls the method once it's found, whereas Python (generally) doesn't - instead it r…
Nice summary. I've been using Ruby both professionally and not for going on 20 years and I just today learned about singleton_class when attempting to build something like Rails' view helpers from first principles.
https://lloeki.github.io/illustrated-ruby/
Each chapter kind of builds up on the previous one. It's still WIP and far from complete but what's there has helped me onboard a few people to Ruby already.
You might be interested in the Classes and Ancestry chapters.
Re: Some Smalltalk about Ruby Loops
#27https://journal.stuffwithstuff.com/2013/01/13/iteration-insi...
https://journal.stuffwithstuff.com/2013/02/24/iteration-insi...
Re: Some Smalltalk about Ruby Loops
#28Anyone who likes this kind of stuff, highly recommend Metaprogramming Ruby [2] by Paolo Perrota. Great look into Ruby innards and inspiring code examples. Gets me pumped
Re: Some Smalltalk about Ruby Loops
#29Even something as basic as "if" is done with message passing and blocks in Smalltalk. There's a method named "ifTrue:ifFalse:" in Smalltalk (with each ":" expecting an argument, in this case, a block). You can also chain messages and make phrases: `anObject aMethod; anotherMethod; yourself.` The Ruby equivalent has repetition: `an_object.a_method; an_object.another_method; an_object` or requires a block: `an_object.t…
an_object.a_method.another_method
but, sure, it's less elegant (or at least less terse) than Smalltalk for the specific case of chaining invocations of methods with meaningful return values which are called for their side effects while discarding the return values.Re: Some Smalltalk about Ruby Loops
#30> But Python also looks up methods at runtime. Does that mean Python also does message passing? Not quite. I don't think Ruby's "message passing" is fundamentally different from Python's "method calls". Ultimately, both languages implementations are very similar: both look up methods by name in a hash table and then call them. IMO "message passing" is just an alternative metaphor for what Ruby does when you type `obj…
Ruby Instances can have their own methods and override methods separate from their class.