frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Ruby Symbols

https://tech.stonecharioteer.com/posts/2025/ruby-symbols/
21•stonecharioteer•5d ago

Comments

Mystery-Machine•1h ago
Symbols are a foot gun.

> Symbols aren’t interchangeable though.

    user = { name: "Alice", age: 30 }
    puts user[:name] # Alice
    puts user["name"] # nil

I'm 100% convinced that every Ruby developer has at least once made a bug where they tried to access a hash entry using a symbol, where the key was actually a string or vice-versa.

It would be great if Ruby would finally have immutable strings by default and, at that point, it would be possible to make symbols be strings. This would prevent any such user[:name] vs user["name"] bugs while not breaking any other functionality. And also keeping the memory "optimized" by reusing a single immutable string.

Lio•1h ago
Sure, we wouldn't have ActiveSupport::HashWithIndifferentAccess if it wasn't an occasional issue.
shevy-java•1h ago
Agreed. However had it should also be mentioned that this originated from rails.

Many bad things originate from the rails ecosystem. (Arguably some good too, but I am very pessimistic ever since shopify's recent powermove and DHH side-line commenting off-the-fence while being on shopify's board.)

Lio•36m ago
Rails has paid my salary for the best part of 20 years on and off. I'm OK with it. ;)
shevy-java•1h ago
> I'm 100% convinced that every Ruby developer has at least once made a bug where they tried to access a hash entry using a symbol, where the key was actually a string or vice-versa.

Yeah, that is true. It adds a cognitive load onto the ruby developer writing the code as well. Personally I prefer symbols as keys in a Hash, mostly because I like symbols, I assume it may be faster usually (this depends on factors, such as how many symbols one uses, the garbage collection kicking off and so forth, but by and large I think for most use cases, Symbols are simply more efficient). We also have abominations such as HashWithIndifferentAccess; Jeremy wrote an article why that is not good (indirectly, e. g. the article he wrote was about Symbols more, their use cases and differences to Strings, but from this it follows that HashWithIndifferentAccess is not a good idea. While I agree, I think some people simply don't want to have to care either way).

If I need to query a hash often, I tend to write a method, and the method then makes sure any input is either a string or a symbol for that given Hash.

> It would be great if Ruby would finally have immutable strings by default

But it has. I still use "# frozen_string_literal: true", but if you omit it, the Strings are frozen by default. People could set "# frozen_string_literal: true" in a .rb file if they want to retain the old behaviour.

> it would be possible to make symbols be strings.

But Symbols are not Strings. And bugs based on x[:foo] versus x['foo'] are always going to happen. They are very easy to avoid though. I don't really run into these in my own code, largely because I settled on symbols as keys for a Hash.

> And also keeping the memory "optimized" by reusing a single immutable string.

But a Symbol is not a String. Not even an immutable String. I understand what you mean (and internally it may be that way already, actually), but it is not a String.

Mystery-Machine•1h ago
I also prefer symbols as keys in hash. It just looks more aesthetically pleasing. :) I think the optimization string vs symbol is negligent in most of the apps. If you need that level of optimization, you should probably switch to Rust.

> If I need to query a hash often, I tend to write a method, and the method then makes sure any input is either a string or a symbol for that given Hash.

This is terrible. This is the exact opposite of what Ruby is trying to achieve: developer happiness. You basically implement "symbol is a string" for hashes (aka HashWithIndifferentAccess).

> But it has. I still use "# frozen_string_literal: true", but if you omit it, the Strings are frozen by default.

This is not the case. If you omit "# frozen_string_literal: true", the strings are mutable, in all versions of Ruby, even in Ruby 4.0, which will be released on 25 Dec.

> But a Symbol is not a String. Not even an immutable String. I understand what you mean (and internally it may be that way already, actually), but it is not a String.

If it walks like a duck and quacks like a duck... Who cares? What's the difference it makes for you whether symbols and string are interchangeable? Show me one valid use-case where having symbols and strings being different (user[:name] vs user["name"], or attr_reader "name") is useful.

an0malous•1h ago
That’s not much more of a foot gun than:

    user[“1”] = user[1]
Symbols are always taught as a first class object in Ruby, not just syntactic sugar for accessing hashes. “foo” does not equal :foo
IshKebab•32m ago
The foot-gun there is dynamic typing, not symbols.
thomascountz•20m ago
Here's a fantastic writeup about frozen strings in Ruby and the upcoming changes: https://byroot.github.io/ruby/performance/2025/10/28/string-...
masklinn•29m ago
OP is really tying themselves into knots.

Symbols are special cased pseudo-strings for langages which have either extremely inefficient strings (erlang) or mutable ones (ruby). That’s about the extent of it.

Python or Java don’t really have a use for them because their strings are immutable, and likely interned when metaprogramming is relevant (e.g. method or attribute names).

Joker_vD•4m ago
What about LISPs? They have atoms too.
Ecco•28m ago
I think the whole article is super confusing.

A Symbol is really just a string!

Well, it's a string that will guarantee unique allocations (two identical strings are guaranteed to be allocated at the same address), which makes equality checks super fast (compare pointers directly). But pretty much just a string nonetheless...

How Quake.exe got its TCP/IP stack

https://fabiensanglard.net/quake_chunnel/index.html
165•billiob•3h ago•15 comments

Cloudflare Global Network experiencing issues

https://www.cloudflarestatus.com/incidents/8gmgl950y3h7
98•meetpateltech•18m ago•33 comments

The Uselessness of "Fast" and "Slow" in Programming

https://jerf.org/iri/post/2025/the_uselessness_of_fast/
22•zdw•6d ago•4 comments

How many video games include a marriage proposal? At least one

https://32bits.substack.com/p/under-the-microscope-ncaa-basketball
242•bbayles•4d ago•54 comments

Cloudflare, X, More are down

https://www.cloudflarestatus.com/?t=1
359•imdsm•31m ago•198 comments

Show HN: I built a synth for my daughter

https://bitsnpieces.dev/posts/a-synth-for-my-daughter/
1157•random_moonwalk•5d ago•198 comments

Ruby Symbols

https://tech.stonecharioteer.com/posts/2025/ruby-symbols/
21•stonecharioteer•5d ago•12 comments

Unofficial "Tier 4" Rust Target for older Windows versions

https://github.com/rust9x/rust
97•kristianp•9h ago•50 comments

Azure hit by 15 Tbps DDoS attack using 500k IP addresses

https://www.bleepingcomputer.com/news/microsoft/microsoft-aisuru-botnet-used-500-000-ips-in-15-tb...
368•speckx•18h ago•250 comments

When Reverse Proxies Surprise You: Hard Lessons from Operating at Scale

https://www.infoq.com/articles/scaling-reverse-proxies/
42•miggy•4d ago•3 comments

The Miracle of Wörgl

https://scf.green/story-of-worgl-and-others/
4•simonebrunozzi•1h ago•0 comments

Compiling Ruby to machine language

https://patshaughnessy.net/2025/11/17/compiling-ruby-to-machine-language
257•todsacerdoti•16h ago•45 comments

Rebecca Heineman has died

https://www.pcgamer.com/gaming-industry/legendary-game-designer-programmer-space-invaders-champio...
566•shdon•10h ago•84 comments

My stages of learning to be a socially normal person

https://sashachapin.substack.com/p/my-six-stages-of-learning-to-be-a
492•eatitraw•2d ago•323 comments

Comparing Android Alternatives: Lineage OS, ∕E∕OS, and Graphene OS

https://kevinboone.me/lineage-eos-graphene.html
14•ingve•2h ago•0 comments

Langfuse (YC W23) Hiring OSS Support Engineers in Berlin and SF

https://jobs.ashbyhq.com/langfuse/5ff18d4d-9066-4c67-8ecc-ffc0e295fee6
1•clemo_ra•5h ago

Astrophotographer snaps skydiver falling in front of the sun

https://www.iflscience.com/the-fall-of-icarus-you-have-never-seen-an-astrophotography-picture-lik...
396•doener•2d ago•78 comments

Project Gemini

https://geminiprotocol.net/
291•andsoitis•20h ago•165 comments

FreeMDU: Open-source Miele appliance diagnostic tools

https://github.com/medusalix/FreeMDU
307•Medusalix•22h ago•82 comments

The surprising benefits of giving up

https://nautil.us/the-surprising-benefits-of-giving-up-1248362/
100•jnord•7h ago•81 comments

Show HN: Parqeye – A CLI tool to visualize and inspect Parquet files

https://github.com/kaushiksrini/parqeye
116•kaushiksrini•12h ago•30 comments

Ditch your (mut)ex, you deserve better

https://chrispenner.ca/posts/mutexes
81•commandersaki•6d ago•69 comments

Windows 11 adds AI agent that runs in background with access to personal folders

https://www.windowslatest.com/2025/11/18/windows-11-to-add-an-ai-agent-that-runs-in-background-wi...
473•jinxmeta•12h ago•408 comments

Run ancient UNIX on modern hardware

https://github.com/felipenlunkes/run-ancient-unix
103•doener•14h ago•23 comments

LeJEPA

https://arxiv.org/abs/2511.08544
48•nothrowaways•9h ago•12 comments

Raccoons are showing early signs of domestication

https://www.scientificamerican.com/article/raccoons-are-showing-early-signs-of-domestication/
162•pavel_lishin•3d ago•127 comments

How when AWS was down, we were not

https://authress.io/knowledge-base/articles/2025/11/01/how-we-prevent-aws-downtime-impacts
170•mooreds•18h ago•62 comments

WeatherNext 2: Our most advanced weather forecasting model

https://blog.google/technology/google-deepmind/weathernext-2/
263•meetpateltech•21h ago•118 comments

Show HN: ESPectre – Motion detection based on Wi-Fi spectre analysis

https://github.com/francescopace/espectre
179•francescopace•21h ago•45 comments

Aldous Huxley predicts Adderall and champions alternative therapies

https://angadh.com/inkhaven-7
107•surprisetalk•21h ago•125 comments