Hacker Newsnew | past | comments | ask | show | jobs | submit | more levodelellis's commentslogin

I'm the author. No, I completely disagree. No one ever complains about logs and malloc except having too much of them - A line I removed from this article

The next article has examples and IMO much better, but makes no mention of action at a distance, and currently makes no mention of how people use clone to prevent mutability.


I dont understand how your comment relates to my comment, beyond that you disagree.


I like mutation in global variables. I don't think it's the problem. I'm explaining it in my next article


Ouch, I partially address this in the next article


Only if it's const. Otherwise the data is copied into memory you can write to


Isn’t there a part of the data segment that is writable? Initialized vs uninitialized data segment right?


You're right, I know mutable and read-only are separates, I know I seen gcc and clang put static int and global int in the same page, and I know I heard people say global variables are on the heap thousands of times. I guess I forgot global writable data doesn't necessarily mean heap nor the read-only section of memory


I didn't mind. I knew I'd hear a lot of disagreements and incorrect thoughts. My next article has a lot of examples which should make things easier to digest.

One thing I dislike about compsci is everyone has different definitions for everything. If people say static variables are not on the heap fine, but you can easily see the address of a static variable and global variable being in the same 4K page


What do you suppose is the recommended way to use the encapsulation? ;) This is partly why there's a "defining global variables" section, I know people will will consider some usage as not using a global


> What do you suppose is the recommended way to use the encapsulation? ;) This is partly why there's a "defining global variables" section, I know people will will consider some usage as not using a global

What the post discusses can be distilled into the concept of Referential Transparency[0]:

  A linguistic construction is called referentially 
  transparent when for any expression built from it, 
  replacing a subexpression with another one that denotes the 
  same value[b] does not change the value of the expression.
Any construct which is not referentially transparent can be classified as potentially effectual, which is not a Bad Thing(TM) as if there were no observable effects of a program, it would be useless.

What makes programs easier to prove correct and reason about is when effects are localized to well-defined areas often "at the edges" of the architecture.

What makes programs impossible to prove correct and very difficult to reason about is when effectual logic is pervasive throughout, such as most of the "Global Variable Use Cases" the post advocates.

0 - https://en.wikipedia.org/wiki/Referential_transparency


You might like the article I wrote for next week. Could you tell me where this post is linked from? I didn't think anyone would see this when no one commented the first day


You may hate my article next week, it's meant to replace this article. If you want you can email me for early access and tell me how I can improve the article. Lets say you can guess my email if you're emailing the right domain


That's exactly why I used this specific example. I seen many code bases that use clone to avoid mutation problems so I wrote this specifically to show it can become a problem too.

I wrote a better article on globals. I plan on posting it next week


This seems more an issue with not understanding structuralClone, than one of understanding globals or lack thereof. There’s nothing wrong with the example, it does exactly what the code says it should — if you want counter to be “global” then structuralClone isn’t the function you want to call. The bug isn’t in how counter was in obj, the bug is in calling structuralClone when its behaviour wasn’t wanted.

With that said, it seems obvious that if you want to globally count the calls, then that count shouldn’t live in an argument where you (the function) don’t control its lifetime or how global it actually is. Simple has no say over what object obj.counter points to, it could trivially be a value type passed into that particular call, so if you know you want a global count then of course storing it in the argument is the wrong choice.

Global has two conflated meanings: global lifetime (ie lifetime of the whole program) and global access (which the article states). Simple needs global lifetime but not global access.

You rarely ”need” global access, although for things like a logger it can be convenient. Often you do need global lifetime.


Could you tell me where this was posted? I thought no one would see this after I got no comments the first day

No one I showed this to complained about the first example but online many people did. I wrote a completely different article which I think is much better that uses examples I would have used in the follow up. I'll post that article next week


Second chance pool. This post is, per your submission history, from 2 days ago. HN has a second chance pool that lets articles continue collecting upvotes (more easily than digging through the full history). Some of those articles will get their timestamp updated to artificially inflate their ranking. This brings them to the front page again and gives them their "second chance". After a few hours or whatever time, the timestamp is reverted and they'll start falling back into their natural place in the rankings.

https://news.ycombinator.com/submitted?id=levodelellis

https://news.ycombinator.com/lists

https://news.ycombinator.com/pool


See my comment above. After I learned a few essentials that are not mentioned the game became very reasonable and more enjoyable


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: