请选择 进入手机版 | 继续访问电脑版

技术控

    今日:35| 主题:61447
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Smalltalk and protein programming

[复制链接]
梦中所念 发表于 2016-12-2 15:35:44
184 1
Analogies to help understand Eve

   Welcome to Part IV of my VI-part series about Eve , an exciting and fascinating new programming language.
         

Smalltalk and protein programming

Smalltalk and protein programming-1-技术控-foundation,understand,references,developed,released
      
       
  •   I. How Eve unifies your entire programming stack   
  •   II. When logic programming meets CQRS   
  •   III. Throwing off our scope chains   
  • IV. Smalltalk and protein programming    
  • V. The rock-solid foundation for Eve’s big vision (Monday 12/5)   
  • VI. Why Eve will be perfect for realtime apps (Thursday 12/8)  
  Smalltalk with stateless APIs

   One of Eve’s influences is Smalltalk , an innovative programming language developed at Xerox PARC and released in 1980. In Smalltalk, a running program consists of objects, each with their own independently-programmed behavior, passing messages to one another.
         

Smalltalk and protein programming

Smalltalk and protein programming-2-技术控-foundation,understand,references,developed,released
       Wikipedia explains that a Smalltalk object can do exactly three things:
  1. Hold state (references to other objects).
  2. Receive a message from itself or another object.
  3. In the course of processing a message, send messages to itself or another object.
   From 30,000 feet, Eve looks like Smalltalk because both kinds of programs are made out of self-contained chunks of code that can be dropped into a program, even while the program is running, which is called live programming .
  But once you zoom in and look at what the specific blocks are doing, the similarity breaks down: Smalltalk objects persist state between messages in lexical scope chains, while Eve blocks can only persist state between timesteps by writing to global databases.
   Instead of comparing Eve blocks to Smalltalk objects, it’s more accurate to compare them to API handlers , those blocks of server-side application-layer code that handle client requests to API endpoints.
  More precisely, Eve is similar to so-called “stateless” API handlers (ones that don't persist in-memory state between requests). Stateless API handlers are only allowed to do the following:
  
       
  • Read from a request buffer   
  • Manipulate local variables   
  • Manipulate database data   
  • Write to a response buffer  
   #2 and #3 are Eve’s bread and butter, and #1 and #4 are equivalent to manipulating the @request database (a subset of #3). So Eve is like Smalltalk with stateless APIs instead of objects.
  Protein programming

   Recall from biology class that proteins are stateless API handlers running in your cells. They get called to do interesting jobs like catalyze chemical reactions and transport molecules. When they finish the job, they don’t persist any state; they reset back to their original configuration.
   Have you ever wondered how cells call their little API handlers? Check out Sean Johnson’s Biology Stack Exchange answer for “How does a protein reach its substrate within the cell?” :
  The protein doesn’t move towards anything. It just randomly diffuses (bounces around) in the cell until it sticks to something. The particular chemical structure (the shape) of the protein and whatever it hits will determine how tightly they stick together and whether or not a chemical reaction occurs.
  […]
   Here’s a cool video that shows how proteins with a very specific shape bouncing around randomly can assemble into a complex structure.
  Now that we know the basic rules of “protein programming”, we can get some insight about Eve by looking at places where it’s similar to protein programming but different from mainstream programming:
  1. Live programming

   We’ve seen that Smalltalk and Eve are “live programming”  systems whose blocks of code can change without restarting the program.  Similarly, a cell’s set of proteins can change at runtime without needing to restart the cell. This is a special case of live programming called “life”.
  2. No single point of failure

  Any individual protein can get messed up and fail to do its job. But when a cell is deployed in an organism, it can’t afford to go offline for any reason. Luckily, no single protein failure can corrupt the cell’s state that much, so the vast majority of other cellular processes don’t care when single proteins fail. Furthermore, error-checking and redundancy can be layered in, in the form of other proteins.
  3. Programming without order

   In Glycolysis , glucose is broken down in a series of reactions in order to eventually create ATP , the “energy currency” of a cell. The whole process happens in the cell’s cytoplasm, a.k.a. that liquid where all the proteins bounce around like crazy.
         

Smalltalk and protein programming

Smalltalk and protein programming-3-技术控-foundation,understand,references,developed,released
       Glycolysis is a “metabolic pathway”, but the individual proteins don’t encode the fact that they’re part of anything larger — each one only encodes the logic for when to run and the state modifications it makes when it runs. The proteins just happen to be chainable in such a way that one’s output can be the next one’s input. In a cell, that timeless input-output chain structure ends up being mapped into an actual chain of events running in time; it’s just that the timing isn’t explicit in the proteins.
  Eve calls itself “programming without order” because its blocks of code don’t explicitly represent the order of their execution pathways, just like proteins don’t explicitly encode the glycolysis pathway.
  In a distributed system like a cell or database, implicitly ordered processes are more robust than ones that try to coordinate their timing explicitly. For example, during glycolysis, if one protein’s output gets gobbled up by some other cellular process, the metabolic pathway automatically knows not to keep running. And if that intermediate output later reappears, the metabolic pathway knows how to pick up where it left off.
  4. Code triggered by data

  Whenever there’s a glucose molecule hanging out in the cytoplasm, that’s when the first glycolysis protein calls itself in (a “hexokinase” in case you were wondering).
   Event-driven programming is a mainstream paradigm, but a glucose molecule hanging around is just ordinary data; it’s not an event. A glycolysis protein is a case of code triggered by data, just like an Eve block.
214531562 发表于 2016-12-2 21:21:56
顶起顶起顶起
回复 支持 反对

使用道具 举报

我要投稿

推荐阅读


回页顶回复上一篇下一篇回列表
手机版/c.CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 | 粤公网安备 44010402000842号 )

© 2001-2017 Comsenz Inc.

返回顶部 返回列表