TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

State and time are the same thing

63 点作者 BerislavLopac9 个月前

19 条评论

nickdrozd9 个月前
For anyone who finds this sort of discussion interesting, I highly recommend reading Chapter 3 of <i>The Structure and Interpretation of Computer Programs</i>. There is quite a bit of philosophical musing about the connection between time and state. For example:<p>&gt; The basic phenomenon here is that synchronizing different processes, establishing shared state, or imposing an order on events requires communication among the processes. In essence, any notion of time in concurrency control must be intimately tied to communication. It is intriguing that a similar connection between time and communication also arises in the Theory of Relativity, where the speed of light (the fastest signal that can be used to synchronize events) is a fundamental constant relating time and space. The complexities we encounter in dealing with time and state in our computational models may in fact mirror a fundamental complexity of the physical universe.<p><a href="https:&#x2F;&#x2F;mitp-content-server.mit.edu&#x2F;books&#x2F;content&#x2F;sectbyfn&#x2F;books_pres_0&#x2F;6515&#x2F;sicp.zip&#x2F;full-text&#x2F;book&#x2F;book-Z-H-23.html#%_idx_3720" rel="nofollow">https:&#x2F;&#x2F;mitp-content-server.mit.edu&#x2F;books&#x2F;content&#x2F;sectbyfn&#x2F;b...</a>
评论 #41383737 未加载
senkora9 个月前
State changes that are internal to a function and not visible are sometimes called &quot;benign effects&quot; in functional programming. A function can be considered &quot;pure&quot; if it has only benign effects, which is a relaxation on the stricter requirement that a pure function have no (side) effects at all.
kstenerud9 个月前
This is a dangerous way to think about it. State and time are different things, and if you think of them as the same, then your mental model glosses over some parts of reality that will become important as your software grows more complex.<p>State is inherently dangerous BECAUSE a program runs TEMPORALLY. As the number of state changes increases, the dangers of an unwanted state increase (particularly insidious are the state combinations you thought weren&#x27;t even possible). This is why functional programmers favor immutability and idempotent functions.<p>Also: Just because the EXTERNAL observability of state hasn&#x27;t changed is no reason to assume that no state changes have occurred. Hidden state changes are the most dangerous of all.
评论 #41380748 未加载
评论 #41381544 未加载
KaiserPro9 个月前
For the room, yes, state and time happen to be the same thing.<p>However for a lot of systems thats not the case. Worrying about hidden state is the enemy of joy.<p>Sure, if you are doing shared things, or exposing the internals of something to the world, then yes, you need to be paranoid. But, marshalling things so that state is in a known and guarded place is a much better way to think about things.<p>State is basically the computer science version of an egg drop. There are many ways to make it work, some more complex than others. but worrying about sudden cross winds[0] isn&#x27;t the way to make sure your egg doesn&#x27;t shatter when it hits the floor.<p>[0] unless your arena has active cross winds of substance.
IMTDb9 个月前
I&#x27;d argue that the way we define &quot;state&quot; as being &quot;a set of things that matter to us&quot;. In the context of the article, if we define state as being a &quot;state vector of (hours, minutes, seconds)&quot; we explicitly exclude everything but these three value (miliseconds, date, etc). The two pictures with the hands pointing to the same umber then by definition <i>are</i> the same. We can even consider them as being the same &quot;every 24 hour&quot;.<p>The distinction between single threaded or multi threaded is moot; the world is in perpetual mutation anyway; even is two lines of code are being executed at exactly the same time in a multithreaded fashion, one is executed on CPU A and one on CPU B so their &quot;environment&quot; is different and there will never be two lines of code that are executed in exactly the same environment - regardless of what tools and techniques you use to try and enforce reproducibility.<p>What matters is to explicitly define what you consider as having an impact (which you add in the &quot;state&quot;) and what you don&#x27;t (which you leave out).
评论 #41382906 未加载
tantalor9 个月前
A finger pointing at the moon is not the moon.<p>The map is not the territory.
评论 #41381771 未加载
jerf9 个月前
It might be better to say &quot;changes in state are time&quot;.<p>This is a deeper understanding of what time is than the common one we have... but... since &quot;the common one we have&quot; is the result of living in a universe that is absolutely constantly pounding state changes into us every Planck-time of our lives, and I don&#x27;t know about you but I&#x27;m not building anything that I expect to exist in some sort of ontologically different state, you can do rather a lot of work with the &quot;intuitive&quot; concept of time. Even complicated server communications which are fast enough that the fact that relativity bans &quot;simultaneous&quot; becomes relevant can be understood just fine in an intuitive framework.<p>I do find it helpful to conceive of time as &quot;state changes occurring&quot; for a particular case, though, which is multithreaded programming. It is helpful to conceive of threads as &quot;perceiving&quot; time not as ticks on a clock, but changes in the state (which can be to a first approximation be &#x27;lines of code executed&#x27;). From this point of view, threads do not experience time as a clock ticking onward, but as &quot;a particular value that exists but only when they look&quot;. That is to say, if a thread &quot;consults the clock&quot; and determines that it is noon on Jan 1st, it can be helpful as a programmer to understand that that does not particularly mean that three lines later, it will be noon on Jan 1st. Arbitrary amounts of universe-time can progress between any two lines of code. Threads really relate to each other not across universe-clock time, but by what observable effects other threads cause on them, and <i>only</i> on what observable effects other threads have on them. In principle, two threads that cause no effects visible to the other are essentially running in different universes. This is a place that a mathematical mindset can really help.<p>But, again, this is just a sort of helpful thing for relatively advanced mental modeling, but you can get a long way just based on assuming a monotonic universe-clock.<p>This is why I assert, with some vigor but without much persistence (since it&#x27;s obviously a <i>massively</i> uphill battle), that a clock-simulating library really should not be based on assuming threads will witness a monotonic universe clock, and a clock-simulating library ought to make it possible to test that a task nominally scheduled to come after some other task actually runs to completion before the first task even starts, because that can happen in the real world. In an imperative language, you can assume that one statement within a thread will follow another, and that the external threads you can see are also operating in that order, but the slip <i>between</i> those &quot;ticks&quot; can be arbitrarily large.
评论 #41383798 未加载
zackmorris9 个月前
I realized this around 2016 while working in PHP&#x2F;Laravel and realizing that mutation=state=time.<p>I use higher-order methods like map&#x2F;reduce&#x2F;filter now, storing temporary results in variables when needed (although PHP&#x27;s lack of const variables is a travesty). PHP&#x27;s functional model of receiving data, transmuting it with the help of copy-on-write arrays, and returning it with a possible side effect stored in a database, all in an independent process, is one of the best around IMHO. It&#x27;s too bad that legacy mistakes&#x2F;features in the language and performance inefficiencies in operating system multiprocessing implementations (Windows, cough) obfuscate how powerful this model is.<p>Most&#x2F;all of the complexity in debugging comes from mutation and side effects. Unfortunately nearly every language gets this wrong. Python has a huge emphasis on mutating variables rather than returning values that can be piped to the next function. Rust goes to great lengths with its borrow checker to allow mutation when copy-on-write would negate most of the need for that. I&#x27;d like to see a language and even an operating system that piped data around rather than mutating it in place, with an accepted cost of taking about twice as much memory to accomplish it. Then code could be mapped directly to spreadsheet form, and code execution could be mapped to diffs between state transitions to provide rewind functionality and debugging for free.<p>I would love to work on a paradigm like this if I had any spare money and time at all to do it. I&#x27;ve waited since the 90s for what I consider basic features, but sadly almost no language got this stuff right in the time since. Which leaves me with the unfortunate impression that probably 90% of the work we do in programming is a waste of time. Imagine if that wasted effort had gone towards solving foundational problems in programming for the benefit of all, instead of internet lottery winners just rolling their profits into their next venture.
评论 #41388140 未加载
评论 #41383942 未加载
jmull9 个月前
I think a more useful way to put it is:<p>State is a value in a system that may change over time.<p>I would like to add “… that can be accessed from more than one scope”, but that doesn’t quite match common usage of the term so might just cause confusion.<p>The distinction is useful, though, because values that change over time but only exist in one scope are easy to reason about and handle correctly, while ones shared across scopes can cause no end of problems if not well organized. Maybe we can use terms something like “trivial state” and “significant state”.<p>(And, yes, we’d also need to define “scope”. I think the intuitive&#x2F;common meaning is enough to get the point across though.)
kwoff9 个月前
I know it&#x27;s about programming, but I have a thought experiment I think about occasionally. Imagine a universe with one point particle. There&#x27;s no time or space. Add another particle. The particles can either be separate or at the same point. So in some sense there is time, since we can go between separate and together states. There still isn&#x27;t space, I think? Is this a philosophical subject I can read about?
评论 #41391197 未加载
评论 #41387441 未加载
gibsonf19 个月前
Actually, a state is when a measurable attribute of an object remains unchanged for a period of time. So saying state = time completely misses what a state is.
评论 #41384275 未加载
评论 #41383839 未加载
评论 #41384168 未加载
taeric9 个月前
I think this is a useful way to model a simulation. Probably a good way to reason about bugs and how a program works.<p>However, I question if you want to try and embrace this on anything that takes on user input. It would be one thing if we had temporal logic based programming models. But I don&#x27;t know if any program that does.
deterministic9 个月前
I think about it this way:<p>A state is an identifier for a sequence of &quot;atomically&quot; changing values.<p>By &quot;atomically&quot; I mean before&#x2F;after an event is handled end-to-end.
phkahler9 个月前
Completely disagree with the title. A system - especially software - can return to the same state at a later time. It makes no sense to conflate the two. It&#x27;s telling that the author deliberately starts with a clock as an example - something whose state is supposed to reflect time.<p>The main point seems to be one about hidden state or unobservable internal state, and I&#x27;m all in favor of having that. One of my preferred ways to make software subsystems (particularly in embedded devices) is to use a state machine. To the outside software there may be only a handful of visible states - NOT_READY, READY, MODE1, MODE2, MODE3, FAULTED. But internally there may be any number of intermediate states - several startup states hidden behind NOT_READY, several transitional steps in mode changes, etc. When switching modes I prefer to report the old mode until a transition is complete and then show the new mode as the current state to the outside world. IMHO you don&#x27;t want to report &quot;in transition&quot; or anything like that, the outside may need to tolerate some time going by before getting what it wants, but it&#x27;s not needed to know what&#x27;s happening internally. You either get there or fault. The simplification from what&#x27;s happening to what&#x27;s reported is important to reduce the spread of complexity.
slowhadoken9 个月前
They’re not the same but you could say that time is a special case of statefulness.
AtlasBarfed9 个月前
Are they saying I just need to let the universe reach the desired state I want it in as a totally deterministic universe,then merely record that timestamp?<p>To read my data, I wait for the gnab gib to restart the phone universe?
yawnxyz9 个月前
from having built a bunch of tiny indie games in a prior life (in Flash :P), time = state, and time = world<p>and depending on what games we&#x27;re building, either we record actions as state changes (eg chess &#x2F; turn based games: if no moves are made, time didn&#x27;t elapse), or &quot;real-time&quot; games (eg chess w&#x2F; a world state like a clock)
lilyball9 个月前
This is reminding me of Functional Reactive Programming all those years ago
rhelz9 个月前
Maybe change of state is the same thing as time?