Live data from Hacker News

Some Smalltalk about Ruby Loops

tech.stonecharioteer.com

21–30 of 59 posts

Re: Some Smalltalk about Ruby Loops

#22

Earlier 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!

A robust static type system is what was missing for me, at least last time I looked.

Re: Some Smalltalk about Ruby Loops

#24
post #11
post #5

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

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.

Re: Some Smalltalk about Ruby Loops

#25
Leaving the comfort of lisp, I have started to wonder: why are all the looping facilities in other languages so awful?

Standing 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

#26
post #24
post #11

Earlier 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.

Thanks. I've been trying to put these bits in a succinct format:

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

#27
I like this article a lot but if you want to dig deeper and understand some of the negative consequences of Ruby's approach, you might like these two articles I wrote:

https://journal.stuffwithstuff.com/2013/01/13/iteration-insi...

https://journal.stuffwithstuff.com/2013/02/24/iteration-insi...

Re: Some Smalltalk about Ruby Loops

#28
Love Ruby. Wish I could use it more often. Always end up reaching for Python in day-to-day because of how mature and well-docunented the libs are.

Anyone 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

#29

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

In Ruby, methods called mainly for side effects rather than return value conventionally return the object itself, and so can be chanined by:

  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
post #5

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

> This means that in Ruby, `object.name` is always calling a method defined on `object.class`, with `self` set to `object`. That can be re-interpreted as "sending a message" to `object.class`.

Ruby Instances can have their own methods and override methods separate from their class.

Post reply on HN