frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Some Smalltalk about Ruby Loops

https://tech.stonecharioteer.com/posts/2025/ruby-loops/
66•birdculture•1w ago

Comments

stonecharioteer•6d ago
Author here, I'd already shared it here.

https://news.ycombinator.com/item?id=45644349

xutopia•3h ago
Thank you for this article. It makes it easier to explain to newcomers to Ruby why not to use the `for` keyword.
stonecharioteer•1h ago
Thanks for reading. I didn't expect to hit HN Front page a second time this month!!
stonecharioteer•57m ago
You might like my other post too

https://tech.stonecharioteer.com/posts/2025/ruby-blocks/

Joker_vD•3h ago
> Leaving the handling of the loop to the method allows us to add behaviour to loops that are controlled by the object and not by the user. This is a nice way to add side-effects.

No, it's an absolutely horrible way to "add side-effects" which, usually, is already a horrible idea in its own right.

> Asking an object to iterate over itself allows objects to develop interfaces that dictate how to iterate.

That's true in pretty much any language? And since you need to know which iteration interface you need to use, it's not that much of an advantage.

> And now, when I see: `10.times { |i| puts "i = #{i}" }` I do not see a loop anymore.

Yeah, because it's not a loop: it may or may not run that block 10 times. Seriously, when a programmer's intention is "run something 10 times", the resulting expression arguably should not be "send that something to someone who, hopefully, will execute it 10 times".

pansa2•3h ago
> 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 `object.name`. The metaphor fits Ruby but not Python, because the languages do three things differently:

- Ruby only looks for `name` in `object.class` (and its superclasses), whereas Python first looks in `object` itself

- If Ruby finds `name`, it's guaranteed to be a method whereas in Python it could be a different kind of value

- Ruby immediately calls the method once it's found, whereas Python (generally) doesn't - instead it returns a binding to be called later

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

In Python, `object.name` is a more general value lookup - maybe the result will be callable, maybe not.

shevy-java•2h ago
But here you refer to implementation details. Isn't the point about message passing that objects themselves communicate with one another through such messages? And in turn, messages can also be assumed to be small objects. I don't think any of those implementations really fulfil that as a meaning. Or perhaps I misunderstood Alan Kay here. He drew inspiration more from biological cells and communication pathways therein. Naturally biology can not be mapped 1:1 onto in-silico hardware, that wouldn't even make sense either - but for instance, erlang's model appears to me closer to different objects happily communicating with one another in a very flexible, safe, fault-tolerant manner. I don't think it is the implementation detail that is about message passing. I also don't think "sending a message" is the confinement either - it's an important but, but does not appear to capture all that is meant with a "message". A message could be many things, including objects that themselves could change at any moment in time again. I see it more as an intrinsic part of communication at all times.
lloeki•1h ago
> 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 returns a binding to be called later

Again incorrect, `foo.bar` in Ruby and Python are two very fundamentally different things.

Python returns a binding to a method because it's an attribute accessor; when you throw inheritance into the mix it ends up that that attribute is inherited from the parent class, bound to the instance (which really in python means pass `self` as first argument), and - schematically - adding `()` after that ends up calling that bound method. If there's no attribute that's a no method error. It's all very C-ish and make believe, barely a notch above Go structs and their functions. The closest parallel in Ruby would be `foo.method(:bar).call()`

By contrast Ruby is going to send the :bar message along the inheritance chain, and if someone can respond it's going to invoke the responder's code, and surprise surprise method_missing happens only if it has exhausted inheritance but it's itself a method-slash-message; Oh and by the way the message passing is naturally so lazy that you can actually modify the inheritance chain -in flight- and inject a parent responder right before calling `super`. The whole notion of `binding` is a very concrete construct, way more rich that simply "hey I'm passing self as first argument". It becomes even more strange to "C&al. folks" when you start to involve singleton classes and start to realise weird things like Ruby classes are merely instances of the class Class and it's all instance turtles all the way down and all stupidly simple but you gotta have to wrap your head around it.

I surmise that so many differences and surprises have with Ruby are because most languages have some ALGOL legacy and Ruby is a conceptual heir to Smalltalk (and LISP†); the whole concept of open classes being another one: nothing is ever "finished" in Ruby!

Most of the time you don't have to care about these differences, until you do.

† While code isn't quite S-expr data in Ruby, there are more than enough first-class facilities that you can create and inject code entirely dynamically without resorting to `eval`ing strings.

top_sigrid•2h ago
Like Alan Kay himself said, it wasn't about objects, but about messaging. [0]

[0] https://lists.squeakfoundation.org/pipermail/squeak-dev/1998...

shevy-java•2h ago
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).
bglusman•40m ago
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!
skywhopper•2h ago
I loved Smalltalk when I had to learn it for my first job out of college. Clean and clear OO with a flexible, play-inside-of-your-code runtime. Unfortunately the Smalltalk community is pretty small.

So imagine my delight when I found Ruby in 2005. It took the best of Perl and the best of Smalltalk and gave it a much better syntax than either, plus it had a massively growing community.

Ruby breaks a lot of the rules for what people claim they want (or should be allowed) from a programming language these days, but for me there’s still no more joyful and easy programming language to express my ideas.

pjmlp•1h ago
Not all the best parts of Smalltalk, otherwise a IDE based experience with a JIT compiler would be there from the early days, that is an integral part of Smalltalk experience as developer.
lazyvar•2h ago
I think this misses the point. `times` is "better" than `for` because it's declarative, reads like English, etc. Which of course are opinions, but the implementation details (messaging passing or not) are irrelevant.

Example: Swift and Kotlin can do `Int#times` and don't need message passing to get it done.

dominicrose•1h ago
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.tap { _1.a_method; _1.another_method}` (and we usually use newlines instead of ";")

wry_discontent•1h ago
I have found that chaining things in Smalltalk get immensely painful after just a couple elements. Unlike most other languages, I find myself reaching for silly little var names for lots of different things I would normally just let flow.
stonecharioteer•57m ago
Damn, I'm a fulltime Ruby blogger now?
throwaway106382•17m ago
7 minutes of Pharroh Smalltalk for Rubyists: https://www.youtube.com/watch?v=HOuZyOKa91o

Ventoy: Create Bootable USB Drive for ISO/WIM/IMG/VHD(x)/EFI Files

https://github.com/ventoy/Ventoy
139•wilsonfiifi•1h ago•48 comments

987654321 / 123456789

https://www.johndcook.com/blog/2025/10/26/987654321/
267•ColinWright•4d ago•41 comments

Affinity Studio Now Free

https://www.affinity.studio/get-affinity
26•dagmx•14m ago•14 comments

US declines to join more than 70 countries in signing UN cybercrime treaty

https://therecord.media/us-declines-signing-cybercrime-treaty?
124•pcaharrier•1h ago•56 comments

Show HN: In a single HTML file, an app to encourage my children to invest

https://roberdam.com/en/dinversiones.html
120•roberdam•5h ago•208 comments

Uv is the best thing to happen to the Python ecosystem in a decade

https://emily.space/posts/251023-uv
2061•todsacerdoti•21h ago•1150 comments

ZOZO's Contact Solver (for physics-based simulations)

https://github.com/st-tech/ppf-contact-solver
9•vintagedave•47m ago•1 comments

Estimating the Perceived 'Claustrophobia' of New York City's Streets (2024)

http://mfranchi.net/posts/claustrophobic-streets/
50•jxmorris12•2h ago•29 comments

Replacing EBS and Rethinking Postgres Storage from First Principles

https://www.tigerdata.com/blog/fluid-storage-forkable-ephemeral-durable-infrastructure-age-of-agents
60•mfreed•1d ago•24 comments

Free software scares normal people

https://danieldelaney.net/normal/
17•cryptophreak•1h ago•6 comments

Typst's Math Mode Problem

https://laurmaedje.github.io/posts/math-mode-problem/
71•marcianx•5d ago•28 comments

Tell HN: Azure outage

839•tartieret•1d ago•765 comments

Language models are injective and hence invertible

https://arxiv.org/abs/2510.15511
171•mazsa•6h ago•121 comments

Spinning Up an Onion Mirror Is Stupid Easy

https://flower.codes/2025/10/23/onion-mirror.html
133•speckx•1w ago•49 comments

Minecraft removing obfuscation in Java Edition

https://www.minecraft.net/en-us/article/removing-obfuscation-in-java-edition
896•SteveHawk27•23h ago•385 comments

Some Smalltalk about Ruby Loops

https://tech.stonecharioteer.com/posts/2025/ruby-loops/
66•birdculture•1w ago•18 comments

Frozen DuckLakes for Multi-User, Serverless Data Access

https://ducklake.select/2025/10/24/frozen-ducklake/
4•g0xA52A2A•5d ago•0 comments

How ancient people saw themselves

https://worldhistory.substack.com/p/how-ancient-people-saw-themselves
199•crescit_eundo•4d ago•124 comments

The Aesthete's Progress

https://sydneyreviewofbooks.com/essays/the-aesthetes-progress
10•pepys•6d ago•0 comments

Raspberry Pi Pico Bit-Bangs 100 Mbit/S Ethernet

https://www.elektormagazine.com/news/rp2350-bit-bangs-100-mbit-ethernet
228•chaosprint•16h ago•64 comments

3D solar tower increases capacity factor 50%, triples solar surface area

https://www.pv-magazine.com/2025/10/27/3d-solar-tower-increases-capacity-factor-50-triples-solar-...
45•geox•2h ago•24 comments

Hello-World iOS App in Assembly

https://gist.github.com/nicolas17/966a03ce49f949dd17b0123415ef2e31
141•pabs3•13h ago•50 comments

Kafka is Fast – I'll use Postgres

https://topicpartition.io/blog/postgres-pubsub-queue-benchmarks
478•enether•1d ago•333 comments

Dithering – Part 1

https://visualrambling.space/dithering-part-1/
395•Bogdanp•21h ago•84 comments

Keep Android Open

http://keepandroidopen.org/
2592•LorenDB•1d ago•816 comments

The Internet runs on free and open source software and so does the DNS

https://www.icann.org/en/blogs/details/the-internet-runs-on-free-and-open-source-softwareand-so-d...
228•ChrisArchitect•21h ago•39 comments

Board: New game console recognizes physical pieces, with an open SDK

https://board.fun/
251•nicoles•1d ago•121 comments

GLP-1 therapeutics: Their emerging role in alcohol and substance use disorders

https://academic.oup.com/jes/article/9/11/bvaf141/8277723?login=false
241•PaulHoule•2d ago•168 comments

Tailscale Peer Relays

https://tailscale.com/blog/peer-relays-beta
338•seemaze•23h ago•100 comments

AOL to be sold to Bending Spoons for $1.5B

https://www.axios.com/2025/10/29/aol-bending-spoons-deal
272•jmsflknr•23h ago•249 comments