TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Gelidum – My Python library to freeze objects

43 pointsby diegojromeroalmost 4 years ago

7 comments

diegojromeroalmost 4 years ago
Per advice from Daniel from HN (thank you!), I have reposted this Ask HN I made earlier about immutability. [1]<p>I was thinking the other day about my days working with Ruby On Rails and how the strings are mutable in Ruby and the freeze method. My mind wandered about that, the several freeze packages that exist (even the frozendict [2] package) that make frozen classes of objects.<p>I haven&#x27;t worked professionally with Haskell or Erlang, but some of their functional capabilities are nice and have ejerced a big influence in my work with Ruby on Rails and Python. Specially the ideas of having immutable objects and keeping updates at minimum.<p>I thought on doing a freeze package that could make frozen objects recursively in Python. The idea is to make easier to share objects between threads without having to worry about updates inside threads.<p>However, I&#x27;m not sure that this package is useful at all. Maybe is because Python is not a well-suited language for this? Maybe is because my lack of knowledge about functional programming? Maybe is because it doesn&#x27;t make sense to &quot;freeze&quot; objects?<p>Some ideas I have in the back of my mind for this package are:<p>- Some kind of basic datastore-server where data is immutable (threaded server?). - Storing all updates some kind of super-object by storing all history as immutable objects.<p>What are some sources to learn about immutability on programing languages? How could you use a freeze package in Python or other languages? Would it be useful to share information between threads?<p>Any advice&#x2F;idea&#x2F;feeback&#x2F;criticism or comment on this matter is appreciated.<p>[1] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27503947" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27503947</a><p>[2] <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;frozendict&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;frozendict&#x2F;</a>
评论 #27510139 未加载
评论 #27509852 未加载
whalesaladalmost 4 years ago
I try to treat real&#x2F;physical Python objects as disposable. Everything in the runtime can be recreated from something else - be it a file on disk, a table in a DB, redis, a blob on S3, etc… and try not to put too much weight on the actual objects themselves. Modifying an object is really not something I ever do. I&#x2F;O is dealt with elsewhere. I guess you could call it a hybrid approach of functional programming where objects are just used as structs that might have a few methods for synthetic properties.<p>For that reason I’m having a tough time seeing the use case for this. I could see it being useful with “bad” code that mutates things it shouldn’t… but can’t really think of a way I’d integrate this in an environment where I control most or all of the code.
评论 #27510416 未加载
评论 #27512587 未加载
trinovantesalmost 4 years ago
I wish more languages have the concept of &quot;object&#x2F;memory freezing&quot; especially at runtime, similar to runtime assertion checks, but without using 3rd party compiler plugins to instrument my code.<p>C++&#x27;s insane &quot;const * const&quot; syntax makes it hard to conceptualize when I just want &quot;create object, do bunch of non trivial stuff, freeze object forever&quot;
评论 #27510361 未加载
评论 #27510168 未加载
emefalmost 4 years ago
<p><pre><code> # on_update=&quot;nothing&quot;: does nothing when an update is tried frozen_shared_state = freeze(shared_state, on_update=&quot;nothing&quot;) frozen_shared_state.count = 4 # Does nothing, as this update did not exist </code></pre> yikes. Thoughts on when this feature would ever be useful? Just the thought of working in a codebase with this subtle inconsistency makes me cringe.
评论 #27510658 未加载
评论 #27512615 未加载
nickysielickialmost 4 years ago
I like the purity that might come with decorating basically everything in a codebase with `@freeze_params()`, although I wonder&#x2F;worry about what the runtime overhead might be. I really wish that something like that could be checked statically.
评论 #27510881 未加载
评论 #27512628 未加载
m_muelleralmost 4 years ago
FYI there is also<p><pre><code> @dataclass(frozen=True) </code></pre> this tends to be enough for my usecases. you can still circumvent (and sometimes have to in dataclass post_init) with object.__setattr__.
评论 #27512876 未加载
slava_kiosealmost 4 years ago
Such a question. Why does the function keep adding the default value &quot;baz&quot; to the existing list every time foo () is called, instead of creating a new list every time?