<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Learn-Shitao5</title>
<link>https://learn.shitao5.org/</link>
<atom:link href="https://learn.shitao5.org/index.xml" rel="self" type="application/rss+xml"/>
<description>Here are Shitao5&#39;s study notes.</description>
<generator>quarto-1.4.553</generator>
<lastBuildDate>Sat, 23 Mar 2024 16:00:00 GMT</lastBuildDate>
<item>
  <title>Efficient Linux at the Command Line</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240324-efficient-linux/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: 23%.</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/35776782/" class="uri">https://book.douban.com/subject/35776782/</a></li>
<li>翻译来自 ChatGPT 3.5 和 ChatGPT 4</li>
</ul>
</div>
</div>
<section id="core-concepts" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> <strong>Core Concepts</strong>
</h1>
<section id="combining-commands" class="level2" data-number="1.1"><h2 data-number="1.1" class="anchored" data-anchor-id="combining-commands">
<span class="header-section-number">1.1</span> <strong>Combining Commands</strong>
</h2>
<ul>
<li>
<p>The Linux command line is different. Instead of big applications with tons of features, Linux supplies thousands of small commands with very few features.</p>
<blockquote class="blockquote">
<p>Linux命令行不同于此。与具有大量功能的大型应用程序不同，Linux提供了数千个功能很少的小型命令。</p>
</blockquote>
</li>
<li>
<p>Linux makes it easy to combine commands so their individual features work together to accomplish your goal. This way of working yields a very different mindset about computing. Instead of asking “Which app should I launch?” to achieve some result, the question becomes “Which commands should I combine?”</p>
<blockquote class="blockquote">
<p>Linux使得将命令组合在一起，使它们的各个功能共同完成你的目标变得很容易。这种工作方式产生了一种非常不同的计算思维。与其问“我应该启动哪个应用程序？”以实现某个结果，问题变成了“我应该组合哪些命令？”</p>
</blockquote>
</li>
<li>
<p>The vertical bar (<code>|</code>) between the commands is the Linux pipe symbol. It connects the first command’s stdout to the next command’s stdin. Any command line containing pipes is called a <em>pipeline</em>. Commands generally are not aware that they’re part of a pipeline. <code>ls</code> believes it’s writing to the display, when in fact its output has been redirected to <code>less</code>. And <code>less</code> believes it’s reading from the keyboard when it’s actually reading the output of <code>ls</code>.</p>
<blockquote class="blockquote">
<p>命令之间的竖线（<code>|</code>）是Linux管道符号。它将第一个命令的标准输出连接到下一个命令的标准输入。任何包含管道的命令行都称为管道线。通常命令并不知道它们是管道线的一部分。<code>ls</code>认为它正在向显示器写入，而实际上它的输出已被重定向到<code>less</code>。<code>less</code>认为它正在从键盘读取，而实际上它正在读取<code>ls</code>的输出。</p>
</blockquote>
</li>
<li>
<p>Unlike virtually every other Linux command, <code>ls</code> is aware of whether stdout is the screen or whether it’s been redirected (to a pipe or otherwise). The reason is user-friendliness. When stdout is the screen, <code>ls</code> arranges its output in multiple columns for convenient reading. When stdout is redirected, however, <code>ls</code> produces a single column.</p>
<blockquote class="blockquote">
<p>与几乎所有其他 Linux 命令不同，<code>ls</code> 能够感知到 stdout 是屏幕还是已被重定向（到管道或其他地方）。原因是为了用户友好性。当 stdout 是屏幕时，<code>ls</code> 将其输出排列成多列，方便阅读。然而，当 stdout 被重定向时，<code>ls</code> 则会生成单列。</p>
</blockquote>
</li>
</ul></section><section id="introducing-the-shell" class="level2" data-number="1.2"><h2 data-number="1.2" class="anchored" data-anchor-id="introducing-the-shell">
<span class="header-section-number">1.2</span> <strong>Introducing the Shell</strong>
</h2>
<ul>
<li>
<p>The wildcard is handled entirely by the shell.</p>
<blockquote class="blockquote">
<p>通配符完全由shell处理。</p>
</blockquote>
</li>
<li>
<p>Shell pattern matching applies only to file and directory paths.&nbsp;It doesn’t work for usernames, hostnames, and other types of arguments that certain commands accept.</p>
<blockquote class="blockquote">
<p>Shell 模式匹配仅适用于文件和目录路径。它不适用于用户名、主机名和某些命令接受的其他类型的参数。</p>
</blockquote>
</li>
<li>
<p>A variable is a name that stands in for a value. The shell also has names that stand in for commands. They’re called <em>aliases</em>.</p>
<blockquote class="blockquote">
<p>变量是代表值的名称。Shell 还有代表命令的名称，它们被称为别名。</p>
</blockquote>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> alias g=grep                 A command with no arguments</span>
<span id="cb1-2"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> alias ll=<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ls -l"</span>             A command with arguments: quotes are required</span></code></pre></div>
</li>
<li>
<p>Aliases take precedence&nbsp;over commands of the same name.</p>
<blockquote class="blockquote">
<p>别名优先于同名的命令。</p>
</blockquote>
</li>
<li>
<p>Output redirection has a partner, <em>input redirection</em>, that redirects stdin to come from a file instead of the keyboard. Use the symbol <code>&lt;</code> followed by a filename to redirect stdin.</p>
<blockquote class="blockquote">
<p>输出重定向有一个伴侣，即输入重定向，它将 stdin 重定向到来自文件而不是键盘。使用符号 &lt; 后跟文件名来重定向 stdin。</p>
</blockquote>
</li>
<li>
<p>A leading backslash before an alias escapes the alias, causing the shell to look for a command of the same name, ignoring any shadowing.</p>
<blockquote class="blockquote">
<p>在别名前加上反斜杠可以转义该别名，这会导致 shell 寻找同名的命令，忽略任何可能的覆盖。</p>
</blockquote>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> alias less=<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"less -c"</span>        Define an alias</span>
<span id="cb2-2"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> less myfile                 Run the alias, which invokes less <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-c</span></span>
<span id="cb2-3"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\l</span>ess myfile                Run the standard less command, not the alias</span></code></pre></div>
</li>
<li>
<p>When the shell searches for a command by name, it checks if that name is an alias before checking the search path. That’s why an alias can shadow (take precedence over) a command of the same name.</p>
<blockquote class="blockquote">
<p>当 Shell 按名称搜索一个命令时，它会在检查搜索路径之前检查该名称是否为一个别名。这就是为什么一个别名可以遮蔽（优先于）一个同名的命令。</p>
</blockquote>
</li>
</ul></section><section id="rerunning-commands" class="level2" data-number="1.3"><h2 data-number="1.3" class="anchored" data-anchor-id="rerunning-commands">
<span class="header-section-number">1.3</span> Rerunning Commands</h2>
<ul>
<li>
<p>The shell appends commands to the history, verbatim, unevaluated. The one exception to this rule is history expansion. Its expressions are always evaluated before they’re added to the command history.</p>
<blockquote class="blockquote">
<p>Shell 将命令原样、未经评估地添加到历史中。这条规则的唯一例外是历史扩展。它的表达式在添加到命令历史之前总是先被评估。</p>
</blockquote>
</li>
</ul></section><section id="cruising-the-filesystems" class="level2" data-number="1.4"><h2 data-number="1.4" class="anchored" data-anchor-id="cruising-the-filesystems">
<span class="header-section-number">1.4</span> Cruising the Filesystems</h2>


<!-- -->

</section></section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Linux</category>
  <guid>https://learn.shitao5.org/posts/20240324-efficient-linux/</guid>
  <pubDate>Sat, 23 Mar 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240324-efficient-linux/cover.png" medium="image" type="image/png" height="85" width="144"/>
</item>
<item>
  <title>漫长的危机</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240321-mcdwj/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: 9%.</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/30157597/" class="uri">https://book.douban.com/subject/30157597/</a></li>
</ul>
</div>
</div>
<section id="前言" class="level1 unnumbered"><h1 class="unnumbered">前言</h1>
<ul>
<li><p>总体来看，从20世纪80年代初开始，在市场自律环境中的新一轮放松财政管控和不加节制的信用消费浪潮就已经席卷全球。</p></li>
<li><p>苏联的解体使资本主义制度没有了敌人，也开启了一个新的阶段：人们开始相信“历史的终结”和以持续股市行情看涨为基础的“新增长”。</p></li>
<li><p>我们正处于并将长期处于一个历史时期：经济发达国家的财富积累量稳步提升，而生产率和收入增长则十分缓慢。</p></li>
</ul></section><section id="漫长的危机" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 漫长的危机</h1>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Economics</category>
  <guid>https://learn.shitao5.org/posts/20240321-mcdwj/</guid>
  <pubDate>Wed, 20 Mar 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240321-mcdwj/cover.png" medium="image" type="image/png" height="82" width="144"/>
</item>
<item>
  <title>Statistical Thinking for the 21st Century</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240302-statsthinking21/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: 7.21%.</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://statsthinking21.github.io/statsthinking21-core-site/index.html" class="uri">https://statsthinking21.github.io/statsthinking21-core-site/index.html</a></li>
<li><a href="https://github.com/statsthinking21/statsthinking21-core" class="uri">https://github.com/statsthinking21/statsthinking21-core</a></li>
<li>翻译来自 ChatGPT 3.5</li>
</ul>
</div>
</div>
<section id="preface" class="level1 unnumbered"><h1 class="unnumbered">Preface</h1>
<ul>
<li>
<p>This book focuses on understanding the basic ideas of <em>statistical thinking</em> – a systematic way of thinking about how we describe the world and use data make decisions and predictions, all in the context of the inherent uncertainty that exists in the real world.</p>
<div>
<blockquote class="blockquote">
<p>本书侧重于理解统计思维的基本理念——这是一种系统性思考我们如何描述世界、利用数据做决策和预测的方式，所有这些都在现实世界固有的不确定性背景下进行。</p>
</blockquote>
</div>
</li>
<li><p>The only way to really learn statistics is to <em>do</em> statistics.</p></li>
</ul></section><section id="introduction" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> Introduction</h1>
<ul>
<li><p>Statistical thinking will one day be as necessary for efficient citizenship as the ability to read and write. — H.G. Wells</p></li>
<li><p>Statistical thinking provides us with the tools to more accurately understand the world and overcome the biases of human judgment.</p></li>
<li><p>One way to think of statistics is as a set of tools that enable us to learn from data. In any situation, we start with a set of ideas or <em>hypotheses</em> about what might be the case. Another way to think of statistic is as “the science of throwing away data”.</p></li>
<li>
<p>Statistics provides us with a way to describe how new data can be best used to update our beliefs, and in this way there are deep links between statistic and psychology. In fact, many theories of human and animal learning from psychology are closely aligned with ideas from the new field of <em>machine learning</em>. Machine learning is a field at the interface of statistics and computer science that focuses on how to build computer algorithms that can learn from experience. While statistics and machine learning often try to solve the same problems, researchers from these fields often take very different approaches; the famous statistician Leo Breiman once referred to them as “The Two Cultures” to reflect how different their approaches can be. In this book I will try to blend the two cultures together because both approaches provide useful tools for thinking about data.</p>
<div>
<blockquote class="blockquote">
<p>统计学为我们提供了一种描述新数据如何最好地用于更新我们信仰的方法，这样统计学与心理学之间存在深刻的联系。事实上，许多心理学中关于人类和动物学习的理论与新兴的机器学习领域的思想密切相关。机器学习是统计学和计算机科学交界处的一个领域，重点研究如何构建能够从经验中学习的计算机算法。虽然统计学和机器学习通常试图解决相同的问题，但来自这些领域的研究人员通常采取非常不同的方法；著名的统计学家 Leo Breiman 曾将它们称为“两种文化”，以反映它们的方法之间有多么不同。在本书中，我将尝试将这两种文化融合在一起，因为两种方法都为思考数据提供了有用的工具。</p>
</blockquote>
</div>
</li>
<li>
<p>Statistics provides us with the tools to characterize uncertainty, to make decisions under uncertainty, and to make predictions whose uncertainty we can quantify.</p>
<div>
<blockquote class="blockquote">
<p>统计学为我们提供了表征不确定性、在不确定性下做出决策以及对我们可以量化不确定性的预测的工具。</p>
</blockquote>
</div>
</li>
<li>
<p>Statistics can provide us with evidence, but it’s always tentative and subject to the uncertainty that is always present in the real world.</p>
<div>
<blockquote class="blockquote">
<p>统计学可以为我们提供证据，但它始终是暂时的，并受到现实世界中始终存在的不确定性的影响。</p>
</blockquote>
</div>
</li>
<li>
<p>In fact, the rate at which the benefit of larger samples decreases follows a simple mathematical rule, growing as the square root of the sample size, such that in order to double the precision of our estimate we need to quadruple the size of our sample.</p>
<div>
<blockquote class="blockquote">
<p>事实上，随着样本规模的增大，较大样本的益处减小的速率遵循一个简单的数学规律，按照样本大小的平方根增长，这意味着为了提高我们的估计精度，我们需要将样本的大小增加四倍。</p>
</blockquote>
</div>
</li>
<li>
<p>Although observational research cannot conclusively demonstrate causal relations, we generally think that causation can be demonstrated using studies that experimentally control and manipulate a specific factor. In medicine, such a study is referred to as a <em>randomized controlled trial</em> (RCT).</p>
<div>
<blockquote class="blockquote">
<p>尽管观察性研究不能最终证明因果关系，但我们通常认为，可以使用实验性地控制和操作特定因素的研究来证明因果关系。在医学中，这样的研究被称为随机对照试验（RCT）。</p>
</blockquote>
</div>
</li>
<li>
<p>Researchers often try to address these confounds using statistical analyses, but removing the influence of a confound from the data can be very difficult.</p>
<div>
<blockquote class="blockquote">
<p>研究人员通常尝试使用统计分析来解决这些混淆问题，但从数据中消除混淆的影响可能非常困难。</p>
</blockquote>
</div>
</li>
</ul></section><section id="working-with-data" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> Working with data</h1>
<ul>
<li><p>The first important point about data is that data <em>are</em> – meaning that word “data” is plural (though some people disagree with me on this).</p></li>
<li><p>In many fields such as psychology, the thing that we are measuring is not a physical feature, but instead is an unobservable theoretical concept, which we usually refer to as a <em>construct</em>. It is usually impossible to measure a construct without some amount of error.</p></li>
<li><p>When we think about what makes a good measurement, we usually distinguish two different aspects of a good measurement: it should be <em>reliable</em>, and it should be <em>valid</em>.</p></li>
<li><p>Reliability refers to the consistency of our measurements. One common form of reliability, known as “test-retest reliability”, measures how well the measurements agree if the same measurement is performed twice.</p></li>
<li>
<p>Reliability is important if we want to compare one measurement to another, because the relationship between two different variables can’t be any stronger than relationship between either of the variables and itself (i.e., its reliability). This means that unreliable measure can never have a strong statistical relationship with any other measure. For this reason, researchers developing a new measurement (such as a new survey) will often go to great lengths to establish and improve its reliability.</p>
<div>
<blockquote class="blockquote">
<p>如果我们想要将一个测量结果与另一个进行比较，可靠性就非常重要，因为两个不同变量之间的关系不可能比任何一个变量与其自身之间的关系更强（即其可靠性）。这意味着一个不可靠的测量永远不可能与任何其他测量有强烈的统计关系。因此，开发新测量（如新调查）的研究人员通常会极力确立和改善其可靠性。</p>
</blockquote>
</div>
</li>
<li>
<p>We want our measurements to also be <em>valid</em> — that is, we want to make sure that we actually measuring the construct that we think we are measuring.</p>
<ul>
<li><p><em>Face validity.</em> Does the measurement make sense on its face?</p></li>
<li><p><em>Construct validity</em>. Is the measurement related to other measurements in an appropriate way?</p></li>
<li><p><em>Predictive validity</em>. If our measurements are truly valid, then they should be predictive of other outcomes.</p></li>
</ul>
</li>
</ul></section><section id="summarizing-data" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> Summarizing data</h1>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Data Science</category>
  <guid>https://learn.shitao5.org/posts/20240302-statsthinking21/</guid>
  <pubDate>Fri, 01 Mar 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240302-statsthinking21/cover.png" medium="image" type="image/png" height="75" width="144"/>
</item>
<item>
  <title>权力的 48 条法则</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240228-48laws-power/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: 12.41%.</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/2158889/" class="uri">https://book.douban.com/subject/2158889/</a></li>
</ul>
</div>
</div>
<section id="前言" class="level1 unnumbered"><h1 class="unnumbered">前言</h1>
<ul>
<li><p>与其抗拒必然的规律去争论、怨恨或充满罪恶感，还不如努力精于权力之道为好。实际上，你越善于操控权力，你就越能成为一个好朋友、好情人、好丈夫或好妻子。遵循成功朝臣的权力之道，你将会使别人感觉更好，成为他们快乐的源泉。他们将仰仗你的才能，渴望聚集在你的周围。</p></li>
<li><p>对任何情况或局面都产生情绪上的反应是通向权力道路最大的障碍，这样的错误会让你付出巨大的代价。</p></li>
<li><p>欺骗和伪装不应该简单地看成是丑恶的和不道德的，人与人之间的交集互动在很多方面都需要欺骗。</p></li>
<li><p>在本质上，权力是与道德无关的，是超越道德范畴的。要想获取权力，最重要的技能之一，就是能够根据形势变化而不是根据善恶来洞察情势，做出判断和应对。权力就是一场竞赛，这句话必须多次重复。在这场竞赛中，一切都以行动的结果而不是对手的道德意图来决定输赢。</p></li>
<li><p>永远不要去区分谁是你应该研究的，谁是你可以信赖的。永远不要完全信任任何人，而应该研究每一个人，包括朋友和你所爱的人。</p></li>
</ul></section><section id="永远不要盖过上司的光芒" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 永远不要盖过上司的光芒</h1>
<ul>
<li><p>所有的上司都希望自己看起来比别人更杰出。</p></li>
<li><p>你不可能一辈子都在意别人琐碎的感受而忧心忡忡，但是对于权位比你高的人，你必须采取不同的策略和方式。如果你想要获得权力，而你却盖过上司的光芒，这恐怕是最严重的错误。</p></li>
</ul></section><section id="永远不要太信任朋友学会如何利用敌人" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> 永远不要太信任朋友，学会如何利用敌人</h1>
<ul>
<li><p>有许多人认为聪明的君主，在有机会的时候，应该巧妙地挑起仇恨和敌意，然后通过镇压这些敌意，以增强他的威望和伟大。君主，尤其是新的君主，会在那些他刚刚掌权时有所怀疑的人身上，找到更多的信任和更大的用处，而不是一开始他就信任的人。西耶那国王佩特鲁齐人用了更多原来他心存怀疑的人来治理他的国家。 ——马基雅维利</p></li>
<li><p>在你决定任用你的朋友的时候，你会逐渐发现他们隐藏起来的特质，奇怪的是，正是你的仁慈一举打破了所有事情应有的平衡。人们都愿意认为自己的幸运是自然而言理所当然的，接受恩惠会使他们觉得有无形的压力——这意味着被选中并不一定是因为他足堪大任，而仅仅因为你们是朋友！任用朋友难免会有施恩或屈尊的味道，会令朋友内心感觉到莫名其妙的痛苦。这种伤害会渐渐地显示出来：朋友好像比过去更加诚实，但时不时会表露出怨恨的嫉妒，等你知道这些的时候，友谊已经悄悄褪色。你想付出更多的恩惠和礼物来恢复友谊，相反你获得的感激却越少。</p></li>
<li><p>利用或任用朋友的问题在于，它自然而然地会限制你的权力。朋友很少是那些最能够帮助你的人，最后你会发现，技能和才干远比友谊的感觉要重要得多。</p></li>
<li><p>在所有的工作环境里，都要与他人保持一定距离。你是要努力工作，而不是交朋友。友情（不论真或假）只会使事情混淆不清。因此，权力的要点在于能够判断谁最能干，能够在各种不同的情况下使你的利益最大化。友谊归友谊，事业需要的是技能和才干。</p></li>
<li><p>一个人如果要努力证明自己的价值，他就会有排山倒海的力量。</p></li>
</ul></section><section id="隐藏你的意图" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> 隐藏你的意图</h1>
<ul>
<li><p>在欺瞒的过程中，不论在哪一点上，如果人们对你的意图起了最轻微的疑心，你也会满盘皆输。你不要给别人任何机会察觉到你的意图。你需要巧布疑阵转移人们的注意力；装出虚假的诚实，释放模棱两可的信号，树起误导的目标。由于分辨不出真假，人们就无法弄清你真正的意图。</p></li>
<li><p>诱惑必须完全依赖于暗示，你不可以公开宣布你的意图或直截了当地把它们说出来。相反，你必须欺瞒你所诱惑的对象，让他摸不着头脑，最后屈从于你的指示。</p></li>
<li><p>千万不要被人看成是骗子，即便是不施骗术就无以为生。要用最巧妙的办法掩盖最高明的诡计。 ——葛拉西安</p></li>
<li><p>虚情假意，言不由衷，同时放出误导的信息，瞒过所有的人，隐藏住真正的目的，最终得到他想要的一切——这就是掩盖你的真正意图的强大威力。</p></li>
<li><p>事实上，诚实是一把钝刀子，割得不快，血还流得特别多。你的诚实很容易冒犯别人，比较谨慎的做法是好好修饰你的语言，说别人想听的话，而不是告诉他们你的感受或你思考的丑陋的事实真相。更为重要的是，毫无掩饰的开放会让你一览无遗，人们根本不会敬重或畏惧你。别人不敬重或畏惧的人，权力是不会光临的。</p></li>
<li><p>人们很容易把热诚误认为诚实。记住，人的第一直觉总是相信外表。他们很看重诚实而且愿意相信周围的人都是诚实的，因此很少会怀疑你或看穿你行为的目的。</p></li>
<li><p>最高明的骗子会想尽各种办法掩盖他们流氓无赖的本质。他们在某个方面表现出来的诚实是为了掩盖他们在其他方面的不诚实。诚实只是他们武器库中用来欺骗的道具。</p></li>
<li>
</li></ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Self Development</category>
  <guid>https://learn.shitao5.org/posts/20240228-48laws-power/</guid>
  <pubDate>Tue, 27 Feb 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240228-48laws-power/cover.png" medium="image" type="image/png" height="96" width="144"/>
</item>
<item>
  <title>谈美</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240226-tanmei/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Completed.🎉</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/26838438/" class="uri">https://book.douban.com/subject/26838438/</a></li>
</ul>
</div>
</div>
<section id="序言" class="level1 unnumbered"><h1 class="unnumbered">序言</h1>
<p>孟实先生还写了一部大书——《文艺心理学》。但这本小册子并非节略；它自成一个完整的有机体；有些处是那部大书所不详的；有些是那里面没有的。——“人生的艺术化”一章是著名的例子；这是孟实先生自己最重要的理论。他分人生为广狭两义：艺术虽与“实际人生”有距离，与“整个人生”却并无隔阂；“因为艺术是情趣的表现，而情趣的根源就在人生。反之，离开艺术也便无所谓人生；因为凡是创造和欣赏都是艺术的活动”。他说：“生活上的艺术家也不但能认真而且能摆脱。在认真时见出他的严肃，在摆脱时见出他的豁达。”又引西方哲人之说：“至高的善在无所为而为的玩索”，以为这“还是一种美”。又说：“一切哲学系统也都只能当作艺术作品去看。”又说：“真理在离开实用而成为情趣中心时，就已经是美感的对象……所以科学的活动也还是一种艺术的活动。”这样真善美便成了三位一体了。孟实先生引读者由艺术走入人生，又将人生纳入艺术之中。这种“宏远的眼界和豁达的胸襟”，值得学者深思。文艺理论当有以观其会通；局于一方一隅，是不会有真知灼见的。 （2024-02-26 23:22:43）</p>
</section><section id="开场话" class="level1 unnumbered"><h1 class="unnumbered">开场话</h1>
<p>现在的青年不应该再有复杂错乱的心境了，他们所需要的不是一盆八宝饭而是一帖清凉散。 （2024-02-27 07:30:48）</p>
<p>我坚信中国社会闹得如此之糟，不完全是制度的问题，是大半由于人心太坏。我坚信情感比理智重要，要洗刷人心，并非几句道德家言所可了事，一定要从“怡情养性”做起，一定要于饱食暖衣、高官厚禄等之外，别有较高尚、较纯洁的企求。要求人心净化，先要求人生美化。 （2024-02-27 07:31:39）</p>
<p>人要有出世的精神才可以做入世的事业。现世只是一个密密无缝的利害网，一般人不能跳脱这个圈套，所以转来转去，仍是被“利害”两个大字系住。在利害关系方面，人己最不容易调协，人人都把自己放在首位，欺诈、凌虐、劫夺种种罪孽都种根于此。美感的世界纯粹是意象世界，超乎利害关系而独立。在创造或是欣赏艺术时，人都是从有利害关系的实用世界搬家到绝无利害关系的理想世界里去。艺术的活动是“无所为而为”的。我以为无论是讲学问或是做事业的人都要抱有一副“无所为而为”的精神，把自己所做的学问事业当作一件艺术品看待，只求满足理想和情趣，不斤斤于利害得失，才可以有一番真正的成就。伟大的事业都出于宏远的眼界和豁达的胸襟。如果这两层不讲究，社会上多一个讲政治经济的人，便是多一个借党忙官的人；这种人愈多，社会愈趋于腐浊。现在一般借党忙官的政治学者和经济学者以及冒牌的哲学家和科学家所给人的印象只要一句话就说尽了——“俗不可耐”。 人心之坏，由于“未能免俗”。什么叫作“俗”？这无非是像蛆钻粪似的求温饱，不能以“无所为而为”的精神做高尚纯洁的企求；总而言之，“俗”无非是缺乏美感的修养。 （2024-02-27 07:33:27）</p>
</section><section id="我们对于一棵古松的三种态度-实用的科学的美感的" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 我们对于一棵古松的三种态度—— 实用的、科学的、美感的</h1>
<p>知觉不完全是客观的，各人所见到的物的形象都带有几分主观的色彩。 （2024-02-27 07:39:05）</p>
<p>极平常的知觉都带有几分创造性；极客观的东西之中都有几分主观的成分。 （2024-02-27 07:40:25）</p>
<p>科学的态度则不然。它纯粹是客观的、理论的。所谓客观的态度就是把自己的成见和情感完全丢开，专以“无所为而为”的精神去探求真理。理论是和实用相对的。理论本来可以见诸实用，但是科学家的直接目的却不在于实用。 （2024-02-27 07:42:55）</p>
<p>科学的态度之中很少有情感和意志，它的最重要的心理活动是抽象的思考。科学家要在这个混乱的世界中寻出事物的关系和条理，纳个物于概念，从原理演个例，分出某者为因，某者为果，某者为特征，某者为偶然性。 （2024-02-27 07:45:37）</p>
<p>注意力的集中，意象的孤立绝缘，便是美感的态度的最大特点。 （2024-02-27 07:46:52）</p>
<p>他不计较实用，所以心中没有意志和欲念；他不推求关系、条理、因果等，所以不用抽象地思考。这种脱净了意志和抽象思考的心理活动叫作“直觉”，直觉所见到的孤立绝缘的意象叫作“形象”。美感经验就是形象的直觉，美就是事物呈现形象于直觉时的特质。 （2024-02-27 07:47:38）</p>
<p>实用的态度以善为最高目的，科学的态度以真为最高目的，美感的态度以美为最高目的。在实用态度中，我们的注意力偏在事物对于人的利害，心理活动偏重意志；在科学的态度中，我们的注意力偏在事物间的互相关系，心理活动偏重抽象的思考；在美感的态度中，我们的注意力专在事物本身的形象，心理活动偏重直觉。真善美都是人所定的价值，不是事物所本有的特质。离开人的观点而言，事物都浑然无别，善恶、真伪、美丑就漫无意义。真善美都含有若干主观的成分。 （2024-02-27 07:48:12）</p>
<p>在有所为而为的活动中，人是环境需要的奴隶；在无所为而为的活动中，人是自己心灵的主宰。 （2024-02-27 22:34:53）</p>
<p>悠悠的过去只是一片漆黑的天空，我们所以还能认识出来这漆黑的天空者，全赖思想家和艺术家所散布的几点星光。朋友，让我们珍重这几点星光！让我们也努力散布几点星光去照耀那和过去一般漆黑的未来！ （2024-02-27 22:36:56）</p>
</section><section id="当局者迷旁观者清-艺术和实际人生的距离" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> “当局者迷，旁观者清”—— 艺术和实际人生的距离</h1>
<p>持实用的态度看事物，它们都只是实际生活的工具或障碍物，都只能引起欲念或嫌恶。要见出事物本身的美，我们一定要从实用世界跳开，以“无所为而为”的精神欣赏它们本身的形象。总而言之，美和实际人生有一个距离，要见出事物本身的美，须把它摆在适当的距离之外去看。 （2024-02-27 22:41:10）</p>
<p>正身和实际人生没有距离，倒影和实际人生有距离，美的差别即起于此。 （2024-02-27 22:42:20）</p>
<p>一般人迫于实际生活的需要，都把利害认得太真，不能站在适当的距离之外去看人生世相，于是这丰富华严的世界，除了可效用于饮食男女的营求之外，便无其他意义。 （2024-02-27 22:45:20）</p>
<p>说话不押韵，不论平仄，作诗却要押韵，要论平仄，道理也是如此。艺术本来是弥补人生和自然缺陷的。如果艺术的最高目的仅在妙肖人生和自然，我们既已有人生和自然了，又何取乎艺术呢？ （2024-02-27 22:49:47）</p>
<p>富于艺术材料的生活何以不能产生艺术呢？艺术所用的情感并不是生糙的而是经过反省的。蔡琰在丢开亲生子回国时绝写不出《悲愤诗》，杜甫在“入门闻号咷，幼子饥已卒”时绝写不出《自京赴奉先县咏怀五百字》。这两首诗都是“痛定思痛”的结果。艺术家在写切身的情感时，都不能同时在这种情感中过活，必定把它加以客观化，必定由站在主位的尝受者退为站在客位的观赏者。一般人不能把切身的经验放在一种距离以外去看，所以情感尽管深刻，经验尽管丰富，终不能创造艺术。 （2024-02-28 03:52:10）</p>
</section><section id="子非鱼安知鱼之乐-宇宙的人情化" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> “子非鱼，安知鱼之乐”—— 宇宙的人情化</h1>
<p>移情作用不一定就是美感经验，而美感经验却常含有移情作用。美感经验中的移情作用不单是由我及物的，同时也是由物及我的；它不仅把我的性格和情感移注于物，同时也把物的姿态吸收于我。所谓美感经验，其实不过是在聚精会神之中，我的情趣和物的情趣往复回流而已。 （2024-02-28 03:59:30）</p>
<p>真正的美感经验都是如此，都要达到物我同一的境界，在物我同一的境界中，移情作用最容易发生，因为我们根本就不分辨所生的情感到底是属于我还是属于物的。 （2024-02-28 04:00:27）</p>
<p>从心理学看，这本来不是奇事。凡是观念都有实现于运动的倾向。念到跳舞时脚往往不自主地跳动，念到“山”字时口舌往往不由自主地说出“山”字。通常观念往往不能实现于动作者，由于同时有反对的观念阻止它。同时念到打球又念到泅水，则既不能打球，又不能泅水。如果心中只有一个观念，没有旁的观念和它对敌，则它常自动地现于运动。聚精会神看赛跑时，自己也往往不知不觉地弯起胳膊动起脚来，便是一个好例。在美感经验之中，注意力都是集中在一个意象上面，所以极容易起模仿的运动。 （2024-02-28 04:04:55）</p>
<p>艺术和宗教都是把宇宙加以生气化和人情化，把人和物的距离以及人和神的距离都缩小。它们都带有若干神秘主义的色彩。所谓神秘主义其实并没有什么神秘，不过是在寻常事物之中见出不寻常的意义。这仍然是移情作用。从一草一木之中见出生气和人情以至于极玄奥的泛神主义，深浅程度虽有不同，道理却是一样的。 （2024-02-28 04:07:18）</p>
</section><section id="记得绿罗裙处处怜芳草-美感与联想" class="level1" data-number="4"><h1 data-number="4">
<span class="header-section-number">4</span> “记得绿罗裙，处处怜芳草”—— 美感与联想</h1>
<p>就广义说，联想是知觉和想象的基础，艺术不能离开知觉和想象，就不能离开联想。但是我们通常所谓联想，是指由甲而乙，由乙而丙，辗转不止的乱想。就这个普通的意义说，联想是妨碍美感的。美感起于直觉，不带思考，联想却不免带有思考。在美感经验中我们聚精会神于一个孤立绝缘的意象上面，联想则最易使精神涣散，注意力不专一，使心思由美感的意象旁迁到许多无关美感的事物上面去。在审美时我看到芳草就一心一意地领略芳草的情趣；在联想时我看到芳草就想到罗裙，又想到穿罗裙的美人，既想到穿罗裙的美人，心思就已不复在芳草了。 （2024-03-05 07:25:23）</p>
</section><section id="灵魂在杰作中的冒险-考证批评与欣赏" class="level1" data-number="5"><h1 data-number="5">
<span class="header-section-number">5</span> “灵魂在杰作中的冒险”—— 考证、批评与欣赏</h1>
<p>了解和欣赏是互相补充的。未了解决不足以言欣赏，所以考据学是基本的功夫。但是只了解而不能欣赏，则只是做到史学的功夫，却没有走进文艺的领域。 （2024-03-05 07:30:50）</p>
<p>一般讨论读书方法的书籍往往劝读者持“批评的态度”。这所谓“批评”究竟取哪一个意义呢？它大半是指“判断是非”。所谓持“批评态度”去读书，就是说不要“尽信书”，要自己去分判书中何者为真、何者为伪、何者为美、何者为丑。这其实就是“法官”式的批评。这种“批评的态度”和“欣赏的态度”（就是美感的态度）是相反的。批评的态度是冷静的，不杂情感的，其实就是我们在开头时所说的“科学的态度”；欣赏的态度则注重我的情感和物的姿态的交流。批评的态度须用反省的理解，欣赏的态度则全凭直觉。批评的态度预存有一种美丑的标准，把我放在作品之外去评判它的美丑；欣赏的态度则忌杂有任何成见，把我放在作品里面去分享它的生命。遇到文艺作品如果始终持批评的态度，则我是我而作品是作品，我不能沉醉在作品里面，永远得不到真正的美感的经验。 （2024-03-05 07:34:59）</p>
<p>总而言之，考据不是欣赏，批评也不是欣赏，但是欣赏却不可无考据与批评。从前老先生们太看重考据和批评的功夫，现在一般青年又太不肯做脚踏实地的功夫，以为有文艺的嗜好就可以谈文艺，这都是很大的错误。 （2024-03-05 07:38:05）</p>
</section><section id="情人眼底出西施-美与自然" class="level1" data-number="6"><h1 data-number="6">
<span class="header-section-number">6</span> “情人眼底出西施”—— 美与自然</h1>
<p>美感是什么呢？从积极方面说，我们已经明白美感起于形象的直觉，而这种形象是孤立自足的，和实际人生有一种距离；我们已经见出美感经验中我和物的关系，知道我的情趣和物的姿态交感共鸣，才见出美的形象。从消极方面说，我们已经明白美感一不带意志欲念，有异于实用态度，二不带抽象思考，有异于科学态度；我们已经知道一般人把寻常快感、联想以及考据与批评认为美感的经验是一种大误解。 美生于美感经验，我们既然明白美感经验的性质，就可以进一步讨论美的本身了。 （2024-03-06 06:54:01）</p>
<p>美虽不完全在物却亦非与物无关，你看到峨眉山才觉得庄严、厚重，看到一个小土墩却不能觉得庄严、厚重。从此可知物须先有使人觉得美的可能性，人不能完全凭心灵创造出美来。 （2024-03-06 06:59:34）</p>
<p>心灵把混乱的事物综合成整体的倾向却有一个限制，事物也要本来就有可综合为整体的可能性。 （2024-03-13 06:36:40）</p>
<p>美的欣赏也是如此，也是把自然加以艺术化。所谓艺术化，就是人情化和理想化。 （2024-03-13 06:39:53）</p>
<p>老子所说的“为而不有，功成而不居”，可以说是美感态度的定义。古董商和书画金石收藏家大半都抱有“奇货可居”的态度，很少有能真正欣赏艺术的。我在上文说过，美的欣赏极似“柏拉图式的恋爱”，所谓“柏拉图式的恋爱”对于所爱者也只是无所为而为的欣赏，不带占有欲。这种恋爱是否可能，颇有人置疑，但是历史上有多少著例，凡是到极浓度的初恋者也往往可以达到胸无纤尘的境界。 （2024-03-13 06:41:27）</p>
</section><section id="大人者不失其赤子之心-艺术与游戏" class="level1" data-number="7"><h1 data-number="7">
<span class="header-section-number">7</span> “大人者不失其赤子之心”—— 艺术与游戏</h1>
<p>读诗就是再作诗，一首诗的生命不是作者一个人所能维持住的，也要读者帮忙才行。读者的想象和情感是生生不息的，一首诗的生命也就是生生不息的，它并非一成不变的。一切艺术作品都是如此，没有创造就不能有欣赏。 （2024-03-13 23:17:07）</p>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Art</category>
  <guid>https://learn.shitao5.org/posts/20240226-tanmei/</guid>
  <pubDate>Sun, 25 Feb 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240226-tanmei/cover.png" medium="image" type="image/png" height="89" width="144"/>
</item>
<item>
  <title>Introduction to Bash Scripting</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240223-intro-bash/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Completed.🎉</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://ebook.bobby.sh/" class="uri">https://ebook.bobby.sh/</a></li>
</ul>
</div>
</div>
<section id="about-the-book" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> About the book</h1>
<ul>
<li>
<p>I am always doing that which I cannot do in order that I may learn how to do it, and I believe in sharing knowledge.</p>
<div>
<blockquote class="blockquote">
<p>我总是在做那些我不能做的事情，以便学会如何做，而且我坚信分享知识的重要性。</p>
</blockquote>
</div>
</li>
<li>
<p>I think it’s essential always to keep professional and surround yourself with good people, work hard, and be nice to everyone. You have to perform at a consistently higher level than others. That’s the mark of a true professional.</p>
<div>
<blockquote class="blockquote">
<p>我认为始终保持专业，与优秀的人为伍，努力工作并对每个人都友善是至关重要的。你必须在一个始终比其他人更高水平表现的位置。这是真正专业人士的标志。</p>
</blockquote>
</div>
</li>
</ul></section><section id="bash-variables" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> Bash Variables</h1>
<ul>
<li><p>As in any other programming language, you can use variables in Bash Scripting as well. However, there are no data types, and a variable in Bash can contain numbers as well as characters.</p></li>
<li><p>You can not have spaces before and after the <code>=</code> sign.</p></li>
<li>
<p>Wrapping the variable name between curly brackets is not required, but is considered a good practice, and I would advise you to use them whenever you can:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">${name}</span></span></code></pre></div>
</div>
</li>
<li><p>You can also add variables in the Command Line outside the Bash script and they can be read as parameters.</p></li>
<li><p><code>$0</code> is used to reference the script itself.</p></li>
</ul></section><section id="bash-arrays" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> Bash Arrays</h1>
<ul>
<li>
<p>You can initialize an array by assigning values devided by space and enclosed in <code>()</code>. Example:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">my_array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value 1"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value 2"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value 3"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value 4"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
</li>
<li>
<p>Prepending the array with a hash sign (<code>#</code>) would output the total number of elements in the array, in our case it is <code>4</code>:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">${</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">my_array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[@]</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
</div>
</li>
<li><p>Bash 数组索引从 0 开始，左闭右开，和 Python 类似。</p></li>
</ul></section><section id="bash-conditional-expressions" class="level1" data-number="4"><h1 data-number="4">
<span class="header-section-number">4</span> Bash Conditional Expressions</h1>
<ul>
<li><p>
In Bash, conditional expressions are used by the <code>[[</code> compound command and the <code>[</code> built-in commands to test file attributes and perform string and arithmetic comparisons.
</p></li>
</ul></section><section id="bash-conditionals" class="level1" data-number="5"><h1 data-number="5">
<span class="header-section-number">5</span> Bash Conditionals</h1>
<ul>
<li>
<p>The format of an <code>if-else</code> statement in Bash is as follows:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">[[</span> some_test <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">]]</span></span>
<span id="cb4-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">then</span></span>
<span id="cb4-3">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>commands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb4-4"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span></span>
<span id="cb4-5">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>another <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">commands</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb4-6"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">fi</span></span></code></pre></div>
</div>
</li>
<li>
<p>The Bash <code>case</code> statement syntax looks like this:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">case</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$some_variable</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span></span>
<span id="cb5-2"></span>
<span id="cb5-3">  <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">pattern_1</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb5-4">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>commands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb5-5">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">;;</span></span>
<span id="cb5-6"></span>
<span id="cb5-7">  <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">pattern_2</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">|</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">pattern_3</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb5-8">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>commands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb5-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">;;</span></span>
<span id="cb5-10"></span>
<span id="cb5-11">  <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">*</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb5-12">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>default <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">commands</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb5-13">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">;;</span></span>
<span id="cb5-14"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">esac</span></span></code></pre></div>
</div>
</li>
</ul></section><section id="bash-loops" class="level1" data-number="6"><h1 data-number="6">
<span class="header-section-number">6</span> Bash Loops</h1>
<ul>
<li>
<p>The structure of a for loop:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> var <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">${list}</span></span>
<span id="cb6-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">do</span></span>
<span id="cb6-3">  <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">your_commands</span></span>
<span id="cb6-4"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">done</span></span></code></pre></div>
</div>
</li>
<li>
<p>The structure of a while loop:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb7-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">while</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">[</span> your_condition <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">]</span></span>
<span id="cb7-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">do</span></span>
<span id="cb7-3">  <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">your_commands</span></span>
<span id="cb7-4"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">done</span></span></code></pre></div>
</div>
</li>
<li>
<p>The structure of a until loop:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb8-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">until</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">[[</span> your_condition <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">]]</span></span>
<span id="cb8-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">do</span></span>
<span id="cb8-3">  <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">your_commands</span></span>
<span id="cb8-4"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">done</span></span></code></pre></div>
</div>
</li>
<li>
<p><code>continue</code> tells your bash script to stop the current iteration of the loop and start the next iteration. The syntax of the continue statement:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb9-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">continue</span> <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">[n]</span></span></code></pre></div>
</div>
</li>
<li>
<p><code><a href="https://rdrr.io/r/base/Control.html">break</a></code> tells your bash script to end the loop straight away. The syntax of the break statement:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb10-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">break</span> <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">[n]</span></span></code></pre></div>
</div>
</li>
<li><p>We can also use break command with multiple loops. If we want to exit out of current working loop whether inner outer loop, we simply use <code><a href="https://rdrr.io/r/base/Control.html">break</a></code> but if we are in inner loop and want to exit out of outer loop, we use <code>break 2</code>.</p></li>
</ul></section><section id="bash-functions" class="level1" data-number="7"><h1 data-number="7">
<span class="header-section-number">7</span> Bash Functions</h1>
<ul>
<li>
<p>The structure of a function in bash is quite similar to most languages:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb11-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"> function_name()</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb11-2">  <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">your_commands</span></span>
<span id="cb11-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
</div>
<p>You can also omit the <code>function</code> keyword at the beginning, which would also work:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">function_name()</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb12-2">  <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">your_commands</span></span>
<span id="cb12-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
</div>
</li>
<li><p>One thing to keep in mind is that you should not add the parenthesis when you call the function.</p></li>
</ul></section><section id="debugging-testing-and-shortcuts" class="level1" data-number="8"><h1 data-number="8">
<span class="header-section-number">8</span> Debugging, testing and shortcuts</h1>
<ul>
<li>
<p>
In order to debug your bash scripts, you can use <code>-x</code> when executing your scripts:
</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bash</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-x</span> ./your_script.sh</span></code></pre></div>
</div>
</li>
</ul></section><section id="creating-custom-bash-commands" class="level1" data-number="9"><h1 data-number="9">
<span class="header-section-number">9</span> Creating custom bash commands</h1>
<ul>
<li><p>In order to make the change persistent, we need to add the <code>alias</code> command in our shell profile file. <code>nano ~./bashrc</code> open the file and add the <code>alias</code> command, save and then exit.</p></li>
<li><p>Use <code>alias</code> to list all of the available aliases for your current shell.</p></li>
<li><p>Of course, you could actually write a bash script and add the script inside your <code>usr/bin</code> folder, but this would not work if you don’t have root or sudo access, whereas with aliases you can do it without the need of root access.</p></li>
</ul></section><section id="write-your-first-bash-script" class="level1" data-number="10"><h1 data-number="10">
<span class="header-section-number">10</span> Write your first Bash script</h1>
<ul>
<li><p>
By using <code>$()</code> we tell bash to actually interpret the command and then assign the value to our variable.
</p></li>
</ul></section><section id="pipes-and-redirections" class="level1" data-number="11"><h1 data-number="11">
<span class="header-section-number">11</span> Pipes and Redirections</h1>
<ul>
<li><p>Both <em>pipes</em> and <em>redirections</em> redirect streams (file descriptor) of process being executed. The main difference is that <em>redirections</em> deal with files stream, sending the output stream to a file or sending the content of a given file to the input stream of the process.<br>
On the otherhand a pipe connects two commands by sending the output stream of the first one to the input stream of the second one, without any redirections specified.</p></li>
<li><p>Everytime you redirect the STDOUT of any command multiple times to the same file, it will remove the existing contents of the file to write the new ones. This behaviour can be avoided using the <code>&gt;&gt;</code> operator.</p></li>
</ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Bash</category>
  <guid>https://learn.shitao5.org/posts/20240223-intro-bash/</guid>
  <pubDate>Thu, 22 Feb 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240223-intro-bash/cover.png" medium="image" type="image/png" height="96" width="144"/>
</item>
<item>
  <title>The {targets} R package user manual</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240221-targets/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: 26.32%.</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><p><a href="https://docs.ropensci.org/targets/index.html" class="uri">https://docs.ropensci.org/targets/index.html</a></p></li>
<li><p><a href="https://docs.ropensci.org/targets/articles/overview.html" class="uri">https://docs.ropensci.org/targets/articles/overview.html</a></p></li>
<li><p><a href="https://books.ropensci.org/targets/" class="uri">https://books.ropensci.org/targets/</a></p></li>
<li><p>翻译来自 ChatGPT 3.5</p></li>
</ul>
</div>
</div>
<section id="introduction" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> Introduction</h1>
<ul>
<li>
<p>Pipeline tools coordinate the pieces of computationally demanding analysis projects. The <a href="https://docs.ropensci.org/targets/"><code>targets</code></a> package is a <a href="https://www.gnu.org/software/make/">Make</a>-like pipeline tool for statistics and data science in R. The package skips costly runtime for tasks that are already up to date, orchestrates the necessary computation with implicit parallel computing, and abstracts files as R objects. If all the current output matches the current upstream code and data, then the whole pipeline is up to date, and the results are more trustworthy than otherwise.</p>
<blockquote class="blockquote">
<p>流水线工具协调计算密集型分析项目的各个部分。“targets”包是一个类似于 Make 的用于 R 中统计和数据科学的流水线工具。该包跳过那些已经是最新的任务的昂贵运行时，通过隐式并行计算协调必要的计算，并将文件抽象为 R 对象。如果所有当前输出与当前上游代码和数据匹配，那么整个流水线是最新的，结果比其他情况更可信。</p>
</blockquote>
</li>
<li>
<p><a href="https://docs.ropensci.org/targets/"><code>targets</code></a> implicitly nudges users toward a clean, function-oriented programming style that fits the intent of the R language and helps practitioners maintain their data analysis projects.</p>
<blockquote class="blockquote">
<p>“targets”隐式地引导用户朝着一种清晰的、面向函数的编程风格前进，符合 R 语言的意图，有助于从业者维护其数据分析项目。</p>
</blockquote>
</li>
</ul></section><section id="debugging-pipelines" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> Debugging pipelines</h1>
<ul>
<li>
<p>In <code>targets</code>, several layers of encapsulation and automation separate you from the code you want to debug:</p>
<ul>
<li><p>The pipeline runs in an external non-interactive <a href="https://github.com/r-lib/callr"><code>callr::r()</code></a> process where you cannot use the R console.</p></li>
<li><p>Data management</p></li>
<li><p>Environment management</p></li>
<li><p><a href="https://books.ropensci.org/targets/hpc.html">High-performance computing</a></p></li>
<li><p>Built-in error handling</p></li>
</ul>
<p>Although these layers are essential for reproducibility and scale, you will need to cut through them in order to diagnose and solve issues in pipelines.</p>
<div>
<blockquote class="blockquote">
<p>在 targets 中，几个封装和自动化的层将您与要调试的代码分开：</p>
<ul>
<li><p>管道在外部非交互式 <code><a href="https://callr.r-lib.org/reference/r.html">callr::r()</a></code> 进程中运行，您无法使用 R 控制台。</p></li>
<li><p>数据管理</p></li>
<li><p>环境管理</p></li>
<li><p>高性能计算</p></li>
<li><p>内置错误处理</p></li>
</ul>
<p>虽然这些层对于可重现性和扩展性至关重要，但您需要穿过它们才能诊断和解决管道中的问题。本章将解释如何做到这一点。</p>
</blockquote>
</div>
</li>
<li><p>Even if you hit an error, you can still finish the successful parts of the pipeline. The&nbsp;<code>error</code>&nbsp;argument of&nbsp;<code>tar_option_set()</code>&nbsp;and&nbsp;<code>tar_target()</code>&nbsp;tells each target what to do if it hits an error. For example,&nbsp;<code>tar_option_set(error = "null")</code>&nbsp;tells errored targets to return&nbsp;<code>NULL</code>. The output as a whole will not be correct or up to date, but the pipeline will finish so you can look at preliminary results. This is especially helpful with&nbsp;<a href="https://books.ropensci.org/targets/dynamic.html">dynamic branching</a>.</p></li>
</ul></section><section id="functions" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> Functions</h1>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>R</category>
  <guid>https://learn.shitao5.org/posts/20240221-targets/</guid>
  <pubDate>Tue, 20 Feb 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240221-targets/logo.svg" medium="image" type="image/svg+xml"/>
</item>
<item>
  <title>Building reproducible analytical pipelines with R</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240203-raps-with-r/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Completed.😸</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://raps-with-r.dev/" class="uri">https://raps-with-r.dev/</a></li>
</ul>
</div>
</div>
<section id="preface" class="level1 unnumbered"><h1 class="unnumbered">Preface</h1>
<ul>
<li><p>
There are many self-help books out there that state that it’s better to know a lot about only a few, maybe even only one, topic, than know a lot about many topics. I tend to disagree with this; at least in my experience, knowing enough about many different topics always allowed me to communicate effectively with many different people, from researchers focusing on very specific topics that needed my help to assist them in their research, to clients from a wide range of industries that were sharing their problems with me in my consulting years. If I needed to deepen my knowledge on a particular topic before I could intervene, I had the necessary theoretical background to grab a few books and learn the material. Also, I was never afraid of asking questions.
</p></li>
</ul></section><section id="introduction" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> Introduction</h1>
<ul>
<li>
<p>Your projects are going to be reproducible simply because they were engineered, from the start, to be reproducible. There are two main ideas in this book that you need to keep in mind at all times:</p>
<ul>
<li><p>DRY: Don’t Repeat Yourself;</p></li>
<li><p>WIT: Write IT down.</p></li>
</ul>
<p>DRY WIT is not only the best type of humour, it is also the best way to write reproducible analytical pipelines.</p>
</li>
<li><p>Interacting graphically with a program is simply not reproducible. So our aim is to write code that can be executed non-interactively by a machine. This is because one necessary condition for a workflow to be reproducible and get referred to as a RAP (<strong>R</strong>eproducible <strong>A</strong>nalytical <strong>P</strong>ipeline), is for the workflow to be able to be executed by a machine, automatically, without any human intervention.</p></li>
<li><p>A reproducible project means that this project can be rerun by anyone at 0 (or very minimal) cost.</p></li>
<li>
<p>Basically, for something to be truly reproducible, it has to respect the following bullet points:</p>
<ul>
<li><p>Source code must obviously be available and thoroughly tested and documented (which is why we will be using Git and Github);</p></li>
<li><p>All the dependencies must be easy to find and install (we are going to deal with this using dependency management tools);</p></li>
<li><p>To be written with an open source programming language (nocode tools like Excel are by default non-reproducible because they can’t be used non-interactively, and which is why we are going to use the R programming language);</p></li>
<li><p>The project needs to be run on an open source operating system (thankfully, we can deal with this without having to install and learn to use a new operating system, thanks to Docker);</p></li>
<li><p>Data and the paper/report need obviously to be accessible as well, if not publicly as is the case for research, then within your company. This means that the concept of “scripts and/or data available upon request” belongs in the trash.</p></li>
</ul>
</li>
<li><p>The take-away message is that counting on the language itself being stable through time as a sufficient condition for reproducibility is not enough. We have to set up the code in a way that it actually is reproducible.</p></li>
</ul></section><section id="part-1-dont-repeat-yourself" class="level1 unnumbered"><h1 class="unnumbered">Part 1: Don’t Repeat Yourself</h1>
</section><section id="before-we-start" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> Before we start</h1>
<ul>
<li><p>You need to know what an actual text file is. A document written in Word (with the <code>.docx</code> extension) is not a text file. It looks like text, but is not. The <code>.docx</code> format is a much more complex format with many layers of abstraction. “True” plain text files can be opened with the simplest text editor included in your operating system.</p></li>
<li><p>The tools are always right. If you’re using a tool and it’s not behaving as expected, it is much more likely that your expectations are wrong. Take this opportunity to review your knowledge of the tool.</p></li>
</ul></section><section id="project-start" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> Project start</h1>
<ul>
<li><p>Getting data from Excel into a tidy data frame can be very tricky. This is because very often, Excel is used as some kind of dashboard or presentation tool. So data is made human-readable, in contrast to machine-readable.</p></li>
<li><p>An issue with scraping tables off the web is that they might change in the future. It is therefore a good idea to save the page by right clicking on it and then selecting save as, and then re-hosting it.</p></li>
<li>
<p>Let’s ask ourselves the following important questions:</p>
<ul>
<li><p>How easy would it be for someone else to rerun the analysis?</p></li>
<li><p>How easy would it be to update the analysis once new data gets published?</p></li>
<li><p>How easy would it be to reuse this code for other projects?</p></li>
<li><p>What guarantee do we have that if the scripts get run in 5 years, with the same input data, we get the same output?</p></li>
</ul>
</li>
<li><p>Sometimes you might not be interested in reusing code for another project: however, even if that’s the case, structuring your code into functions and packaging them makes it easy to reuse code even inside the same project.</p></li>
</ul></section><section id="version-control-with-git" class="level1" data-number="4"><h1 data-number="4">
<span class="header-section-number">4</span> Version control with Git</h1>
<ul>
<li><p>Modern software development would be impossible without version control systems, and the same goes for building analytical pipelines that are reproducible and robust.</p></li>
<li><p>What really sets up Github.com apart is Github Actions, Github’s continuous integration service. Github Actions is literally a computer in the cloud that you can use to run a set of actions each time you interact with the repository (or at defined moments as well).</p></li>
<li><p>By the way, if you’re using a cloud service like Dropbox, Onedrive, and the like, DO NOT put projects tracked by Git in them! I really need to stress this: do not track projects with both something like Dropbox and Git.</p></li>
<li><p>Unlike Dropbox (or similar services), Git deals with conflicts not on a per-file basis, but on a per-line basis. So if two collaborators change the same file, but different lines of this same file, there will be no conflict: Git will handle the merge on its own.</p></li>
<li><p><em>Committing</em> means that we are happy with our work, and we can snapshot it. These snapshots then get uploaded to Github by pushing them. This way, the changes will be available for our coworkers for them to pull.</p></li>
<li><p>Try to keep commit messages as short and as explicit as possible. This is not always easy, but it really pays off to strive for short, clear messages. Also, ideally, you would want to keep commits as small as possible, ideally one commit per change. For example, if you’re adding and amending comments in scripts, once you’re done with that make this a commit. Then, maybe clean up some code. That’s another, separate commit. This makes rolling back changes or reviewing them much easier. This will be crucial later on when we will use trunk-based development to collaborate with our teammates on a project. It is generally not a good idea to code all day and then only push one single big fat commit at the end of the day, but that is what happens very often…</p></li>
<li><p>If you encountered a bug and want to open an issue, it is very important that you provide a minimal, reproducible example (MRE). MREs are snippets of code that can be run very easily by someone other than yourself and which produce the bug reliably. Interestingly, if you understand what makes an MRE minimal and reproducible, you understand what will make our pipelines reproducible as well.</p></li>
<li><p>The bar you need to set for an MRE is as follows: bar needed package dependencies that may need to be installed beforehand, people that try to help you should be able to run your script by simply copy-and-pasting it into an R console. Any other manipulation that you require from them is unacceptable: remember that in open source development, developers very often work during their free time, and don’t owe you tech support! And even if they did, it is always a good idea to make it as easy as possible for them to help you, because it simply increases the likelihood that they will actually help.</p></li>
</ul></section><section id="collaborating-using-trunk-based-development" class="level1" data-number="5"><h1 data-number="5">
<span class="header-section-number">5</span> Collaborating using Trunk-based development</h1>
<ul>
<li>
<p>The idea of trunk-based development is simple; team members should work on separate branches to add features or fix bugs, and then merge their branch to the “trunk” (in our case the <em>master</em> branch) to add their changes back to the main codebase. And this process should happen quickly, ideally every day, or as soon as some code is ready. When a lot of work accumulates in a branch for several days or weeks, merging it back to the master branch can be very painful. So by working in short-lived branches, if conflicts arise, they can be dealt with quickly. This also makes code review much easier, because the reviewer only needs to review little bits of code at a time. If instead long-lived branches with a lot of code changes get merged, reviewing all the changes and solving the conflicts that could arise would be a lot of work. To avoid this, it is best to merge every day or each time a piece of code is added, and, <strong>very importantly</strong>, this code does not break the whole project (we will be using unit tests for this later).</p>
<p>So in summary: to avoid a lot of pain by merging branches that moved away too much from the trunk, we will create branches, add our code, and merge them to the trunk as soon as possible. <em>As soon as possible</em> can mean several things, but usually this means <em>as soon as a feature was added</em>, <em>a bug was fixed</em>, or <em>as soon as we added some code that does not break the whole project, even if the feature we wanted to add is not done yet</em>. The philosophy is that if merging fails, it should fail as early as possible. Early failures are easy to deal with.</p>
</li>
<li><p>Well, let’s be clear; even with Git, it can sometimes be very tricky to resolve conflicts. But you should know that when solving a conflict with Git is difficult, this usually means that it would be impossible to do any other way, and would inevitably result in someone having to reconcile the files by hand. What makes handling conflicts easier with Git though, is that Git is able to tell you where you can find clashes on a per-line basis. So for instance, if you change the first ten lines of a script, and I change the next ten lines, there would be no conflict, and Git will automatically merge both our contributions into a single file.</p></li>
<li><p>If adding a feature would take more time than just one day, then the task needs to be split in a manner that small contributions can be merged daily. In the beginning, these contributions can be simple placeholders that will be gradually enriched with functioning code until the feature is successfully implemented. This strategy is called branching by abstraction.</p></li>
</ul></section><section id="functional-programming" class="level1" data-number="6"><h1 data-number="6">
<span class="header-section-number">6</span> Functional programming</h1>
<ul>
<li><p>Functional programming is a paradigm that relies exclusively on the evaluation of functions to achieve the desired result.</p></li>
<li><p>A referentially transparent function is a function that does not use any variable that is not also one of its inputs.</p></li>
<li><p>A pure function is a function that does not interact in any way with the global environment. It does not write anything to the global environment, nor requires anything from the global environment.</p></li>
<li><p>Turns out that pure functions are thus necessarily referentially transparent.</p></li>
<li><p>In a functional programming language, functions are first-class objects. Contrary to what the name implies, this means that functions, especially the ones you define yourself, are nothing special. A function is an object like any other, and can thus be manipulated as such. Think of anything that you can do with any object in R, and you can do the same thing with a function.</p></li>
<li><p>Functions that return functions are called <em>function factories</em> and they’re incredibly useful.</p></li>
<li><p>There is an issue with recursive functions (in the R programming language, other programming languages may not have the same problem, like Haskell): while it is sometimes easier to write a function using a recursive algorithm than an iterative algorithm, like for the factorial function, recursive functions in R are quite slow.</p></li>
<li><p>We can take inspiration from the Unix philosophy and rewrite it for our purposes: <em>Write functions that do one thing and do it well. Write functions that work together. Write functions that handle lists, because that is a universal interface.</em></p></li>
<li><p>This idea of splitting the problem into smaller chunks, each chunk in turn split into even smaller units that can be handled by functions and then the results of these function combined into a final output is called composition.</p></li>
<li><p>Loops are incredibly useful, and you are likely familiar with them. The problem with loops is that they are a concept from iterative programming, not functional programming, and this is a problem because loops rely on changing the state of your program to run.</p></li>
<li><p>All of this to say that if you want to extend R by writing packages, learning some OOP essentials is also important. But for data analysis, functional programming does the job perfectly well.</p></li>
<li><p>While this chapter stresses the advantages of functional programming, you should not forget that R is not a pure, and solely, functional programming language and that other paradigms, like object-oriented programming, are also available to you. So if your goal is to master the language (instead of “just” using it to solve data analysis problems), then you also need to know about R’s OOP capabilities.</p></li>
</ul></section><section id="literate-programming" class="level1" data-number="7"><h1 data-number="7">
<span class="header-section-number">7</span> Literate programming</h1>
<ul>
<li><p>In literate programming, authors mix code and prose, which makes the output of their programs not just a series of tables, or graphs or predictions, but a complete report that contains the results of the analysis directly embedded into it. Scripts written using literate programming are also very easy to compile, or render, into a variety of document formats like <code>html</code>, <code>docx</code>, <code>pdf</code> or even <code>pptx</code>.</p></li>
<li><p>Quarto is not tied to R. Quarto is actually a standalone tool that needs to be installed alongside your R installation, and works completely independently. In fact, you can use Quarto without having R installed at all, as Quarto, just like <a href="https://yihui.org/knitr/">knitr</a> supports many engines. This means that if you’re primarily using Python, you can use Quarto to author documents that mix Python chunks and prose.</p></li>
<li><p>Copy and pasting is forbidden. Striving for 0 copy and pasting will make our code much more robust and likely to be correct.</p></li>
<li><p>Child documents are exactly what you think they are: they’re smaller documents that get knitted and then embedded into the parent document. You can define anything within these child documents, and as such you can even use them to print more complex objects, like a ggplot object.</p></li>
<li>
<p>It is important not to succumb to the temptation of copy and pasting sections of your report, or parts of your script, instead of using these more advanced features provided by the language. It is tempting, especially under time pressure, to just copy and paste bits of code and get things done instead of writing what seems to be unnecessary code to finally achieve the same thing. The problem, however, is that in practice copy and pasting code to simply get things done will come bite you sooner rather than later. Especially when you’re still in the exploration/drafting phase of the project. It may take more time to set up, but once you’re done, it is much easier to experiment with different parameters, test the code or even re-use the code for other projects. Not only that but forcing you to actually think about how to set up your code in a way that avoids repeating yourself also helps with truly understanding the problem at hand. What part of the problem is constant and does not change? What does change? How often, and why? Can you also fix these parts or not? What if instead of five sections that I need to copy and paste, I had 50 sections? How would I handle this?</p>
<p>Asking yourself these questions, and solving them, will ultimately make you a better programmer.</p>
<div>
<blockquote class="blockquote">
<p>重要的是，不要屈服于复制和粘贴报告部分或脚本部分的诱惑，而是使用语言提供的这些更高级的功能。尤其是在时间紧迫的情况下，很容易只是复制和粘贴代码的片段，完成任务，而不是编写最终实现相同效果的看似不必要的代码。然而，实际上，复制和粘贴代码只是解决问题的权宜之计，迟早会给你带来麻烦，尤其是在项目的勘探/起草阶段。设置可能需要更多的时间，但一旦完成，就可以更轻松地尝试不同的参数，测试代码，甚至将代码用于其他项目。不仅如此，迫使你真正思考如何以避免重复的方式设置代码，还有助于更好地理解手头的问题。问题的哪一部分是恒定的且不变的？什么会改变？多久改变一次，为什么？你能否修复这些部分？如果我需要复制和粘贴的不是五个部分，而是五十个部分呢？我该如何处理？</p>
<p>问自己这些问题，并解决它们，最终将使你成为更好的程序员。</p>
</blockquote>
</div>
</li>
</ul></section><section id="part-2-write-it-down" class="level1 unnumbered"><h1 class="unnumbered">Part 2: Write IT down</h1>
<ul>
<li><p>We cannot leave code quality, documentation and finally its reproducibility to chance. We need to write down everything we need to ensure the long-term reproducibility of our pipelines.</p></li>
<li><p>Indeed, any human interaction with the analysis is a source of errors. That’s why we need to thoroughly and systematically test our code. These tests also need to run non-interactively.</p></li>
<li><p>Once we have a package, we can use <a href="https://testthat.r-lib.org">testthat</a> for unit testing, and base R functions for assertive programming. At this stage, our code should be well-documented, easy to share, and thoroughly tested.</p></li>
</ul></section><section id="rewriting-our-project" class="level1" data-number="8"><h1 data-number="8">
<span class="header-section-number">8</span> Rewriting our project</h1>
<ul>
<li><p>A script is simply a means, it’s not an end. The end is (in most cases) a document so we might as well use literate programming to avoid the cursed loop of changing the script, editing the document, going back to the script, etc.</p></li>
<li><p>So by using <code>quo()</code>, we can delay evaluation. So how can we tell the function that it’s time to evaluate <code>locality</code>? This is where we need <code>!!</code> (pronounced <em>bang-bang</em>).</p></li>
</ul></section><section id="basic-reproducibility-freezing-packages" class="level1" data-number="9"><h1 data-number="9">
<span class="header-section-number">9</span> Basic reproducibility: freezing packages</h1>
<ul>
<li><p>Packages offer us a great framework for documenting, testing and sharing our code (even if only sharing internally in your company/team, or even just future you).</p></li>
<li><p>This works because <a href="https://rstudio.github.io/renv/">renv</a> does more than simply create a list of the used packages and recording their versions inside the <code>renv.lock</code> file: it actually creates a per-project library that is completely isolated from the main, default, R library on your machine, but also from the other <a href="https://rstudio.github.io/renv/">renv</a> libraries that you might have set up for your other projects (remember, the <em>library</em> is the set of R packages installed on your computer). To save time when setting up an <a href="https://rstudio.github.io/renv/">renv</a> library, packages simply get copied over from your main library instead of being re-downloaded and re-installed (if the required packages are already installed in your default library).</p></li>
<li><p>It is important to remember that when you’ll use <a href="https://rstudio.github.io/renv/">renv</a> to restore a project’s library on a new machine, the R version will not be restored: so in the future, you might be restoring this project and running old versions of packages on a newer version of R, which may sometimes be a problem.</p></li>
<li>
<p>So should you use <a href="https://rstudio.github.io/renv/">renv</a>? I see two scenarios where it makes sense:</p>
<ul>
<li><p>You’re done with the project and simply want to keep a record of the packages used. Simply call <code><a href="https://rstudio.github.io/renv/reference/init.html">renv::init()</a></code> at the end of the project and commit and push the <code>renv.lock</code> file on Github.</p></li>
<li><p>You want to use <a href="https://rstudio.github.io/renv/">renv</a> from the start to isolate the project’s library from your whole R installation’s library to avoid any interference (I would advise you to do it like this).</p></li>
</ul>
</li>
</ul></section><section id="packaging-your-code" class="level1" data-number="10"><h1 data-number="10">
<span class="header-section-number">10</span> Packaging your code</h1>
<ul>
<li>
<p>The goal is to convert your analysis into a package because when your analysis goes into <em>package development mode</em>, you can, as the developer, leverage many tools that will help you improve the quality of your analysis. These tools will make it easier for you to:</p>
<ul>
<li><p>document the functions you had to write for your analysis;</p></li>
<li><p>test these functions;</p></li>
<li><p>properly define dependencies;</p></li>
<li><p>use all the code you wrote into a true reproducible pipeline.</p></li>
</ul>
<p>Turning the analysis into a package will also make the separation between the software development work you had to write for your analysis (writing functions to clean data for instance) from the analysis itself much clearer.</p>
</li>
<li>
<p>By turning your analysis into a package you will essentially end up with two <em>things</em>:</p>
<ul>
<li><p>a well-documented, and tested package;</p></li>
<li><p>an analysis that uses this package like any other package.</p></li>
</ul>
</li>
<li><p>The other benefit of turning all this code into a package is that we get a clear separation between the code that we wrote purely to get our analysis going (what I called the <em>software development part</em> before) from the analysis itself (which would then typically consist in computing descriptive statistics, running regression or machine learning models, and visualisation). This then in turn means that we can more easily maintain and update each part separately. So the pure software development part goes into the package, which then gives us the possibility to use many great tools to ensure that our code is properly documented and tested, and then the analysis can go inside a purely reproducible pipeline. Putting the code into a package also makes it easier to reuse across projects.</p></li>
<li>
<p>So, basically, a <a href="https://thinkr-open.github.io/fusen/">fusen</a>-ready <code>.Rmd</code> file is nothing more than an <code>.Rmd</code> file with some structure imposed on it. Instead of documenting your functions as simple comments, document them using <a href="https://roxygen2.r-lib.org/">roxygen2</a> comments, which then get turned into the package’s documentation automatically. Instead of trying your function out on some mock data in your console, write down that example inside the <code>.Rmd</code> file itself. Instead of writing ad-hoc tests, or worse, instead of testing your functions on your console manually, one by one (and we’ve all done this), write down the test inside the <code>.Rmd</code> file itself, right next to the function you’re testing.</p>
<p><strong>Write it down</strong>, <strong>write it down</strong>, <strong>write it down</strong>… you’re already documenting and testing things (most of the time in the console only), so why not just write it down once and for all, so you don’t have to rely on your ageing, mushy brain so much? Don’t make yourself remember things, just write them down! <a href="https://thinkr-open.github.io/fusen/">fusen</a> gives you a perfect framework to do this. The added benefit is that it will improve your package’s quality through the tests and examples that are not directly part of the analysis itself but are still required to make sure that the analysis is of high quality, reproducible and maintainable. So that if you start messing with your functions, you have the tests right there to tell you if you introduced breaking changes.</p>
</li>
<li><p>Note that any open-source work should present a license so that users know how they are allowed to use it. Otherwise, theoretically, without a license, no one is allowed to re-use or share your work.</p></li>
<li><p>the concept of private functions doesn’t really exist in R. You can always access a “private” function by using <code>:::</code> (three times the <code>:</code>), as in <code>package:::private_function()</code>.</p></li>
</ul></section><section id="testing-your-code" class="level1" data-number="11"><h1 data-number="11">
<span class="header-section-number">11</span> Testing your code</h1>
<ul>
<li>
<p>Tests need to be run each time <em>any</em> of the code from a project gets changed. This might seem overkill (why test a function that you didn’t even touch for weeks?), but because there are dependencies between your functions, a change in one function can affect another function. Especially if the output of function A is the input of function B: you changed function A and now the output of function A changed in a way that it breaks function B, or also modifies its output in an unexpected way.</p>
<p>There are several types of tests that we can use:</p>
<ul>
<li><p>unit testing: these are written while developing, and executed while developing;</p></li>
<li><p>assertive testing: these are executed at runtime. These make sure, for example, that the inputs a function receives are sane.</p></li>
</ul>
</li>
<li><p>When using <a href="https://thinkr-open.github.io/fusen/">fusen</a>, a unit test should be a self-contained chunk that can be executed completely independently. This is why in this chunk we re-created the different variables that were needed, <code>communes</code> an <code>flat_data</code>. If you were developing the package without <a href="https://thinkr-open.github.io/fusen/">fusen</a>, you would need to do the same, so don’t think that this is somehow a limitation of <a href="https://thinkr-open.github.io/fusen/">fusen</a>.</p></li>
<li><p>This is another advantage of writing tests: it forces you to think about what you’re doing. The simple act of thinking and writing tests very often improves your code quite a lot, and not just from a pure algorithmic perspective, but also from a user experience perspective.</p></li>
<li>
<p>You need to consider writing tests as an integral part of the project, and need to take the required time it takes to write them into account when planning projects. But keep in mind that writing them makes you gain a lot of time in the long run, so actually, you might even be faster by writing tests! Tests also allow you to immediately see where something went wrong, when something goes wrong. So tests save you time here as well. Without tests, when something goes wrong, you have a hard time finding where the bug comes from, and end up wasting precious time. And worse, sometimes things go wrong and break, but silently. You still get an output that may look ok at first glance, and only realise something is wrong way too late. Testing helps to avoid such situations.</p>
<p>So remember: it might <em>feel</em> like packaging your code and writing tests for it takes time, but you’re actually already doing it, but non-systematically and manually and it ends up saving you time in the long run instead. Testing also helps with developing complex functions.</p>
</li>
</ul></section><section id="build-automation-with-targets" class="level1" data-number="12"><h1 data-number="12">
<span class="header-section-number">12</span> Build automation with targets</h1>
<ul>
<li>
<p>The build automation tool then tracks:</p>
<ul>
<li><p>any change in any of the code. Only the outputs that are affected by the changes you did will be re-computed (and their dependencies as well);</p></li>
<li><p>any change in any of the tracked files. For example, if a file gets updated daily, you can track this file and the build automation tool will only execute the parts of the pipeline affected by this update;</p></li>
<li><p>which parts of the pipeline can safely run in parallel (with the option to thus run the pipeline on multiple CPU cores).</p></li>
</ul>
<p>Just like many of the other tools that we have encountered in this book, what build automation tools do is allow you to not have to rely on your brain. You <em>write down</em> the recipe once, and then you can focus again on just the code of your actual project. You shouldn’t have to think about the pipeline itself, nor think about how to best run it. Let your computer figure that out for you, it’s much better at such tasks than you.</p>
</li>
<li><p>You need to remember our chapter on functional programming. We want our pipeline to be a sequence of pure functions. This means that our pipeline running successfully should not depend on anything in the global environment (apart from loading the packages in the first part of the script, and the options set with <code>tar_option_set()</code> for the others) and it should not change anything outside of its scope. This means that the pipeline should not change anything in the global environment either. This is exactly how a <a href="https://docs.ropensci.org/targets/">targets</a> pipeline operates. A pipeline defined using <a href="https://docs.ropensci.org/targets/">targets</a> will be pure and so the output of the pipeline will not be saved in the global environment.</p></li>
<li><p>After running this pipeline you should see a file called <code>my_plot.png</code> in the folder of your pipeline. If you type <code>tar_load(data_plot)</code>, and then <code>data_plot</code> you will see that this target returns the <code>filename</code> argument of <code>save_plot()</code>. This is because a target needs to return something, and in the case of functions that save a file to disk returning the path where the file gets saved is recommended. This is because if I then need to use this file in another target, I could do <code>tar_target(x, f(data_plot))</code>. Because the <code>data_plot</code> target returns a path, I can write <code>f()</code> in such a way that it knows how to handle this path. If instead I write <code>tar_target(x, f("path/to/my_plot.png"))</code>, then <a href="https://docs.ropensci.org/targets/">targets</a> would have no way of knowing that the target <code>x</code> depends on the target <code>data_plot</code>. The dependency between these two targets would break. Hence why the first option is preferable.</p></li>
<li><p>It is worth noting that the <a href="https://ggplot2.tidyverse.org">ggplot2</a> package includes a function to save <code>ggplot</code> objects to disk called <code><a href="https://ggplot2.tidyverse.org/reference/ggsave.html">ggplot2::ggsave()</a></code>. So you could define two targets, one to compute the <code>ggplot</code> object itself, and another to generate a <code>.png</code> image of that <code>ggplot</code> object.</p></li>
<li><p>It is also possible to compile documents using RMardown (or Quarto) with <a href="https://docs.ropensci.org/targets/">targets</a>. The way this works is by setting up a pipeline that produces the outputs you need in the document, and then defining the document as a target to be computed as well. For example, if you’re showing a table in the document, create a target in the pipeline that builds the underlying data. Do the same for a plot, or a statistical model. Then, in the <code>.Rmd</code> (or <code>.Qmd</code>) source file, use <code><a href="https://docs.ropensci.org/targets/reference/tar_read.html">targets::tar_read()</a></code> to load the different objects you need.</p></li>
<li><p>Don’t worry, we will make it look nice, but right at the end. Don’t waste time making things look good too early on. Ideally, try to get the pipeline to run on a simple example, and then keep adding features. Also, try to get <em>as much feedback</em> as possible on the <em>content</em> as <em>early</em> as possible from your colleagues. No point in wasting time to make something look good if what you’re writing is not at all what was expected.</p></li>
<li><p>Because the computation of all the objects is handled by <a href="https://docs.ropensci.org/targets/">targets</a>, compiling the document itself is very quick. All that needs to happen is loading pre-computed targets. This also means that you benefit from all the other advantages of using <a href="https://docs.ropensci.org/targets/">targets</a>: only the outdated targets get recomputed, and the computation of the targets can happen in parallel. Without <a href="https://docs.ropensci.org/targets/">targets</a>, compiling the RMarkdown document would always recompute all the objects, and all the objects’ recomputation would happen sequentially.</p></li>
</ul></section><section id="reproducible-analytical-pipelines-with-docker" class="level1" data-number="13"><h1 data-number="13">
<span class="header-section-number">13</span> Reproducible analytical pipelines with Docker</h1>
<ul>
<li><p>When you run a Docker image, as in, you’re executing your pipeline using that image definition, this now is referred to as a Docker container.</p></li>
<li>
<p>But why Linux though; why isn’t it possible to create Docker images based on Windows or macOS? Remember in the introduction, where I explained what reproducibility is? I wrote:</p>
<blockquote class="blockquote">
<p>Open source is a hard requirement for reproducibility.</p>
</blockquote>
<p>Open source is not just a requirement for the programming language used for building the pipeline but extends to the operating system that the pipeline runs on as well. So the reason Docker uses Linux is because you can use Linux distributions like Ubuntu for free and without restrictions. There aren’t any licenses that you need to buy or activate, and Linux distributions can be customized for any use case imaginable. Thus Linux distributions are the only option available to Docker for this task.</p>
</li>
<li><p>The Ubuntu operating system has two releases a year, one in April and one in October. On even years, the April release is a long-term support (LTS) release. LTS releases get security updates for 5 years, and Docker images generally use an LTS release as a base.</p></li>
<li><p>A major difference between Ubuntu (and other Linux distributions) and macOS and Windows is how you install software. In short, software for Linux distributions is distributed as packages.</p></li>
<li><p>First we define a variable using <code>ENV</code>, called <code>TZ</code> and we set that to the <code>Europe/Luxembourg</code> time zone (you can change this to your own time zone). We then run a rather complex looking command that sets the defined time zone system-wide. We had to do all this, because when we will later install R, a system-level dependency called <code>tzdata</code> gets installed alongside it. This tool then asks the user to enter his or her time zone interactively. But we cannot interact with the image interactively as it’s being built, so the build process gets stuck at this prompt. By using these two commands, we can set the correct time zone and once <code>tzdata</code> gets installed, that tool doesn’t ask for the time zone anymore, so the build process can continue.</p></li>
<li><p>Remember: <code>RUN</code> commands get executed at build-time, <code>CMD</code> commands at run-time. This distinction will be important later on.</p></li>
<li><p>In summary, the first approach is “dockerize pipelines”, and the second approach is “dockerize the dev environment and use it for many pipelines”. It all depends on how you work: in research, you might want to go for the first approach, as each project likely depends on bleeding-edge versions of R and packages. But in industry, where people tend to put the old adage “if ain’t broke don’t fix it” into practice, dev environments are usually frozen for some time and only get updated when really necessary (or according to a fixed schedule).</p></li>
<li><p>To dockerize the pipeline, we first need to understand something important with Docker, which I’ve already mentioned in passing: a Docker image is an immutable sandbox. This means that we cannot change it at run-time, only at build-time. So if we log in to a running Docker container (as we did before), and install an R package using <code>install.packages("package_name")</code>, that package will disappear if we stop that container. The same is true for any files that get created at run-time: they will also disappear once the container is stopped. So how are we supposed to get the outputs that our pipeline generates from the Docker container? For this, we need to create a volume. A volume is nothing more than a shared folder between the Docker container and the host machine that starts the container. We simply need to specify the path for this shared folder when running the container, and that’s it.</p></li>
<li>
<p>So in summary, here’s how you can share images with the world, your colleagues, or future you:</p>
<ul>
<li><p>Only share the Dockerfiles. Users need to build the images.</p></li>
<li><p>Share images on Docker Hub. It’s up to you if you want to share a base image with the required development environment, and then separate, smaller images for the pipelines, or if you want to share a single image which contains everything.</p></li>
<li><p>Share images but only within your workplace.</p></li>
</ul>
</li>
</ul></section><section id="continuous-integration-and-continuous-deployment" class="level1" data-number="14"><h1 data-number="14">
<span class="header-section-number">14</span> Continuous integration and continuous deployment</h1>
<ul>
<li><p>Using CI/CD is an essential part of the DevOps methodology for software engineering.</p></li>
<li><p>DevOps is a set of practices, tools, and a cultural philosophy that automate and integrate the processes between software development and IT teams. It emphasizes team empowerment, cross-team communication and collaboration, and technology automation.</p></li>
</ul></section><section id="the-end" class="level1" data-number="15"><h1 data-number="15">
<span class="header-section-number">15</span> The end</h1>
<ul>
<li>
<p>So, why bother building RAPs? Firstly, there are purely technical considerations. It is not impossible that in quite a near future, we will work on ever thinner clients while the heavy-duty computations will run on the cloud. Should this be the case, being comfortable with the topics discussed in this book will be valuable. Also, in this very near future, large language models will be able to set up most, if not all, of the required boilerplate code to set up a RAP. This means that you will be able to focus on analysis, but you still need to understand what are the different pieces of a RAP, and how they fit together, in order to understand the code that the large language model prepared for you, but also to revise it if needed. And it is not a stretch to imagine that simple analyses could be taken over by large language models as well. So you might very soon find yourself in a position where you will not be the one doing an analysis and setting up a RAP, but instead check, verify and adjust an analysis and a RAP built by an AI. Being familiar with the concepts laid out in this book will help you successfully perform these tasks in a world where every data scientist will have AI assistants.</p>
<p>But more importantly, the following factors are inherently part of data analysis:</p>
<ul>
<li><p>transparency;</p></li>
<li><p>sustainability;</p></li>
<li><p>scalability.</p></li>
</ul>
</li>
<li><p>In the case of research, the <em>publish or perish</em> model has distorted incentives so much that unfortunately a lot of researchers are focused on getting published as quickly as possible, and see the three factors listed above as hurdles to getting published quickly. Herculean efforts have to be made to reproduce studies that are not reproducible, and more often than not, people that try to reproduce the results are unsuccessful. Thankfully, things are changing and there are more and more efforts being made to make research reproducible by design, and not as an afterthought. In the private sector, tight deadlines lead to the same problem: analysts think that making the project reproducible is an hindrance to being able to deliver on time. But here as well, taking the time to make the project reproducible will help with making sure that what is delivered is of high quality, and it will also help with making reusing existing code for future projects much easier, even further accelerating development.</p></li>
<li>
<p>Data analysis, at whatever level and for whatever field, is not just about getting to a result, the way to get to the result is part of it! This is true for science, this is true for industry, this is true everywhere. You get to decide where on the iceberg of reproducibility you want to settle, but the lower, the better.</p>
<p>So why build RAPs? Well, because there’s no alternative if you want to perform your work seriously.</p>
</li>
</ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>R</category>
  <guid>https://learn.shitao5.org/posts/20240203-raps-with-r/</guid>
  <pubDate>Fri, 02 Feb 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240203-raps-with-r/cover.png" medium="image" type="image/png" height="107" width="144"/>
</item>
<item>
  <title>Tidy design principles</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240203-tidy-design-principles/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Paused. Current progress 21%.⏱</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://design.tidyverse.org/" class="uri">https://design.tidyverse.org/</a></li>
</ul>
</div>
</div>
<section id="unifying-principles" class="level1 unnumbered"><h1 class="unnumbered">Unifying principles</h1>
<ul>
<li><p>The tidyverse is a language for solving data science challenges with R code. Its primary goal is to facilitate the conversation that a human has with a dataset, and we want to help dig a “pit of success” where the least-effort path trends towards a positive outcome. The primary tool to dig the pit is API design: by carefully considering the external interface to a function, we can help guide the user towards success.</p></li>
<li>
<p>The tidyverse has four guiding principles:</p>
<ul>
<li><p>It is <strong>human centered</strong>, i.e.&nbsp;the tidyverse is designed specifically to support the activities of a human data analyst.</p></li>
<li><p>It is <strong>consistent</strong>, so that what you learn about one function or package can be applied to another, and the number of special cases that you need to remember is as small as possible.</p></li>
<li><p>It is <strong>composable</strong>, allowing you to solve complex problems by breaking them down into small pieces, supporting a rapid cycle of exploratory iteration to find the best solution.</p></li>
<li><p>It is <strong>inclusive</strong>, because the tidyverse is not just the collection of packages, but it is also the community of people who use them.</p></li>
</ul>
</li>
<li><p>Idea of “chunking” is important. Some setup cost to learn a new chunk, but once you’ve internalised it, it only takes up one spot in your working memory. In some sense the goal of the tidyverse is to discover the minimal set of chunks needed to do data science and have some sense of the priority of the remainder.</p></li>
<li><p>Most importantly performance of code depends not only on how long it takes to run, but also how long it takes to <em>write</em> and <em>read</em>. Human brains are typically slower than computers, so this means we spend a lot of time thinking about how to create intuitve interfaces, focussing on writing and reading speed. Intuitive interfaces sometimes are at odds with running speed, because writing the fastest code for a problem often requires designing the interface for performance rather than usability. Generally, we optimise first for humans, then use profiling to discover bottlenecks that cause friction in data analysis. Once we have identified an important bottleneck, then performance becomes a priority and we rewrite the existing code. Generally, we’ll attempt to preserve the existing interface, only changing it when the performance implications are significant.</p></li>
<li>
<p>There are two ways that we make functions consistent that are so important that they’re explicitly pull out as high-level principles below:</p>
<ul>
<li><p>Functions should be composable: each individual function should tackle one well contained problem, and you solve complex real-world problems by composing many individual functions.</p></li>
<li><p>Overall, the API should feel “functional”, which is a technical term for the programming paradigm favoured by the tidyverse.</p></li>
</ul>
</li>
</ul></section><section id="implementation" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> Implementation</h1>
<section id="names-attribute" class="level2" data-number="1.1"><h2 data-number="1.1" class="anchored" data-anchor-id="names-attribute">
<span class="header-section-number">1.1</span> Names attribute</h2>


<!-- -->

</section></section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>R</category>
  <guid>https://learn.shitao5.org/posts/20240203-tidy-design-principles/</guid>
  <pubDate>Fri, 02 Feb 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240203-tidy-design-principles/logo.png" medium="image" type="image/png" height="166" width="144"/>
</item>
<item>
  <title>王川宝典</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240203-wcbd/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Completed.🎉</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://cowtransfer.com/s/29923361e05744" class="uri">https://cowtransfer.com/s/29923361e05744</a></li>
</ul>
</div>
</div>
<section id="财富" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 财富</h1>
<section id="赚钱这事不可入戏太深" class="level2" data-number="1.1"><h2 data-number="1.1" class="anchored" data-anchor-id="赚钱这事不可入戏太深">
<span class="header-section-number">1.1</span> 赚钱这事，不可入戏太深</h2>
<ul>
<li><p>所有对于赚钱，对于财富的追求，本质是希望解决下面这个问题：生活可以不那么辛苦，不用被迫做自已不愿做的事情。我把这个目标简化成四个字：<strong>不累，自由</strong>。赚钱只是为了实现上述目标的手段。</p></li>
<li><p>理想状态是，你生活工作中选择做的所有事，既有四两拨千斤的机械增益，又有进退自如的自锁功能。做一件事，可以选择休息离开一阵子，事情的进度不会因此受影响甚至倒退，什么时候休息好了可以回来精神抖擞地继续工作。<br>
如果你做的事，是个逆水行舟，不进则退的事情，必须你亲自不断事必躬亲地，费力地维护，那这就不是一个理想的事业。</p></li>
<li><p>德川家康后来留有几句家训，一曰“人生如有负重致远，不可急躁”，二曰“视不自由为尝试，则不觉不足”，三曰“只知胜而不知败，必害其身”。这几句话也许对着急发大财，以登福布斯富豪榜为唯一人生目的的朋友们有点借鉴作用吧。</p></li>
<li><p>解决各种实际问题才是生活的第一要务。</p></li>
<li><p>问题定义好之后，赤膊上阵直奔主题不一定是最好的方法。先要思考解决问题的工具，利其器后方可善其事。大部分时间应当用于“磨刀霍霍”利其器，等到真正需要“向猪羊”时，则手起刀落，易如反掌。</p></li>
</ul></section><section id="做一个时间富有的人" class="level2" data-number="1.2"><h2 data-number="1.2" class="anchored" data-anchor-id="做一个时间富有的人">
<span class="header-section-number">1.2</span> 做一个时间富有的人</h2>
<ul>
<li><p>最大的财富是闲暇时间，对闲暇时间的最大杀手是一对一的交流，给一个老板打工，或者做一次只能卖给一个客户的定制服务。有更多的闲暇时间，才能深入思考更多前瞻性的问题，才能避免重大战略性的浪费和失误，从而有更多闲暇时间，形成良性循环。警惕任何可能打断这种循环的行为误区。</p></li>
<li><p>当收入超过一个基本值满足基本生活需要以后，更多的金钱不是最终的目的，而是提高赚钱的效率，不断增加私人自由支配/做自己想做的事的时间。保持自身的效率和灵活性，更多的利润迟早会自然涌现。</p></li>
<li><p>千万不能随意接受任何人给你设定的某个截止日期，这样人为摧毁自己的时间冗余，可能酿成大祸。</p></li>
<li><p>提高生活质量的一个角度，是把有时间压力的活动，尽量压缩到日常的 10% 以下。这样可以保持比较长久的内在动力。</p></li>
</ul></section><section id="陈旧的财富观念" class="level2" data-number="1.3"><h2 data-number="1.3" class="anchored" data-anchor-id="陈旧的财富观念">
<span class="header-section-number">1.3</span> 陈旧的财富观念</h2>
<ul>
<li><p>和他人进行金钱，地位或者名气等等的直接实时的攀比，是封闭社会的习惯，在指数增长的开放世界里会非常可笑。而且以这种直接攀比来指导自身策略的制订，往往自乱阵脚，适得其反，事倍功半。</p></li>
<li><p>幸福就是全面的，长期的指数增长。所谓中年危机就是找不到增长点了，也不知道如何真正有机的增长，想拆东墙补西墙寻求表面的增长，反而在泥潭里越陷越深。</p></li>
<li><p>指数增长的神奇，在于常会出现几个月的财富增长超过以前几十年全部积累的现象，而且这种现象，在新兴产业涌现时，屡次发生。重要的课题是理解底层机制，区分伪增长和真正的指数增长，区分有很大潜力的指数增长和昙花一现的泡沫。真正理解机制后，人就不急了。如果你急着要发财，实际上还是没弄懂。</p></li>
<li><p>正确的攀比方法是在经验和方法论上和世界上各行业最优秀的人攀比（学习），在最终的结果上和过去的自己攀比。</p></li>
<li><p>如果效率没有比别人有明显的几倍以上的优势，实际操作上大概率就是在自欺欺人的瞎搞。</p></li>
</ul></section><section id="财富和金钱的本质" class="level2" data-number="1.4"><h2 data-number="1.4" class="anchored" data-anchor-id="财富和金钱的本质">
<span class="header-section-number">1.4</span> 财富和金钱的本质</h2>
<ul>
<li><p>财富的本质是能量和信息的效率。只要别人的能量和信息技术的效率超过你，你的东西很快就一钱不值。</p></li>
<li><p>金钱的本质，是对稀缺的资源，尤其是大众都想获得的稀缺资源的控制力。</p></li>
<li><p>赚钱的本质是为了让自己增加选择权；但让自己增加选择权的事情不一定都赚钱，甚至需要一定的投入。如果增加选择权和赚钱，两件事发生冲突，选择权永远优于赚钱。</p></li>
<li><p>财富的增加，本质来自于增加自己和外部的可组合性。这种可组合型本质来自于开放的，难以被外力破坏的自由连接。任何为了短期利益而减少自身可组合性的行为，最终必被反噬而得不偿失。</p></li>
</ul></section><section id="具体投资标的分析" class="level2" data-number="1.5"><h2 data-number="1.5" class="anchored" data-anchor-id="具体投资标的分析">
<span class="header-section-number">1.5</span> 具体投资标的分析</h2>
<ul>
<li><p>组织结构的惯性，对于任何压低毛利率的竞争压力都会极力抵触。</p></li>
<li><p>新技术的价值最终会聚焦在软件平台上，预测哪个软件平台会胜出，一个重要观察角度是应用开发者愿意在那个平台上开发新应用，这是领先指标。</p></li>
<li><p>未来新的技术平台，要预先判断谁一家独大，一定要近距离观察和理解开发者的视角。开发者越多，应用就越多，用户就越多，生态就更丰富，大家都有更多的钱可赚。开发者的角度很简单，哪个平台可以让我以最小的开发费用，接触到更多的潜在客户，让我赚更多的钱，我就往哪里去。少数技术指标领先 ，但应用生态匮乏的平台，迟早会被虽然局部指标暂时落后，但应用生态丰富的平台超越。而丰富的应用软件，会互相依托，催生出更高效丰富的生态。</p></li>
<li><p>权力的基础，来自于各个微小的层面，你有别人没有的东西。</p></li>
<li><p>要提升对这个世界的理解力，也应当不断训练自己把各种看似距离较远，但实际上强相关的事物关系，能够迅速提取出来的能力。</p></li>
<li><p>效率高的工具，演化到一定程度，会把各种元素连接综合起来，成为一个前所未有的效率越来越高的实体，甚至从一个遥远的观察者来看，像一个有着明确目标的生命体。要注意观察 GPT 的连接，会造就出什么样的全新的，结构完全不同的实体。<br>
大语言模型将成为智能组合叠加的超级胶水。本质上是语言理解力强，降低了接口的精确性要求（一般软件接口种类繁多，各家定义不同，格式严格精确性要求高，还要考虑兼容，做到通用性不容易），大大提高了接口的通用性，降低了各个子领域技术组合的门槛。<br>
把这个思路延伸一下，在分配时间和注意力的时候，最重要的不是你掌握某个具体技术的能力，而是要保持始终和智能最高的大语言模型的生态连接（而不被切断）的能力。始终沉浸于这个生态中，你就赢了大半；孤立的闭门造车，而幻想能创造出什么竞争优势，最好也就是昙花一现，大概率则是白忙一场。</p></li>
<li><p>GPT 的技术，相当于可以让极少数人具有“超大规模处理非结构数据信息”的能力，这个能力层层叠加爆发出的生产力，看不到上限。</p></li>
<li><p>大部分创业的折腾，如果没有达到“收税的生态位”时，非常辛苦，对投资者风险也大。达到“收税的生态位”是一个长期耕耘的过程，也需要一定运气。但如果你还不确信某个东西是否达到“收税生态位”，那就还没到。</p></li>
<li><p>真正的竞争壁垒不在于数据，而在于生态的构建，尤其是当大量第三方开发者自发参与生态的建设。</p></li>
<li><p>如果三十年后的趋势很明显，就不要纠结短期的变化逆势而动。</p></li>
<li><p>汽车行业的一个共识是，车价每下降五千美元，可以负担得起的买家数目就会翻倍。</p></li>
<li><p>搞技术的人有个误区，就是大大低估“品牌共识”的力量，而只是一味注重简单粗暴的技术参数。</p></li>
<li><p>搞技术的人有一种错觉（有时看上去像是傲慢），就是因为自己对底层技术细节非常清楚，那么以为自己对于技术的应用场景也会懂得比别人多。但这里的关键在于，你永远无法想象某个新技术对于你视野之外的别人能够产生的所有应用场景。</p></li>
<li><p>结构（技术细节）和功用（应用场景）是两个完全不同的概念。但是人们往往把这两者混淆。误会之一是以为模仿同样的结构一定可以实现同样的功用，误会之二是以为要实现某个功用就必须要有某个特定的结构，误会之三是因为拥有某种结构就把自己限制在某个特定的功用上。</p></li>
<li><p>只要牢牢抓住稀缺资源，不要在乎别人怎么卷，让他们挥霍真正的稀缺资源，去高溢价置换和争夺事实上的非稀缺资源好了。</p></li>
</ul></section></section><section id="人际" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> 人际</h1>
<section id="几个不要" class="level2" data-number="2.1"><h2 data-number="2.1" class="anchored" data-anchor-id="几个不要">
<span class="header-section-number">2.1</span> 几个不要</h2>
<ul>
<li><p>可以注意别人给你提供的一些原始的客观信息。尤其是这些原始信息和你起初的理解差别比较大，甚至是你完全不知道的。这有可能导致你对自己决策的调整。</p></li>
<li><p>在认知和现实之间套利，永远是最轻松的。但前提是，自己的认知来源于多个角度和层面的原始数据，而不是周边（很可能比你更无知的）人的观点。</p></li>
<li><p>实际上对于任何高价值的棘手难题，标准答案是：没有简单答案。只有长时间多样化的各种微小积累。积累多了，你自然知道答案。不愿积累而想一步登天者，必将获得与其德性匹配的下场。</p></li>
<li><p>在关键问题上，不要依靠任何人给你许诺的支持。更不能因为这种不到位，而且随时可以撤销的支持而去 all in。</p></li>
<li><p>不管什么情况，如果别人不问，不要自作多情去给别人出主意，否则会非常讨人嫌。反之，理解了大家的行为动机和思维框架，就能更好地适应环境，顺势而为。</p></li>
<li><p>人性遇到问题时，一般只想尽快治标，而不愿花更大代价研究如何治本。</p></li>
<li><p>当别人向你寻求帮助时，一定要让他付出一定代价，而不能简单的给予，否则他就会像吸毒上瘾一样下次还缠着你；同时不能简单地顺着他的思路，给出治标的建议，一定要逼着他不断深挖问题的本质，自己慢慢摸索出来解决问题的多种答案。</p></li>
<li><p>在乎别人怎么看你，就跟无视资产的基本面，非常在乎二级市场的价格波动一样。对于资产而言，正确的处理方法是保证基本面的前提下，增加流动性，以获得属于你的流动性溢价。对于人际关系而言，正确的处理方法，是扩大自己的社交网络，而不要浪费时间试图改变对你不友好的人的观点。</p></li>
<li><p>相对封闭的社会让人有个误解，以为一定要保持这种联系，一定要学会适应迁就“不如己者”，是曰情商。但开放社会里，直接切断和无视，是成本最低的做法。</p></li>
<li><p>如果你诧异某些人完全没有必要那么努力地工作，却还要不断对外展现自己的勤奋，一个合理的解释框架是，他必须要维持一个庞氏局，用自己的勤奋忽悠置换来的资源来维持这个局。他不能停，一停庞氏局就彻底垮了。所以不合常理的表演式的勤奋，有可能是内在极为虚弱的一种折射。</p></li>
<li><p>局部的成就感和仪式感，和真正是否能够长期内捕捉到巨大的利益，很多时候毫无关系。</p></li>
<li><p>所谓有原则性，本质上是指有很多既得利益。</p></li>
</ul></section><section id="线下社交的弊端" class="level2" data-number="2.2"><h2 data-number="2.2" class="anchored" data-anchor-id="线下社交的弊端">
<span class="header-section-number">2.2</span> 线下社交的弊端</h2>
<ul>
<li><p>如果用“过程导向”的思路，建立扩大高质量高密度的商务关系网，就会避免效率低下，无头苍蝇一样的社交活动。“过程导向”者埋头做好自身的事，但也注重坚持长期的，零成本的，大规模的传播个人商业理念，建立自身商誉。这里的关键词是“零成本”和“大规模”。不再机会主义地寻求一夜情式的交易，而是靠良好的商誉不断巩固自己的网络。更重要的是，理念和商誉的自动传播不需要花费你的更多时间。</p></li>
<li><p>巴菲特说，“成功者和非常成功者的差别，在于非常成功者几乎对所有事情说不。”（The difference between successful people and really successful people is that readlly successful people say no to almost everything.）</p></li>
<li><p>真正有洞察力的思维模型，往往需要大量跨越较大时间空间的数据和信息积累，才能抽象出真实的一般规律。</p></li>
<li><p>人只有自己主动改变信息输入输出管道时，才能真正改变自己。</p></li>
</ul></section><section id="人际交流的几点经验" class="level2" data-number="2.3"><h2 data-number="2.3" class="anchored" data-anchor-id="人际交流的几点经验">
<span class="header-section-number">2.3</span> 人际交流的几点经验</h2>
<ul>
<li><p>一致性，永远不是愚蠢的特征。如果一个办事不得力的人只是愚蠢的话，他迟早会犯一个对你有好处的错误。</p></li>
<li><p>谈生意的时候，开始都很顺利，然后突然对方提出莫名其妙的新的条件，要让你做更多的事情，而自己并无更多的付出和实质性的 commitment，通常都是在拖时间忽悠你，你已经变成了备胎的角色。</p></li>
<li><p>“软弱”是一种长期积累的气质，它体现为在很多微观节点，不断选择哪个“短期容易，但长期代价要大若干个数量级”的道路，积累得足够多，就会变成一个任人摆布，毫无抵抗能力的弱鸡。即使他可能外在张牙舞爪，暴跳如雷，也无法掩饰他软弱无能的惨淡现实。</p></li>
<li><p>企业家一般而言都有一个稳定的商业模式，有一定现金流，但外在没有太多炫耀性的消费。高级打工者或者一些初级投机者，一般自己本钱细微，总想不断以小博大，空手套白狼，all in 上杠杆，所以没几年就要出大问题而退场。</p></li>
<li><p>识人和识企业的规律是一样的，不要看它的文宣，而要先看他是否经过一个，甚至两个牛熊周期的考验。但这种情况不会因为你意识到而改变，只是说不同的环境生态就自然会涌现有某一特性的玩家。你能做到的就是理解本质，规避风险，尽量选择对你长期最好的环境而已。</p></li>
<li><p>不要屈服于外人没有事先支付合适代价，就想给你强加的压力，不管是显性的还是隐形的。一笔交易中，更着急的那一方必须要付出更多的代价。而不等对方付出代价就随便被外人的指挥棒引导，势必导致各方面资源的错配，自己的事业迟早会有重大损失。</p></li>
<li><p>人的选择非常依赖于他在各个生态环境内所能驾驭的力量：积累的连接越多，技能越多，选择也越多，自然大概率可以做出较优的决策。否则会对未知的环境存在畏难和习得性无助的情绪，有好的选择也抓不住。</p></li>
</ul></section><section id="抛弃对世界的一厢情愿" class="level2" data-number="2.4"><h2 data-number="2.4" class="anchored" data-anchor-id="抛弃对世界的一厢情愿">
<span class="header-section-number">2.4</span> 抛弃对世界的一厢情愿</h2>
<ul>
<li><p>一厢情愿的例子之一，是以为我们对别人好，别人就一定会回馈。但客观现实是，指导人们行为的标杆，是未来你对他有什么好处。无原则地释放善意，是自身资源的巨大错配。如果因为别人不帮你，对别人进行忘恩负义的道德指控，是无效无益的。让自己未来始终有用有价值，才是正解。</p></li>
<li><p>当你寻求别人帮助的时候，要从对方的自身利益出发来引导，而不是乞求他们的仁慈或者感激。（<em>The 48 law of power</em>）</p></li>
<li><p>不仅要让自己有用有价值，而且要让很多人都知道认可自己有用。只要你有用，只要很多人知道你有用，就不愁在未来找到各种各样源源不断的合作者。同时其他一些不相干的旁观者在思考是否和你建立合作的关系中，也会因为这个因素，会对你有更多尊重。从这个角度看，那些甘于默默无闻，从不利用社交媒体来宣传自己的人，白白丧失了发展自己事业的一个重要工具。</p></li>
<li><p>当我听到一些朋友侃侃而谈“大道至简”的时候，我知道，他们可能会因为顽固地一味追求简单，以简单为目的，而重复前人的那些一厢情愿的挫败。大道至简的一个角度可以理解为后端复杂，但对外的 API 简单。但一些无知的懒汉，偷换概念，想不劳而获，自己后端简单，没什么货，也妄想前端的 API 能简单。</p></li>
</ul></section><section id="人缘好是硬通货" class="level2" data-number="2.5"><h2 data-number="2.5" class="anchored" data-anchor-id="人缘好是硬通货">
<span class="header-section-number">2.5</span> 人缘好是硬通货</h2>
<ul>
<li><p>人缘好是真正的硬通货，别人会不请自来地把各种资产空投到你的地址上。二十一世纪最大的财富是“人缘好” + “一个人尽皆知的以太坊地址”。</p></li>
<li><p>真正的奢侈品，是找到一个在某些方面比自己水平高的人，能够在一些你百思不得其解的问题上，点拨出几个你原来不懂，而且自己也很难琢磨出来的关键逻辑，让你终于茅塞顿开，而且极大增加了和世界互动的信心和勇气。</p></li>
<li><p>关注各种社交媒体上各行各业的最优秀的信息源，还有大量阅读各种优秀的书籍，是建立高质量关系，做出高质量选择，而无需消耗个人自控力的有效方法。</p></li>
<li><p>当我们说“人的关系靠缘分”时，缘分背后的本质是悟性，否则高人就在身边仍然存在“有眼不识泰山”的问题。而悟性背后主要靠的是知识结构的深度和广度。而广度可以一定程度上弥补深度的不足。因为当你的广度足够大，就对很多事情存在敬畏，而不会因为见识少的浅薄而武断执着。</p></li>
<li><p>只有极少数朋友，能够从维护你的利益角度，给你真实客观的负面反馈，才真正有价值。</p></li>
<li><p>一个犹太家庭，遭到纳粹的迫害，分成两队投靠两个不同的朋友。一个朋友是以前主动帮过他们的人，一个朋友是接受过他们救助的人。投靠第一个朋友的获救了，投靠第二个朋友的家庭成员则不幸被出卖。<br>
多和那些乐于助人，主动给予的朋友交往吧，他/她们是充满着正能量的你生活中的贵人。</p></li>
</ul></section><section id="论弱关系的重要性" class="level2" data-number="2.6"><h2 data-number="2.6" class="anchored" data-anchor-id="论弱关系的重要性">
<span class="header-section-number">2.6</span> 论弱关系的重要性</h2>
<ul>
<li><p>最有价值的弱关系，是那些可以连接你和其他大型社区的桥梁型的弱关系。</p></li>
<li><p>弱关系帮你找到更好的事情去做，强关系帮你把现在的事情做得更好。</p></li>
<li><p>强关系类似神经网络的宽度（知识的深度），弱关系类似神经网络的深度（知识的广度）。网络的深度数量增加，各种可能性指数型的增加。深层神经网络技术的突破，导致了当下的人工智能技术的飞跃，这是数学上的必然。</p></li>
</ul></section><section id="做一个超级连接者" class="level2" data-number="2.7"><h2 data-number="2.7" class="anchored" data-anchor-id="做一个超级连接者">
<span class="header-section-number">2.7</span> 做一个超级连接者</h2>
<ul>
<li><p>自己的知识体系越丰富，越能产生跨领域的连接。</p></li>
<li><p>提高效率，减轻负担的一个关键是：不断削减，谢绝一对一的交流和互动。尽量增加一对多的交流和互动。</p></li>
<li><p>一对多的时候，不会因为外界任何个体的问题被卡住，总是有更好的选择可以绕过去，效率和节奏始终保持在较高的水平。</p></li>
<li><p>写文章和制作录像是比现场演讲更高级的一对多，写程序被反复调用又是比写文章更高级的一对多，制作 API 又是写程序中更高级的一对多。</p></li>
<li><p>最大的财富是闲暇时间，对闲暇时间的最大杀手是一对一的交流，给一个老板打工，或者做一次只能卖给一个客户的定制服务。财富总是流向更高级的一对多的技术。没有常常一对多的沟通，无法理解一对一沟通的极度低效。没有从头到尾各个阶段审视一个事情的发展变化，无法理解被局部假象当指挥棒带着走的幼稚可笑。</p></li>
<li><p>通过公开展示你的思考，来寻找在知识结构，兴趣或技能上，可能与你产生互补作用，或者 <img src="https://latex.codecogs.com/png.latex?1+1%3E2"> 的效应的朋友。公开展示长期留存的文字记录，效率最高。</p></li>
<li><p>真正有可能获取最大利益的人是在技术和商业模式两边自由游走的人，能够理解技术具体如何改变和发展新的商业模式，能够从商业模式的角度理解技术的哪个维度更重要。这也是 Edge of chaos （混沌边缘）的一个体现吧。</p></li>
<li><p>投资的一个视角，是掌握世界上流动性最高的系统内的最稀缺的资源。</p></li>
<li><p>流动性是建立在信任的基础上的。从个体角度而言，信赖你的人有多少，你的流动性就有多高。而这个数目超过某个临界点，就会形成品牌效应，流动性产生指数级的跃迁。</p></li>
<li><p>可编程，可拓展的贸易联系 <img src="https://latex.codecogs.com/png.latex?%3E"> 人际关系 <img src="https://latex.codecogs.com/png.latex?%3E"> 个人能力。推论是：把自己的对外贸易连接尽量自动化，扩展化，其回报远大于搞人际关系，或者单纯的局部提高个人能力。</p></li>
<li><p>在不过多消耗自身带有稀缺性的瓶颈资源（比如时间）的前提下，不断主动扩大和外界合作的规模，是提高自身利润率和效率的一条可以真正长期持续的捷径。</p></li>
</ul></section></section><section id="健康" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> 健康</h1>
<section id="减肥与间歇性断食" class="level2" data-number="3.1"><h2 data-number="3.1" class="anchored" data-anchor-id="减肥与间歇性断食">
<span class="header-section-number">3.1</span> 减肥与间歇性断食</h2>
<ul>
<li><p>实际上投资和生活中许多问题，都可以按照这样的思路解决：把一个看似复杂，无法解决的大问题，细分为许多力所能及，可以解决的小问题，去一个个解决，积小胜为大胜。日积月累，自然水到渠成。<br>
唯有细分，你才能发现问题症结所在。只有细分，你才可以各个击破。我可以做到，你也行，只是看你有没有这个定力，去知行合一了。</p></li>
<li><p>间歇性断食（intermittent fasting），对于减肥而言，比少吃更有效，而且还有增进身体健康和抗衰老的益处。</p></li>
<li><p>间歇性断食并不适用于所有人，但对于体重超标（BMI &gt; 25），营养过剩，很少从事重体力劳动的大部分人而言，是一条减肥和促进健康的正道。</p></li>
<li><p>因为随机控制实验成本太高，所以往往搞了很多观察性研究。但如果不理解各种认知偏差，不理解干扰因素（confounding variable）等等基本概念，很多论文可以从各种角度断章取义，获取对自己有利的结论。而外行人对此完全没有辨别能力。</p></li>
<li><p>早上接受日光沐浴，对提高睡眠质量的好处，甚至超过运动。这体现在睡眠深度增加，以前睡八个小时还有些困乏，现在七个小时就觉得很精神。而且如果半夜醒来，一般很快就能重新入睡。现代人长期在室内活动，很少主动自觉地在清晨接受阳光，这恐怕是睡眠质量差的一个重要原因。</p></li>
</ul></section><section id="规律运动" class="level2" data-number="3.2"><h2 data-number="3.2" class="anchored" data-anchor-id="规律运动">
<span class="header-section-number">3.2</span> 规律运动</h2>
<ul>
<li><p>单项运动容易让人陷入比拼成绩的回报递减的泥潭。很多时候成绩无法进步，本质是因为身体机能某个参数到了瓶颈，光靠主观努力完全白费力气，而且削弱了健身的乐趣。多样化健身，按照自己的兴趣，摸索各个不同方向的科目，你永远不会输，总能有进步，而且很久后会发现自己达到了以前想不到的高度。</p></li>
<li><p>可以和过去的自己比较一下。但应试教育里面不断和别人比拼成绩的心态，对于保持“多样化健身”的乐趣和长寿，是有毒的。</p></li>
<li><p>真正的好医生，治未病。再也没有比循序渐进，保持一定强度的持续锻炼，更好的灵丹妙药了。</p></li>
<li><p>如果不从“权利和垄断演化的机制”角度来理解投资，而只是看看财务报表和 K 线图，或者追逐某个板块和叙事，本质还在“连错都谈不上”（not even wrong）的层次。</p></li>
<li><p>运动和读书/思考，必须天天有，保持基本强度和时长，不进则退。</p></li>
<li><p>生活工作投资也是，很多细节，如果稍微定量化一下，然后强迫自己坚持完成，实际上都不是特别高的要求，但是积累一段时间，自己可能都会被结果惊讶。</p></li>
<li><p>不要羡慕他人所谓无忧无虑的生活，这大概相当于在无重力条件下生活的宇航人。NASA 有资料说在太空飞行五到十一天，如果没有持续主动的负重训练，肌肉萎缩可能高达 20%。回到地球时手无缚鸡之力，会非常危险。<br>
在自己遇到全新的问题和烦恼时，能够忍住烦躁，直面问题，拆解问题，找到症结所在，最终化解问题，是一种美妙的感觉。这个坎能够过，“情绪肌肉”就又强大了一轮，有更大的耐受力去迎接新的更复杂的问题。这个坎过不了，就像肌肉受伤一样，恢复需要很长时间，甚至陷入抑郁症。</p></li>
</ul></section><section id="跑步" class="level2" data-number="3.3"><h2 data-number="3.3" class="anchored" data-anchor-id="跑步">
<span class="header-section-number">3.3</span> 跑步</h2>
<ul>
<li><p>长跑的另外一个好处是，可以提高自己的最大摄氧量（vo2max），心肺功能极强，这样平时做任何事情都会感觉更轻松随意。游泳也有同样效果，但不能慢慢的蛙泳（那等价于走路），而必须有一定强度的自由泳。</p></li>
<li><p>避免运动损伤的唯一灵丹妙药，就是在身体有一点点不舒服或者疼痛的时候，立刻停止运动，开始休息。不以短期运动成绩为导向，不去逞能和蛮干。即使外人用羞辱式的激将法，也不要去理会。<br>
避免投资破产的唯一灵丹妙药，就是要把部分资金完全严格隔离，只放在最安全的投资工具上。拒绝以短期 Profit and Loss 为导向。即使有人用“别人恐惧我贪婪”的空洞口号来刺激你的时候，也绝对不能违反这个根本原则。<br>
大部分竞技运动最后都变成残害身体的回报递减的活动了，仅仅是由于人为设置的巨额奖励才得以维持。真正回报最大的活动是不屑于外在奖励的。或者他本身就成了设立奖项/制定规则的人。比如说世界上不存在“首富奖”，“寿星奖”，等等。</p></li>
<li><p>为了保持足够的运动量，必须在顶层设计上多挖掘和探索出更多的多样性，让各种新奇感可以自发涌现，这样坚持就不再是个负担，而是一种渴望。</p></li>
<li><p>如果用“跑-走-跑”的方法，每跑几分钟就切换成走路几十秒，一方面走路时腿的受力只有体重的一倍多一点，另一方面走路对心肺功能的需求更低，因此有更多血液和养料可以输送到腿部，以帮助迅速恢复。这样有效避免受伤，有助于把这种锻炼长期坚持下来。</p></li>
</ul></section><section id="睡眠" class="level2" data-number="3.4"><h2 data-number="3.4" class="anchored" data-anchor-id="睡眠">
<span class="header-section-number">3.4</span> 睡眠</h2>
<ul>
<li><p>咖啡因在体内的影响的半衰期是五到七个小时，下午和晚上喝尤其糟糕，会严重干扰睡眠。应当尽量避免消费含咖啡因的食物和饮品。</p></li>
<li><p>越来越多的证据表明，用餐时间是代谢调控的重要因素，而昼夜节律与代谢功能之间存在密切的相互作用。昼夜节律的正常运作对于保持代谢健康至关重要。因此，时间营养学是一门新兴的学科，研究昼夜节律、营养和代谢之间的关系，近年来受到越来越多的关注。</p></li>
<li><p>很多人讲究表面的卫生，穿衣，化妆，却对更重要的睡眠卫生没有精细管理。这是非常不理性的。</p></li>
<li><p>人一半以上的幸福感，都是来自深度和充足的睡眠。没有充足的睡眠，体内细胞和组织的自我修复过程也无法充分完成，各种潜在的慢性疾病和衰老会不断积累，叠加，恶性循环，加速直到最后完蛋。</p></li>
</ul></section><section id="抗衰老" class="level2" data-number="3.5"><h2 data-number="3.5" class="anchored" data-anchor-id="抗衰老">
<span class="header-section-number">3.5</span> 抗衰老</h2>
<ul>
<li><p>人体衰老是个多维度全方面的细胞和脏器的功能退化的过程，而全面的运动是缓解和保持系统不明显退化的最有效手段。</p></li>
<li><p>睡眠 - 运动 - 饮食这是保证代谢健康的三大支柱，缺一不可，有一个短板都会严重损害健康，加速衰老。</p></li>
<li><p>从小就被灌输要努力学习和工作的人，潜意识里，一天不学习/工作/挣钱，就会产生一种负罪感，或者不安全感，觉得在荒废光阴。这种潜意识到了极致，就会产生很多荒谬现象，比如很多人牺牲健康去创业挣钱，即使自己知道有问题也无法摆脱。</p></li>
<li><p>卧倒，相对于坐着，站立，是人体最放松的一种姿势。有的时候你如果只是简单思考问题的话，我也建议躺在垫子上，而不是坐在椅子上思考。</p></li>
<li><p>活得越长，资产累积增长的时间和幅度就越大。所有的投资和经商的策略都是在和时间赛跑。你如果为了短期的财富目标，用力过猛，跑得太快，忽略健康，反而会减少自己的寿命和长期的财富积累。</p></li>
<li><p>在我的领域，我学到的是，永远不要相信专家，除非他们有数据支持他们的观点。要对专家非常小心，因为专家往往对过去非常了解，但是对未来懂得很少。经验证明，许多专家在预测未来时，想象力上有重大缺失，我只相信数据的外推法。还记得 Louis Dublin 预测平均寿命的上限止于 65 岁吗？</p></li>
<li><p>很多健康问题（包括容易感冒染上病毒），底层原因都是因为心肺功能太差，增强心肺功能的唯一办法，是不断循序渐进地加大有氧运动的强度。</p></li>
<li><p>提高心肺功能对于长寿而言，其重要性远远大于吸烟，体重，糖尿病，高血压等风险因子。</p></li>
<li><p>身体健康最终要依靠自身的免疫力，而不是药物。自身培养的免疫力，是最便宜可靠的，而且没有药物的副作用。强大的免疫力来自平和的心态，和健康的生活方式：充足睡眠，节制饮食，适度运动。维系这些健康生活方式，需要高度的自律。而高度的自律，最终需要的还是平静，理性和强大的内心。</p></li>
</ul></section></section><section id="事业" class="level1" data-number="4"><h1 data-number="4">
<span class="header-section-number">4</span> 事业</h1>
<p>所有的技术路线，在复利积累上，都迟早会遭遇资源瓶颈，而无法再进步。所以一定要保持多条线索同时迭代，积累。一条路线到头了，就找另外一个不同维度的，潜力更大，增长更快的路线去积累。尊重自发涌现，不要在一条路径上死磕。这就是摩尔定律演变的真实机制。</p>
<section id="如何实现复合增长" class="level2" data-number="4.1"><h2 data-number="4.1" class="anchored" data-anchor-id="如何实现复合增长">
<span class="header-section-number">4.1</span> 如何实现复合增长</h2>
<ul>
<li><p>一般心智健全的人，都会找到某个东西让他非常有兴趣废寝忘食去忘我探索，不管是画画，写文章，写代码，还是创作什么别的东西。只要这类创作探索的成本足够低，就可以自由迭代若干次，达到极高的质量，通过各种社交媒体渠道发表，最终能够找到高溢价的变现方式。<br>
如果你每周要被迫给人打工，包括在路上的时间是 N，给自己定个计划，花四到五年时间，把 N 降到 10 以下，直到它接近于零。剩下的时间就可以自由探索创造了。很多伪创业是成本极高的盲动，只会适得其反。<br>
大部分工薪阶层每周工作加上来回的时间接近五十个小时。本质等价于每周要做接近五十个小时的奴隶。如果把 N 压到 10 以下，有自由时间去探索创造，其它问题基本迎刃而解。为了伪创业而牺牲实质的自由支配时间，被迫做很多不喜欢的事情，变成另一种变相的奴隶，也很不划算。</p></li>
<li><p>摩尔定律之所以可以持续复合增长，是因为底下存在上百个不同微创新和技术路线在彼此竞争，你看到的只是冒头的增长最快的那个技术路线而已。同理，个人的复合增长，也应当争取在多个不同的增速最快的方向/领域上同时布局，定期强行调整，这样不至于全部资源卡在某个错误路线上浪费很长时间。</p></li>
<li><p>知识和工具库里的部件多了，还有一个好处：你总是可以在某个方向做一些低成本的测试，得到一些正反馈，让你进一步改进，也同时丰富了你的工具库。这样你始终乐在其中，有动力不断探索。</p></li>
<li><p>信息科学，本质就是提高能量的转化与存储的效率。而能量转化存储效率提高，又可以支持更复杂的信息处理系统。信息和能量，永远是研究人类文明进步的两个最重要的变量。<br>
可以这么看，每天要八小时上班，本质上和古猿人主要精力在觅食吃东西是一样的。社会和个体的进步，本质来源于更多人可以从琐碎重复的工作中解放出来，而有很多闲暇时间用于创造性的探索中，这种探索可以支持建立更复杂的个人信息基础设施，进而进一步大幅度提高信息处理和资源调动的效率和能力。</p></li>
<li><p>复合增长的一个矛盾特点是：如果方向和目标太明确，过了市场饱和点之后会发现很多行为全是无效或极低效的，白白消耗能量，即使自己主观上很努力；但如果坚持在最开放的搜索空间里长期摸索，短期看似无所事事，没有进步，长期总是会在意想不到的地方找到指数增长的突破口。这也是为什么回撤（drawdown）和夏普比率（sharp ratio）这些概念，对于一个长期主义者而言，本质都是狗屁，会有反效果。</p></li>
<li><p>真正的效率提高，意味着不断重复利用过去的成果去构建更复杂的产品，或者把同样的成果和产品变着花样推广到更大的市场上去；如果被迫东一榔头西一棒子地搞各种杂事，或者要去做各种定制性的服务，那么一个人很难系统性地提高自己的效率，缺乏实质性竞争优势，无法有效复合增长。</p></li>
<li><p>凡是无法“长期复合式增长”的资产都不值得投资。而真正可以复合式增长的资产，重点不在于现在有多好看，而在于其“强大的系统性的增长动力”，和“几乎无法被外力破坏扼杀的特征”。这样可以彻底忽略掉各种短期噪音，而耐心坐等复利的长期积累，产生奇迹。</p></li>
<li><p>复合增长的两个重要动力，一是过去的劳动成果可以重复使用，二是行动自由度大，没有限制行动自由的瓶颈。打工者之所以无法深刻理解复合增长的内涵，一是因为顶头老板上司就是其最大瓶颈，二是一旦换岗位或者工作就要从头开始，很难重新利用以前的成果或资源。</p></li>
<li><p>如果不能在所从事的行业做到一家独大的话，那就必须有属于自己非常独特的细分市场，而无需和外界进行惨烈的杀价竞争。被迫降价竞争，是扼杀复杂增长的毒药，任何外表的勤奋努力都无法美化掩盖其破坏性。</p></li>
<li><p>阻碍效率提高的三个因素：浪费大量时间找东西，浪费大量时间等别人，无法重复利用以前的劳动成果。最理想的地方一般有下述特点：查找东西方便，多处备份，实物即使丢了也很容易换新的；潜在合作伙伴很多，如果一个人太慢等不及了，马上可以换下一个；可能不断大规模重复利用以前的劳动成果。</p></li>
<li><p>打工者的最大困境，在于其大部分努力最多只能换来老板廉价的夸奖，和一些不断贬值的法币，而无法产生终生受益的效率上的有效积累。然后每次换工作时又要清零重来一遍。</p></li>
<li><p>重要的课题是理解底层机制，区分伪增长和真正的指数增长，区分有很大潜力的指数增长和昙花一现的泡沫。真正理解机制后，人就不急了。如果你急着要发财，实际上还是没弄懂。</p></li>
<li><p>高效率，尤其是特定场景下碾压普通人的效率，随时可以兑换成财富。如果这个效率还能持续自发迭代，复合增长，那么财富价值就更大。</p></li>
<li><p>中年危机这个问题本质就是遇到发展瓶颈而无法增长了，而切换到新的增长路线需要初期比较大的投入，改行的早期比较艰难狼狈。但越不愿意改，后面代价就越大，越狼狈。要治本的方法是意识到定期（每隔最多五六年）切换到新的增长曲线是一种常态，所以要经常关注增长最快的新领域行业，多方面提早布局，提早切换。不要和同病相怜的可怜人混在一起，那样只会给自己增长无数理直气壮的借口，来保持现状。同病相怜的人，很难给你提供新的视角，而且大概率会强化，合理化你的懦弱和无知。然后阻力最小的路径，就是缩在自己的泡沫里，继续抱怨和无作为。<br>
如果没有把“抓住最快和潜力最大的几个增长曲线”这件事情放在第一位，那就是“连错都谈不上”（not even wrong）。</p></li>
<li><p>很多人对财富的概念就是房地产，银行里存的钱或者券商那里代管的股票，“为了胜利而战”的思维，就是不断囤积和守卫，这是一种低维度的思路。如果是“只要不输就接着玩”，它的策略就是，积极思考拓宽财富的维度，即使部分财富因为不可避免的战乱或者其它动荡而被破坏，仍然能够同时在别的维度上获得财富，迅速恢复元气。</p></li>
<li><p>不管是人，还是公司，抽象画程度越高，向其它维度连接扩展的可能性就更多，也就更反脆弱。这也是为什么平台级软件系统估值，远胜于硬件和其它实体生意的原因。</p></li>
<li><p>如果所有的生意都依赖于某一个单一的社交平台，那非常脆弱，危险。所以一定要把自己的产品或者服务，通过多个独立平台，广为分发。</p></li>
<li><p>宁要高维度/抽象化/反脆弱的草，不要低维度/具象化/脆弱的苗。</p></li>
</ul></section><section id="给年轻人的职场建议" class="level2" data-number="4.2"><h2 data-number="4.2" class="anchored" data-anchor-id="给年轻人的职场建议">
<span class="header-section-number">4.2</span> 给年轻人的职场建议</h2>
<ul>
<li><p>如果有长期的宣传建立的品牌，常常会有客户自己找上门来，让你发现以前没有意识到的市场需求。不宣传自己，不对外探索，你永远不知道那些你不知道的市场（you don’t know what you don’t know）！</p></li>
<li><p>当一个极强动力的高端客户找上门的时候，你就有能力根据你提供的巨大价值来收取高额的报酬，而不必再理会那些利润率较低，需求和你提供的东西不匹配的客户。二者的单位时间的利润率，差距可能有两个数量级以上。</p></li>
<li><p>要花时间打造个人品牌，让更多人知道你的存在，知道你的才能，而不是偏安在某个公司的岗位上长期默默无闻。在社交媒体上长期发表有干货的文字，是一个有效手段。你会发现潜在市场比你的想象要大得多，市场的真实需求也和你的臆想有很多不同。潜在客户不断从你想不到的地方来找你，和你四处发简历找工作，是两个完全不同的体验。</p></li>
<li><p>当你接触真实的世界和市场时，会发现有些赚钱的机会和主流媒体上宣传的完全不一样。有些被人忽视误解的领域有赚大钱的机会，但是周围人一直不理解。有些被主流认为有面子有钱赚的职位实际很苦逼。你会困惑很长时间。但最终要相信自己长期实际的体验，而不要被媒体的虚假宣传或者错误认知误导而丧失主见。</p></li>
<li><p>没有捷径，需要长期不懈的努力构建自己的体系，just do it。</p></li>
<li><p>从节能和提高效率的角度看，最有效的操作是不断计算未来将朝哪个方向移动，然后尽量以最低的代价去提前布局和等待。而考虑的时间维度越长，可能撬动的不对称的巨大回报的机会也更多。因为短期大家都可以看到的明显的东西，竞争太激烈了，代价太大了。而且时常代价大到回报是负的。对短期的算计，最大的一个问题是低估竞争者的存在。竞争者的出现常会让你的劳动价值接近于零。对于长期的算计，则有大概率会发现一些精彩的无人区。</p></li>
<li><p>认知有点像古生物进化出来的视觉。有视觉的生物不一定有强健的肌肉，但肯定可以轻松把没有视觉或者视觉低下/但肌肉强健的生物给灭掉。认知框架准确的人看上去好像无所事事，但也可以轻松碾压认知图景完全错误的人群。</p></li>
<li><p>淘宝店主，保险或房地产经纪人听起来没有那么高大上，但里面确实有很多人实力远高于各类总监，而且地位要更稳固，实际经验丰富得多。</p></li>
<li><p>真正的思考需要反复推敲，一开始可能有大量不靠谱甚至幼稚的想法涌现，然后花很长时间不断折腾，去粗取精，最后才慢慢锤炼总结出有价值的东西。只有长时间写作，才容易达到这种效果。</p></li>
<li><p>提高调整纠错能力的一个重要维度：要从事流动性好，通用程度高，虚拟程度高的事业。</p></li>
<li><p>生命涌现的三个基本要素：第一要有很强的能量来源；第二要有固体形态可以存储保留信息；第三要有高流动性，可以实现信息的交流/组合/计算。这些是必要而非充分条件。</p></li>
<li><p>对比到个人的发展来看：第一要到人多经济发达的地方去发展。第二，自己的工作要能够可以记录存储下来，供以后利用。给别人打工，做一些事务性的东西，很难有记录存储的功效。钱可以看成是一种记录存储的形式，但是如果很快就花光了，也就无法存储下来。写作，艺术创造，打造产品品牌，都可以看成是记忆存储的工作。<br>
有了存储，还必须流通，寻求和其他资源组合/创造新价值的机会。所以不断在各个渠道网络去努力传播，也非常重要。能够在“能量/存储/流通”这三点都做到的人/公司/组织，和没有刻意做到这三点的人/公司/组织，其差别类似有机物/无机物的差别。<br>
可以看到，世界的发展史，就是一部：能量摄取效率更高，存储效率更高，容量更大，信息流通更快更多，生命形态更复杂的发展历史。</p></li>
<li><p>所有的专业人士都应当思考创造一些属于自己的，可以长期保存，反复引用，广泛流通的产品作品，这样才能真正实现个人的有机成长。否则不断要出售自己的时间，来换取金钱谋生，是一种痛苦的/低层级的存在。金钱有时并不是最好的信息存储方式，如果被忽悠去举债而无力偿还那就更糟糕。</p></li>
</ul></section><section id="创业" class="level2" data-number="4.3"><h2 data-number="4.3" class="anchored" data-anchor-id="创业">
<span class="header-section-number">4.3</span> 创业</h2>
<ul>
<li><p>可持续的竞争优势包括，你对某个事情特别执着沉迷，愿意花很多时间精力去自发地深入钻研；你在做别的日常业务时，可以顺便把某某事情做了，这样同一个事情对别人而言，启动成本为 N，对你而言启动和持续成本为零。</p></li>
<li><p>没有在源头上海量的，多样化的一手信息，所谓独立思考就是一种装腔的空话，仍然无法避免被各种噪音或者假象所裹挟的命运。如果说这种行为，在信息获取成本较为昂贵的过去，还 情有可原的话，现在还不断犯这种错误，只能说是懒惰和缺乏自我革新的意志力了。</p></li>
<li><p>真正的优势，都是根据自己在局部的具体实际情况和自己的兴趣，一点一滴地摸索积累出来的，有自己特色的优势。有没有优势，自己最清楚，优势越大，积累就越快，进步就越快。</p></li>
<li><p>任何一个雄心勃勃的创业者或者投资者，都应当依照第一性原理，以一种极为残酷的诚实态度，不断剖析自己，制定一个可以最终比肩，甚至超越巴菲特或者马斯克的五十年发展计划。<br>
这个计划的目标很可能无法达到。但是实践这个计划本身，会是一个有价值并充满乐趣的事情。一旦有了这样的计划，从五十年后倒推到今天，你日常决策和思考的参照体系会马上改变：它会强迫你挖掘出最大的潜能，而不是被动地毫无觉知地在环境中随波逐流。<br>
你在战略高度上会非常挑剔也非常现实：你拒绝参加任何没有结构性优势的赌博；你会更加果断并习惯去定期淘汰自身过时的行为模式或者业务。每一个落后习惯的迅速纠正，都意味着更大的结构性优势和更快的积累速度。用这种态度去实践，你会发现战术上越来越容易了，因为你是用指数级别的结构性优势，不断去碾压以前以为高不可攀的困难和障碍。</p></li>
<li><p>投资的目的就是躺平。不能躺平，终日忙忙碌碌的投资者是不合格的。</p></li>
</ul></section><section id="脱离做题家" class="level2" data-number="4.4"><h2 data-number="4.4" class="anchored" data-anchor-id="脱离做题家">
<span class="header-section-number">4.4</span> 脱离做题家</h2>
<ul>
<li><p>真正的艺术家和创作者，为兴趣和自由而创作，而不是去迎合讨好某个特定目标的受众。违背内心去迎合外界定义的 KPI。去讨好外人，是无法持久的，而且对方很容易可以感觉到，并因此对你的态度转为轻蔑。伟大的艺术家和创作者，永远是潮流的领先者，而拒绝做外人支配的做题家。</p></li>
<li><p>要成为出题家，最好在有巨大潜力并快速增长的行业里寻找引起你兴趣的切入点。快速增长期，会有很多真空需要填补，这时竞争不大甚至根本没有，只要你能挺身而出，即使智商不高，也已经赢了。为什么必须有巨大潜力？因为这意味着长长的增长曲线，即使错过这个机会，很快下面有心的机会等待你去填补。</p></li>
<li><p>跟随自己的兴趣来写作，是深度思考和提高自身能力的真正捷径。即使把别人的话抄一遍，抄写的过程中也常常自然涌现出新的感悟。</p></li>
<li><p>所谓“软件定义”，最本质的优点之一，是因为硬件已经被软件抽象化了，底层的硬件可以随时更换成性能更好的模块，而不会因为硬件的更新而被迫需要重写软件。</p></li>
<li><p>从某个角度看，接受专业化的高等教育，虽然有各种高学历和高大上的头衔，但最后的下场就是成为“软件定义社会”里一个被抽象化的，很容易被替代的模块。所以忙了一辈子，没有独特之处，缺乏强势的自我定价权。</p></li>
</ul></section><section id="科技发展对职业的影响" class="level2" data-number="4.5"><h2 data-number="4.5" class="anchored" data-anchor-id="科技发展对职业的影响">
<span class="header-section-number">4.5</span> 科技发展对职业的影响</h2>
<ul>
<li><p>各种各样的中间人，中间商，如果不能保持较大效率上的优势，最终都会变得无关紧要而被绕过去。</p></li>
<li><p>软件公司的高估值，很大程度上就是来自这种层层叠加的“重复使用”。DNA 就是生命体在地球上重复使用几百亿，几千亿次不断叠加演化出来的复杂软件。</p></li>
<li><p>智能大爆发时代的理性态度是：争取以较小代价获取技术进步的巨大红利，但如果自身努力的边际回报开始下降时，一定要选择等待，把这时间多用来锻炼身体和睡觉，而不是对体力和自身资源做无谓的消耗和摧残。因为你很清楚，技术进步正在加速，过了这村还有那个店，只要稍微等待一下，好的新机会信手拈来。</p></li>
<li><p>技术进步如此之快，以至于现在最佳的策略，恐怕默认是以“躺平，养好身体，等待”为主。否则你拼死拼活积攒的那点资源，很可能过几年，就因为技术因素而一钱不值，但你的健康则是切切实实损失掉了。这个 Wait Equation 相关的概念，值得好好研究。</p></li>
<li><p>未来属于能够扮演 CPU 和 GPU 角色的人或者组织。硬盘和内存的价格则会不断下降。很多人在社会分工中的角色相当于“硬盘”或者“内存”，就是知道某个局部的知识或者技能。人工智能技术将不断压低硬盘和内存的价格，因为各种“局部知识”将更加容易被调用。这时，扮演 CPU 和 GPU 角色的人的价值更重要。CPU 就是能够把各种不同资源结合调用，解决全新的问题；GPU 就是能够以超大规模的并行度，把各种资源同时调动起来，在更短的时间内解决某个问题。</p></li>
</ul></section><section id="积累" class="level2" data-number="4.6"><h2 data-number="4.6" class="anchored" data-anchor-id="积累">
<span class="header-section-number">4.6</span> 积累</h2>
<ul>
<li><p>最终要获得突破，一定要建立属于自己独特的体系。在一个多维度的信息世界里，只要涉猎足够广（宽度），下够足够多的功夫（深度），积累一定时间后，一定能够以你自己独特的方式，实现突破。</p></li>
<li><p>涉猎领域越广泛，到后面还有个神奇的效果，就是越来越容易触类旁通，把不同领域的知识连接融合起来，发现新机会，产生边际收益递增的指数增长的效果。这才意识到前面各种通识的自我教育，不是白学的。但要把自己的认知解释给没有基础的人，难！甚至一些稍微反直觉的概念会被不懂的人轻浮地嘲笑。</p></li>
<li><p>可以积累迭代的东西包括：属于自己的产品，品牌，自己的团队或客户或人脉网络，自己的财富（房产股票等），行业的经验，任何一个维度积累到足够深度，想不富都很难。</p></li>
<li><p>军事领域有句名言，“业务爱好者讨论策略，专业人士讨论后勤”。商业领域可以类似地说，“业余爱好者讨论策略，专业人士讨论积累“。缺乏后勤的军事攻势几天内就会歇菜，缺乏积累的盲目创业很快就会现金流枯竭。大量的积累最终还是需要长期自发的兴趣驱动，而不是苦行僧式地压榨自己。</p></li>
</ul></section></section><section id="输入" class="level1" data-number="5"><h1 data-number="5">
<span class="header-section-number">5</span> 输入</h1>
<section id="信息筛选" class="level2" data-number="5.1"><h2 data-number="5.1" class="anchored" data-anchor-id="信息筛选">
<span class="header-section-number">5.1</span> 信息筛选</h2>
<ul>
<li><p>生活工作就是一个一半时间做减法，一半时间做加法的循环往复，不断优化自身信息和能量效率的过程。</p></li>
<li><p>需要意识到虚假夸大的信息，是人间常态。通常你所看到听到的信息，都是信息发布方希望你看到的。重大决策，必须反复从多个角度，多个独立的信息渠道去验证核查。否则依靠直觉，被虚假信息所诱导，代价是惨重的。</p></li>
<li><p>所有事情，都有一个信息获取成本的问题。避免在信息获取成本高的地方去和别人竞争，否则别人放烟幕弹，释放虚假信息，你无法甄别。反过来说，你可以低成本获取高质量信息的空间有多大，你的自由活动空间就有多大。<br>
很多人从来不思考信息获取成本的问题。投资业搞尽调，每天到处飞，倒时差/饮食睡眠不规律/天天讲很多话耗神，是要折寿的。可以反向考虑，什么是你日常非常喜欢做的事情，在做这些事时，你是否顺带着可以低成本地获取哪类高质量信息？以此为基础的信息优势，你可以把握哪些普通人很难把握的机会？</p></li>
<li><p>如果把赚钱当成砍柴，那么建造“低成本获得高质量信息”的系统就好比磨刀。砍柴者众，利刃寡。磨刀永远不误砍柴工。你不需要太多柴，只需要一把独特的，与时俱进的，永远锋利的刀。</p></li>
<li><p>比较有价值的内容，是看极少数人几年前，甚至十几年前对一些趋势的预测分析，而事后发展和大众直觉相反，却和他的预测框架基本吻合。这种分析，值得反复阅读追踪，真正理解其底层逻辑。底层逻辑到表象的逻辑链条越复杂越矛盾，就越没有人耐心看，但这才是普通人凭自己努力真正可以抓住的机会。 <!--# 想起了天涯KK --></p></li>
</ul></section><section id="信息积累" class="level2" data-number="5.2"><h2 data-number="5.2" class="anchored" data-anchor-id="信息积累">
<span class="header-section-number">5.2</span> 信息积累</h2>
<ul>
<li><p>人脑的计算速度差不了太多，所谓智力，本质还是背后的阅历和经历。当搜索，获取和处理信息的成本较高的时候，阅历和经历丰富的人显得智力高。但是信息获取成本大大降低的时候，吸取信息量大而广的人最终胜出，而且这个差距在信息时代会不断拉大。而信息渠道过窄的人，容易被输入信息的内在偏见严重影响判断力，而带到沟里去。</p></li>
<li><p>知道的越多，就感叹为什么不早花时间去知道更多，而是像无头苍蝇一样被各种噪音和假象干扰误导，浪费大量精力去盲动。</p></li>
<li><p>敬畏来自于承认自己必定存在感知盲区，因此要不断学习提升；憧憬来自于有了正确的方法论和框架，相对于其他还在梦游的玩家，结构性的优势会越来越大。</p></li>
<li><p>提高自身全方位多角度地获取信息的能力是最好的投资，比物理世界很多投资要高效得多。</p></li>
<li><p>一个理性人，对于信息知识的持续投入，应当永远超过吃喝玩乐的花费。</p></li>
<li><p>通过自媒体持续发表文字或视频作品，可以在开放世界找到更多同道。受众巨大的自媒体人可以获得很多细微反馈，信息成本和纠错成本极低。信息来源和信息整合的优势，可以复合式增长。强大信息基础设施，造就全面信息优势，才能支持深度思考，才能指导有效的行动。</p></li>
<li><p>相比起在微信上发表文章，微博的极大优势，是可以迅速发短帖子，相当于软件工程的频繁迭代，“release often, release early”。而且遇到有共鸣者可以迅速被转发，迅速和一大堆人互动，迅速覆盖自己的盲点。</p></li>
</ul></section><section id="读书" class="level2" data-number="5.3"><h2 data-number="5.3" class="anchored" data-anchor-id="读书">
<span class="header-section-number">5.3</span> 读书</h2>
<ul>
<li><p>方法论的实践是需要付出代价的，但长期看付出的代价实际上最小。</p></li>
<li><p>散打高手，本质上就是不要让自己露出破绽，并能很快识别利用对手的破绽。搭一下手，过两招，大概可以识别对方的水平在什么量级，打不过就赶快跑。但很多从未被训练过的人对于打架时自己暴露的各种低级破绽，完全没有任何觉知。<br>
人际交往或做销售的高手，基本也是讲几句话，就大概可以理解对方的现状处境和动机，然后调整出有效的沟通方式。</p></li>
</ul></section></section><section id="创作" class="level1" data-number="6"><h1 data-number="6">
<span class="header-section-number">6</span> 创作</h1>
<section id="写作" class="level2" data-number="6.1"><h2 data-number="6.1" class="anchored" data-anchor-id="写作">
<span class="header-section-number">6.1</span> 写作</h2>
<ul>
<li><p>人脑的工作内存（working memory）只能够存四到五个概念，所以聊天扯淡胡喷时的思考深度永远比不上写作。写作时内存可以非常大，而且可以从容不迫地慢慢完成。真正的深度思考，没有文字的记录表达，根本无法完成。</p></li>
<li><p>读书就是不断搜索各种新概念的组件，然后通过社交媒体把自己的碎片思维扔出去，获得评论和新的线索，数量上去了，开放网络的效率自然碾压任何封闭的一个小区间。</p></li>
<li><p>写文章时收获最大的实际上是作者自己，作者对问题的理解深度，远超普通读者想象。也远超作者自己起初的想象。</p></li>
<li><p>创业投资的最终目的是保持高度自由和多重选择权，但自上而下的操作，为了解决一个问题搞出 N 个新问题，成了复杂度的囚徒，完全违背初心。</p></li>
</ul></section><section id="创意" class="level2" data-number="6.2"><h2 data-number="6.2" class="anchored" data-anchor-id="创意">
<span class="header-section-number">6.2</span> 创意</h2>
<ul>
<li><p>英国经济学家 Tim Harford 两年前讲过一个“如何更有创造力”的秘诀：就是慢慢地，没有时间压力地同时做多个不同的项目。（slow motion multi-tasking）</p></li>
<li><p>多个课题同时探索，本质是把自己主动置于一个更高维度的空间，高维度空间里总是可以找到新的高增长的方向，心情愉悦，而且在探索过程中会渐渐发现原来的困扰成为伪命题。运动多样化，和科学研究多样化的好处，有些底层逻辑是相通的。</p></li>
<li><p>创意来自于不同元素的链接。产生创意也许应该 80% 的时间用于积累各种多样化的素材，20% 的时间突然发现里面有些东西可以连起来，然后就去把它们组织连接起来。</p></li>
<li><p>太专注或太放松都不好，最理想的状态是在专注和放松的边界，可以随时来回切换。这有点像自组织/涌现理论里的“混沌边缘”（edge of chaos）的概念。以前只是简单地理解“一张一弛”，但二者之间的切换频率太低了。提高切换频率，常会有惊喜。</p></li>
<li><p>有创意的人，是极度反感各种约束的。主要的时间应当在于不断质疑，突破各种约束。而不是像个小媳妇一样乖乖地在螺丝壳里做道场。突破约束后才能有各种创意创新。Always question the constraint！</p></li>
<li><p>美国组织心理学家 Karl Weick：“我们更可能在行动的过程中，形成一种新思维；而不是在思维的过程中，促成一种新的行为”。</p></li>
<li><p>再也没有比读书和写作更高效的行动了。写开源软件，可以看成是一种广义的写作。</p></li>
</ul></section><section id="拥有自己的作品" class="level2" data-number="6.3"><h2 data-number="6.3" class="anchored" data-anchor-id="拥有自己的作品">
<span class="header-section-number">6.3</span> 拥有自己的作品</h2>
<ul>
<li><p>只要用心学习和创作，在社交媒体上拥有几万真实的粉丝，远比什么名校的校友网络有价值。</p></li>
<li><p>社交媒体上不用实名的，不管怎么折腾，实际上是放弃品牌建设，自己亏大了。</p></li>
<li><p>来自推特的 shaneAParrish：“外行人会分析自己的短处然后试图改进提高。行家会专注自己的长处，然后去寻找那些在自己的弱项上很强的人。”互联网使个人外包的选择越来越多。</p></li>
<li><p>对于个人而言，要把摩尔定律的机制用于自身的发展，就需要尽量做有这么几个特征的工作：制作成本低，边际成本低，分发成本低，通用性高，有长期价值。</p></li>
<li><p>那些听上去很厉害的大公司，和你的最大区别，无非就是他可以把产品卖给几百万人，你现在暂时只能卖给几个人而已。如果有几百万人以上的分发渠道，获得几百万人的信任，商业模式会自然涌现。即使你自己不知道套现，会有别人来请你帮你套现。但最后套现并不是最终目的，有最大数目的信任你的潜在客户和受众，就是最大的财富，不要为了短期利益而辜负他们的信任。</p></li>
<li><p>以钱为目的，而不享受艺术或技术摸索过程本身的人，反而在财富积累上走不远。</p></li>
<li><p>真正的艺术家和创作者，为兴趣和自由而创作，而不是去迎合讨好某个特定目标受众。</p></li>
<li><p>传统经济框架里，人口越多，对某个稀缺资源的竞争越大，最终会把稀缺资源的价格抬高，导致社会生产的回报递减。但是对于边际成本为零或者接近零的产品（比如软件或某种虚拟服务），人口越多，利润就越高，甚至即使产品的单价下调仍然可以获得更高的利润，而同时个体消费者也收益。这个现象是在八十年代之后才开始大行其道的。这两种不同的经济框架，常被老派经济学家混淆，因此常常得出错误的结论。</p></li>
<li><p>“幸福既不是美德，也不是快乐，既不是这一个事情，也不是那一个事情。幸福本质就是成长。我们在成长的时候，就会觉得幸福。”此话出自爱尔兰诗人，1923 年诺贝尔文学奖获得者 William Butler Yeats （1865-1939）。</p></li>
<li><p>要获得幸福感，一定要系统科学地寻找可持续的新增长点，尤其是财富，闲暇时间和知识的增长。</p></li>
<li><p>从信息输入成本和效率上看，当今世界上，再也没有比大量持续读书（总量要上千），读各个领域行业的书，读各种便携的电子书，成本更低，能够更快地识别陷阱，摆脱泥潭，寻找获取新增长点的方法了。<br>
从输出成本和效率上看，写作（包括写代码）是提高效率的一个好方法。第二个方法是一定要坚持构建自己的品牌。第三点是不断寻找新的渠道方法，增加自己的作品产品的可组合性。</p></li>
<li><p>效率的复合增长没有上限，幸福亦无上限。</p></li>
</ul>


<!-- -->

</section></section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Self Development</category>
  <category>Investment</category>
  <guid>https://learn.shitao5.org/posts/20240203-wcbd/</guid>
  <pubDate>Fri, 02 Feb 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240203-wcbd/cover.png" medium="image" type="image/png" height="102" width="144"/>
</item>
<item>
  <title>定投改变命运</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240123-dtgbmy/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Completed.🥳</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://ri.firesbox.com/#/cn/" class="uri">https://ri.firesbox.com/#/cn/</a></li>
</ul>
</div>
</div>
<section id="警告" class="level1 unnumbered"><h1 class="unnumbered">警告</h1>
<ul>
<li><p>金融领域是认知变现的最佳场所，可与此同时，也从来没有任何一个其他领域像金融领域那样，毫不留情地严厉惩罚缺乏正确独立思考能力的人。</p></li>
<li><p>千万不要误以为自己刚刚学到了一些新知识就可以马上变身超人 —— 消化知识所需要的时间远远超出大多数人的想象 —— 请您务必悠着点，千万不要急；最好别太猛，因为若是用力过猛，动作肯定会变形。</p></li>
</ul></section><section id="前言" class="level1 unnumbered"><h1 class="unnumbered">前言</h1>
<ul>
<li><p>解决最重要的问题会直接避免无数他人长期不断面临的问题。</p></li>
<li><p>因为最重要的问题从未被认真对待，于是这个问题就像种子发芽一样，地上长成了参天大树，地下盘根错节，衍生出无数的 “新” 问题…… 于是，我们能看到的情况是一模一样的，人们在地面上围着这盘根错节的 “问题之树”，想出了无数 “解决方案”，每天花大量的时间和精力做着徒劳无益的事情。</p></li>
<li><p>人生最惨烈的失败，就是获得了新的起点却误以为是终点而导致的失败。</p></li>
<li><p>在投资领域里，最重要的概念是什么呢？只有一个：<strong>长期</strong>。</p></li>
<li><p>希腊神话中有一个海岛上群居着美丽的海妖塞壬，她们那天籁般的歌喉和无以伦比的美貌会使所有过往的水手失去魂魄，进而会使航船触礁沉没。历史上只有两位英雄驾驶航船安全渡过。一位是俄耳浦斯，因为他会弹琴，他弹奏竖琴优美到竟然使海妖们为之倾倒的地步。另外一位是奥德修斯，他用白蜡封住了船员们的耳朵，并且命令船员把自己绑在了桅杆上，因为他也想听听传说中那海妖的迷人歌声，可他同时也知道自己无法抵御诱惑。</p></li>
<li><p>只要你稍加思索，就会发现定投策略不仅可以应用在投资领域之中，事实上，几乎所有人生中最重要的领域，无论是学习、工作、生活，都可以采用定投策略，也最好从一开始就采用定投策略。</p></li>
<li><p>从一开始就要解决最重要的问题，不要让它生根发芽，不要让它长成问题之树，而后对之愈发地束手无策 —— 这也许是人生最重要的智慧。君子以思患而豫防之（易·既济），极是。</p></li>
</ul></section><section id="定投策略" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 定投策略</h1>
<ul>
<li><p>定投策略之所以有效，核心机理在于这个策略符合现实世界的真实状况：短期来看，牛熊恨不得日日交替；中期来看（比如两三年之间），<strong>熊市就是比牛市长</strong>，并且长很多很多 —— 虽然长期（跨越很长时间，比如，十年、廿年、卅年、百年）来看，只能一直是牛市……</p></li>
<li>
<p>通过践行定投策略，你未来的利润本质上<strong>几乎全部</strong>来自于你所经历的<strong>漫长</strong>熊市！绝大多数交易市场中的投资者并不了解这个本质，这也是他们之中的绝大多数注定投资失败的最本质原因 —— 他们希望自己能在转瞬即逝的牛市里快速地赚到钱。一个令人沮丧的现象是，大多数在牛市里被吸引进市场的 “投资者” 注定会折戟而归，因为还没等他们反应过来，短暂的牛市已经结束了，漫长的熊市已经开始了…… 他们即无法忍受 “账面损失”，也没有任何办法 “降低均价”…… 与他们截然相反的是，定投策略采用者恰恰是在熊市里慢慢积聚能量的。</p>
<p>事实上，定投策略不仅仅适用于在交易市场里投资，它几乎适用于生活中任何一个重要的领域，无论是学习、工作还是家庭。所谓的终生学习或者终生成长，本质上就是采用定投策略 —— 你想想是不是如此？现实世界运转发展的本质都是类似的，如果能为一个人的学习与成长画一个“价格曲线”，你就会发现它和标准普尔指数的价格曲线差不多，虽然最终大幅上扬，但，在此之前很长很长的时间里，由总体涨幅并不大的各种形状的起起伏伏构成 —— 反正是同样的模式。也就是说，很多的时候，学习的结果显得还不如不学习呢！“熊市”总是很长，不是吗？这就解释了为什么最终只有少数人能够真正做到终生学习或者终生成长—— 道理是一模一样的，因为人们总是想在牛市里入场，快速赚钱，而后离开。</p>
</li>
<li><p>与绝大多数人不一样的是，李笑来对长期这个概念有一个相对清晰准确可用的定义：所谓长期，指的是两个大周期以上。</p></li>
<li><p>为什么要强调 “两个” 大周期以上呢？很多人误解了<strong>趋势</strong>，他们看到昨天价格比前天高，今天价格比昨天高，然后就以为看到了 “上涨趋势”，误以为明天的价格就会比今天的更高…… 事实上，趋势这个东西，短期之内是根本无法判断的 —— 甚至，在一个周期之内也是难以判断的：只有经过了<strong>两个大周期</strong>之后，我们才可能<strong>确切地</strong>知道这到底更可能是个上涨趋势呢还是更可能是个下降趋势呢？</p></li>
<li>
<p>现在我们可以稍加总结整理了：</p>
<ul>
<li><p>一个阶段性的上涨不叫趋势，一个阶段性的下跌也不叫趋势 —— 短期之内根本无法判断趋势；</p></li>
<li><p>一个阶段的下跌（B 阶段）加上一个阶段的上涨（A 阶段）才构成一个完整的大周期；</p></li>
<li><p>我们可以把每一次历史最高点当作一个大周期的 B 阶段的起点；</p></li>
<li><p>每一次历史新高只能靠滞后判断认清；</p></li>
<li><p>判断趋势需要至少两个大周期才有意义；</p></li>
<li><p>关于趋势的判断最多做到 “更可能”；</p></li>
<li><p>上涨趋势的结果通常是 “再创历史新高” —— 至于究竟有多高依然只能靠滞后判断；</p></li>
<li><p>所谓的长期持有，指的是持有两个大周期以上；换句话讲，“穿越至少两次牛熊”……</p></li>
</ul>
</li>
<li><p>对于经济周期的形成，有一个相对更容易理解的角度：经济周期的形成，本质上是参与经济的多方协作时而协调、时而不协调造成的。</p></li>
<li><p>信息的高速流动使得全球化协作更为连贯更为容易，因此，虽然危机依然会不断产生，但修复速度正在变得越来越快。</p></li>
<li><p>在李笑来眼里，所谓的长期并不是虚无缥缈的 “永远”，而是一个非常清晰准确可用的概念。在股票市场，未来的两个大周期大约是 10～15 年；在区块链数字交易市场，未来的两个大周期大约是 6～8 年 —— 无论是哪一个，都属于可期待的未来了罢？</p></li>
<li><p>只会消费不懂投资的人，很难摆脱原有的命运，因为他们只能靠出售自己的时间赚钱。可是，一个人能出售的时间是极为有限的，比人们一贯以为的少很多很多。</p></li>
<li><p>投资的本质就是用你的钱去帮你赚钱 —— 而钱这个东西，它是不休息的，它一年 365 天，每天 24 小时，在投资正确的前提下，它都在为你工作……</p></li>
<li><p>投资领域很少有 “中间状态”，要么是 1 要么是 0，资金有期限，风险就是 1，资金无期限，风险就是 0，根本就没有 0.2 或者 0.8。很多人并不理解这一点，所以才会有那么多人前仆后继地铤而走险不得善终 —— 全世界风险最高的职业就是韩国总统，紧随其后的就是给自己设置了刚兑责任的资金管理者。（所谓 “刚兑” 指的就是 “到期必须足额兑现”。）</p></li>
<li>
<p>把自己的一份时间出售一次以上，是一次个人商业模式的升级 —— 它是如此重要，乃至于没有这个升级的话，任何个体都难以摆脱日益增长的生活成本的束缚。你最初只需要照顾好自己，后来就要照顾好自己的配偶，再后来还要照顾好自己的子女甚至父母…… 绝大多数人最终都是被这些生活基本成本打败的。一个人所能赚到的钱，要超过这个日益增长直至平稳最终才有所下滑的成本线，剩下的钱才是能够用来践行定投策略的部分。不升级个人商业模式，很难有什么钱剩下。</p>
<p>总之，在李笑来看来，采用定投策略，是个人商业模式的三连胜（trifecta）式的升级：</p>
<ul>
<li><p>从一份时间只能出售一次升级到一份时间能出售很多次；</p></li>
<li><p>从只会用钱消费升级到会用钱赚钱 —— 也就是开始投资；</p></li>
<li><p>从只会用钱投资升级到不仅会用钱投资还会用时间投资……</p></li>
</ul>
<p>更为关键的是，定投策略本身系统化地降低了风险。</p>
</li>
<li><p>对于任何策略，我们都有无穷无尽的改良欲望 —— 谁不希望自己手里的工具更精良一些呢？有趣的是，<strong>任何对定投策略的改良都是徒劳</strong>。</p></li>
<li><p>虽然践行群里的成员们都听过课，我也在课上反复强调：对定投策略的任何改良都是徒劳。但还是有相当一部分人依然忍不住被自己的一个天真想法所驱动 —— 每次下跌的时候多买一点岂不是更好？首先，每次根据当前价格作出的决策，事实上依赖的是滞后判断；更为重要的是，他们忽略了更重要的事实：每次决策之后的价格走势究竟是上升还是下降抑或持平，依然是随机的独立事件，不受之前的数据影响。</p></li>
<li><p>对统计概率知识能否深刻把握，是最影响投资者决策正确性的 —— 可惜，有太多的人对这样的基础知识重视程度实在不够，并且在自己反复因此吃亏的情况下，全然不知道无知的代价竟然如此惨烈。对知识完整的人来说，看到这种现象会忍不住笑出声来：有些并不真正了解统计概率常识的人竟然会想尽一切办法去证明周一到周日之间究竟哪一天价格最便宜？</p></li>
<li><p>如果你仔细观察一下那些对 “事实上无效的技巧” 充满兴趣、充满好奇，并且总是忍不住去尝试各种 “雕虫小技” 的人，你就会发现，他们的出发点都是一样的，他们只能看到眼前，他们也恰恰因此不具备高瞻远瞩的能力。切记：一切与长期无关的细节都是鸡毛蒜皮。请认真思考并揣摩以下一句名言的深刻含义，它是投资教父，沃伦·巴菲特的老师本杰明·格雷厄姆说的：短期来看市场是<strong>投票机</strong>，长期来看它是<strong>称重机</strong>。</p></li>
</ul></section><section id="定投标的的选择" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> 定投标的的选择</h1>
<ul>
<li><p>有个非常简单直接粗暴有效的策略：<strong>盲从那些已经展现长期成功业绩的真正成功投资者的建议</strong>。“盲从” 听起来是非常可怕的，可问题在于，我们确实可以盲从那些已经展现长期成功业绩的真正成功投资者的建议 —— 请注意这里的限定词汇，“长期”。因为在投资领域，有一个非常神奇的现象：越是拥有长期成功经验的投资者越是开诚布公。</p></li>
<li><p>相对于选择，是否真的能够做到长期持有才是绝大多数人真正面临的最大问题。</p></li>
<li><p>一个策略的长期有效性，与策略本身的复杂程度全无关系，恰恰相反，只有简单的策略才可能真正长期践行；并且，一个策略的长期有效性，与使用者的聪明才智也没有任何因果关联 —— 决定一个投资策略最终长期有效的核心前提是，这个策略是否在很长一段时间里被不折不扣地长期执行？</p></li>
<li><p><strong>事实上，成功并没有秘密；就算有，那也应该叫 “公开的秘密”。</strong>一切通往成功的路径都是公开的，这个过程中所需的一切技巧和智慧也都是公开的，只不过，耐心地走很久，老实地对待每一个知识与见解，并彻头彻尾的执行，就是很少有人能做到的事情，少到什么地步呢？<strong>万众之中罕见其一</strong>。这些人是人群当中极为罕见的真正做到<strong>知行合一</strong>的人 —— 事实上，针对历史上各个领域之中所有知行合一的人提出的建议，我们都可以直接接受，并且也值得认真执行；从一开始就理解，那很好，照做就是，若是刚开始无法理解怎么办？<strong>盲从。</strong></p></li>
<li><p>大多数人明明是（短期）趋势投资者，因为他们显然是被牛市吸引进市场的！可是，一旦他们被随后熊市里下跌的价格套牢之后，他们就 “变” 成了价值投资者！</p></li>
<li><p>既然更看重长期的趋势，再加上原本就应该也只能以长期作为出发点，那么定投标的选择就只能采用不一样的办法。定投策略采用者相对于其它投资者多出了一个筛选依据：<strong>长期持续成长</strong>。</p></li>
<li><p>定投策略者只能选择长期持续成长的标的（当然增长越大越快越好）—— 仅仅这么一个看似简单的筛选标准，剔除了 99% 的可选项，因为，在这个标准下，严格意义上来讲，竟然没有任何一个单独的投资标的可以那么令人放心地入选 —— 无论它们现在看起来有多棒…… 仅仅因为所有的企业和项目都跟人一样：“长期来看，我们都会死掉。” —— 约翰·梅纳德·凯恩斯。</p></li>
<li><p>我个人非常认同孙正义的见解，在未来的相当长一段时间里，人工智能就很可能是发展最快的行业。只不过，我也有一些稍微不一样的看法，比如，我认定另外一件事情：算法再好，也需要数据喂养。现在手中掌握大量持续增长的用户数据的上市公司，都已经有足够的盈利能力。如果将来算法是大树的话，那么他们手中正在不断增长的数据就是最肥沃的土壤。没有土壤的话，大树是长不出来的。绝大多数算法公司到最后都会为拥有数据的大公司所用……</p></li>
<li><p>那能不能再进一步，去探寻 “我能不能在这个我觉得发展会最快的行业里再进一步选择一个发展最快的企业呢”？我觉得还是算了吧，因为那样的话，你就相当于直接退回到了最初那个最危险的状态 —— 这就是所谓的物极必反。宏观观察的核心技巧之一非常简单，就是 “不要走到极限”，理由只不过是我们不仅讨厌风险，我们更讨厌系统性风险。</p></li>
<li><p>与很多人以为的恰恰相反，事实上，<strong>哪里有泡沫，哪里就可能有机会</strong> —— 至于是否真的有机会，要看那个产生泡沫的事物有没有长期可持续的价值与增长。如果没有，那就是单纯的泡沫；如果有，那么，那就是机会 —— 并且，按照惯例，后面可能还会有若干次泡沫，直至价值终于全然展现。</p></li>
<li><p>我在判断一个趋势是否 “已然成立” 有个非常简单直接粗暴有效的分辨方式：不是看大多数人是否都已经接受，而是看是否大多数人都无法否认。—— 可以用三个字概括：“皆难否”。皆难否是一个趋势已然确立的重要标志。理解不理解并不重要，接受不接受也不重要，重要的是，全部都无法否认，那么，这个趋势已然 “基本上挤干了泡沫” —— 这是定投者最佳入场时机的最佳判断依据。</p></li>
</ul></section><section id="定投策略执行过程" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> 定投策略执行过程</h1>
<ul>
<li><p>对策就是不动，正所谓 “<strong>无为而治</strong>” —— 千万不要低估 “无为” 的力量，除了交易市场之外，真的很难再找出另外一个地方可以让我们如此直观地感受无为的力量了。</p></li>
<li><p>有成本的钱，会导致任何一个原本不错的投资变成坟墓。最普遍的例子是人们向银行贷款买房。很多的时候，房产本来是个比较不错的投资标的 —— 如果你已经有足够多的钱所以你不用向银行贷款的话。可问题在于 99% 的人都没有能力一下子购入那么大的一个资产，于是，银行的赚钱机会来了 —— 注意，房产实际上并不是民众的赚钱机会。他们雇佣最牛的精算师，设计了一个对他们百利而无一害的计划，让民众们花二三十年的时间用两套房子的价格买一套房子…… 为什么总是 “两倍”？为什么全球银行给出来的计划都差不多？因为那是精算的结果，反正，人们每买一套房银行就赚一套房（的钱）！房产是流动性非常差的资产 —— 主要原因来自于绝大多数人买来房子是用来住的，卖掉了就没地方住了 —— 所以，那房价看起来总是在上涨…… 可问题在于，房产的价格是不可能永远上涨的， 一旦房价暴跌（比如，未来 30 年中的某一年跌掉 25%），那么 “投资” 就成了 “上吊绳”。</p></li>
<li><p>有成本的钱是很可怕的，可那只不过是小鬼而已，有使用期限的钱更可怕，干脆就是死神。</p></li>
<li>
<p>你把你的钱想象成一个熟鸡蛋的结构：</p>
<ul>
<li><p>蛋黄的部分，就是你的日常必需开销；</p></li>
<li><p>蛋白的部分，就是你为了抵御风险而准备的储蓄；</p></li>
<li><p>蛋壳的部分，才是你可以用来投资的钱，它可以在未来两个大周期之内绝不离开市场……</p></li>
</ul>
<p>很大一部分人的投资失败，并不是因为智商、信心、毅力之类的问题，而是因为早期彻底低估了生活中可能遇到的那些大意外的成本 —— 也就是说，没想到蛋白的部分竟然那么厚。比如，自己的牙突然坏了，某位重要的亲属得了绝症，自己不小心出了个车祸，孩子不小心惹了什么很贵的麻烦…… 例子举也举不完。反正，意外有很多很多面具，每张面具都有一张血盆大口。</p>
</li>
<li><p>所有投资人都一样，进入市场一小段时间之后就会有深刻体会：<strong>每次你想要卖出投资标的换取现金的时候市场价格就会下跌……</strong>为什么会出现这么违背直觉的现象呢？首先当然是因为交易市场里熊市就是比牛市长很多；与此同时，每当你急需花钱的时候，基本上都是市场外赚钱比较难的时候，市场外赚钱比较难的时候，市场内的价格自然是处于下跌状态的。还有另外一个原因在起作用：当市场内价格上涨的时候，你出售投资标的的意愿更低 —— 在那样的时候，越是长期持有者越是没有消费欲望…… 于是，最大的损失总是来自于 “不得不出售投资标的” 的情况。回过头来，现在的你一定更深入理解了为什么这个你听过无数遍的建议那么重要：投资只能用<strong>闲钱</strong>。定投者用来投资的钱，不应该有成本，更不应该有期限；它必须是能够陪你穿越至少两次牛熊（或者说跨越两个大周期）的钱…… 不仅如此，还要有足够的备用金去应对可能的意外。</p></li>
<li><p>事实上，只要你肯认真观察，你就会发现同样的结论：<strong>在任何企业，销售部门的个体收入总是相对更高……</strong>除了销售很重要之外，还有另外一个隐秘的原因：销售工作是最容易被量化的，所以它最可能附带绩效收入。</p></li>
<li><p>事实上，人人都应该注重自己的销售能力。因为成功销售的核心就是生活中最为重要的一个关键：有效沟通。哪一次成功的销售不是有效的沟通呢？小时候，你能让同桌向老师保守秘密其实就是你的成功销售，长大之后，你能让一位异性对你信任有加还是成功销售，到了工作岗位你能升职加薪事实上又是成功销售…… 销售能力基本上是万能的。</p></li>
<li>
<p>销售的核心是什么？<strong>信任</strong>。千万不要误以为销售是靠忽悠的 —— 这么想的人都是缺乏长期思考能力的人。短暂的信任也许可以通过欺骗获取，长期的信任只能靠时间慢慢积累。信任的价值之所以那么高，是因为它非常脆弱，稍有不慎就前功尽弃。沃伦·巴菲特的理解是这样的：<strong>建立信用需要 20 年的时间，可摧毁它大约只需要 5 分钟。想到这些，你做事就不一样了……</strong></p>
<p>客户肯买你卖的房子、你卖的车子、你卖的课程、你卖的保险，除了销售标的真的值得购买之外，还基于客户对你的信任。本质上来看，信任远比销售标的本身更为重要。没有信任作为前提，就干脆不会有任何销售产生。反过来，信任是如此重要，所以那些优秀的销售绝对不愿销售不好的标的 —— 他们会常常自问，我自己会买这个东西吗？我会把它卖给家人吗？我会把它卖给我那些交往了许多年的朋友吗？缺乏长期观念的人，看到这样的描述，是完全没办法相信的，他们总以为这是很虚伪的态度，可事实上，这几个小问题就是那些长期业绩优秀的销售非常认真对待的问题，他们也恰恰受益于这种基于长期思考的认真。</p>
</li>
<li><p>被合作性能差的根本原因其实只有一个：那就是你没有能力把自己该做好的事情做到最好。个性太强脾气太差等等，根本就不是他人难以与你合作的原因。若是属于你应该做的那一部分你就是能够做到最好，那么，你脾气再差，你个性再强，人家也要硬着头皮与你合作 —— 合作的负担就这样转移到了对方身上。</p></li>
<li><p>你得拥有特定的能力，乃至于他人有与你合作的欲望。当你尝试着与他人合作，对方却没有合作意愿的时候，更可能的原因是因为你并没有什么足够的、特定的能力引发对方的合作欲望，而不是对方不识货。很多人要过了三十岁之后才发现自己其实一无所长，这就很可悲。在这个阶段什么最重要呢？最正确的答案再一次说出来都好像是废话：老实。一无是处的人都一样，哪儿哪儿都不老实。他们对别人不老实，总是在关键的时候使用伪装蒙混过关；他们对自己同样不够老实，所以他们的伪装甚至用来欺骗自己；他们对知识对学习不老实，所以总是并不完全相信知识的作用，也因此在学习的时候总是错过无数细节且全然不自知…… 所有这一切的不老实，直接造成了一个最严重的缺陷 —— 他们不可能具备长期视角和宏观观察能力，因为他们总是不由自主地把自己的全部注意力放到了眼前的得失和投机取巧之上。</p></li>
<li><p>我们这一生所遇到的最重要的东西都没有说明书，结婚的时候没有人能给我们一个清晰明了的婚姻说明书；生孩子的时候也没有人能给我们一个养儿育女说明书；当然，当初我们出生的时候，不仅我们的父母没有子女说明书，直到我们长大成人，父母和我们一样，依然没有人生说明书……</p></li>
<li><p>人类之所以与其他动物不一样，最重要的方面就在于人类有语言和文字，所以人类在出生的时候事实上并不是从零开始 —— 因为只要习得了文字，只要开始阅读，那就相当于 “已经站在了巨人肩膀之上”。但是，为什么明明大家都可以站到巨人肩膀之上，可最终绝大多数人都活在巨人脚趾之下呢？最佳解释就是，绝大多数人在起初的时候过早放弃了事实上是最佳的策略：<strong>盲从</strong> —— 这是我们在第二部分第一节中曾经深入展开过的话题。过早独立思考虽然也许是好事，但更可能是坏事 —— 因为独立思考本身并没有多少价值，建立在见多识广上的独立思考才真正有效，可问题在于早期的时候就是见识少啊！<strong>井底之蛙再怎么独立思考都只能是坐井观天</strong>。</p></li>
<li><p>看他人犯错，看他人付出真金白银的代价，看他人用他们自己宝贵的生命去做验证，虽然看起来颇有些讨巧，可它偏偏却是提高见识的最佳途径，没有任何一个其他途径可以使你变得更加 “见多识广”。很多年来，我最喜欢的消遣之一，就是在各种在线聊天室或者在线论坛上看那些陌生人发表见解，我会做很多笔记，时不时拿出来看，对我的进步有着不可或缺的巨大的帮助。</p></li>
<li><p>事实上，场外赚钱能力才是检验一个人是否真的进步的最靠谱方式，因为在场外，你没有趋势加持。场内是拼交通工具的地方，场外是拼脚力的地方。</p></li>
<li><p>2022 年，新东方经历了一个超级危机。中国大陆的 “双减政策” 导致校外培训全面取缔，新东方收入锐减…… 幸亏俞敏洪的现金储备策略，新东方成了几乎唯一一个 “不必破产” 的培训机构。随后转型成功，“东方甄选” 又一次为新东方注入了新鲜活力 —— 人们再一次意识到，有韧性的企业家的确并不常见，因为 “韧性” 不仅仅是性格，它还需要实力支撑。</p></li>
<li>
<p>到了这个阶段，很可能有一样东西让你无法平静 ——那就是你依然尚未找到值得你持续努力的目标。想象一下，你已然拥有了很多财富，却尚未找到人生的意义，那有多可怕？我个人最大的幸运在于，即便是在我的鸡蛋清都没准备好的情况下，我就已经有了值得终身去做的事情：学习与成长 —— 事实上，很多记者在采访我的时候都用奇怪的眼神直白地表达过他们的难以置信。然而，请你理解一个清楚地了解自己天份原本不佳的人通过长期持续的学习获得不断进步之时他所能感受到的那种激动和幸福。</p>
<p>许多年前，我就发现一个简单的道理：<strong>教是最好的学习方法</strong>。</p>
<p>于是，我喜欢做教育，迄今为止，我已经 “一不小心” 从事了二十年的教育工作 —— 教人考试，教人写作，教人创业，教人投资…… 教育，就是我至死都能做，且极其乐于做的事情，了不起换个领域继续教下去，因为反正我要继续学下去，就这么简单。根据我的体会，<strong>找到值得自己终生去做的事情，是一个人最好的护身符</strong>。</p>
</li>
</ul></section><section id="客观客观更加客观" class="level1" data-number="4"><h1 data-number="4">
<span class="header-section-number">4</span> 客观客观更加客观</h1>
<ul>
<li><p>无数研究证明，若是一个人的某种情绪功能受损，那么他的决策能力就会随之受损。更为重要的是，一切的情绪，都是人们之间最佳、最直接的沟通手段，而人，也正是因为如此才是社交动物；反过来，也正是因为社交的刚需才发展出更为完善的情绪功能。</p></li>
<li><p>知道与做到之间的距离那么长，还有另外一个更为隐秘的原因：之前决策的时候，必然缺乏的是之后的丰富经验。</p></li>
<li><p>人生之中，所有真正重要的活动都属于这种：“无论如何都要开始做、同时也只能边做边学”。</p></li>
<li><p>通过我们自身以及自身行为能够影响的现实终归有一个边界，在这个边界之内，我们可以通过努力不断进取，但是，在这个边界之外，我们事实上就是无能为力。如若不能清醒地意识到这个边界的存在，那么，一个人将始终生活在混乱之中，痛苦不堪。</p></li>
</ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Finance</category>
  <category>Investment</category>
  <guid>https://learn.shitao5.org/posts/20240123-dtgbmy/</guid>
  <pubDate>Mon, 22 Jan 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240123-dtgbmy/cover.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>平面设计中的网格系统</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240121-grid-systems/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Paused. Current progress 27.07%.⏱</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/26806997/" class="uri">https://book.douban.com/subject/26806997/</a></li>
</ul>
</div>
</div>
<section id="前言" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 前言</h1>
<ul>
<li><p>
如我们所知，网格作为一种控制形式的法则，仍然还有许多可以发展的空间。但针对网格需要做的第一步，就是在排版中尽可能地利用版面中的资源来达到秩序和经济的最大可能性。
</p></li>
</ul></section><section id="关于本书" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> 关于本书</h1>
<ul>
<li><p>
只要不嫌麻烦、任何研究网络的人都会发现，在网格系统的帮助下，他都能更快地解决设计中的问题，并让设计更具功能性、逻辑性和视觉美感。
</p></li>
</ul></section><section id="网格与设计哲学" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> 网格与设计哲学</h1>
<ul>
<li>
<p>设计师的作品应该是易懂的、客观的、功能性的和具有数学逻辑美感的。这样，设计师的创作才能对主流文化产生价值，并成为主流文化的一部分。</p>
<p>具有建设性的、可供分析和理解的设计作品不仅可以提高社会的审美品位，还可以对其造型文化和色彩文化产生影响。具有客观性的设计作品符合公众利益，并且能够很好地构成民主行为的基础。用构成化、系统化的手段来进行设计，也意味着将设计法则转化为实际的解决方案。具有系统性并严格遵循原则的设计，需要直接明了、清晰易懂以及各种因素的集成，这些在社会政治生活中也是具有极为重要的意义的。</p>
</li>
<li><p>我们需要认识到教育的意义，并带着创造性和建设性的精神去工作。还应该明白没意见视觉创意作品不仅是设计师个性的彰显，更是他的知识、能力和情感的综合体现。</p></li>
</ul></section><section id="编排设计中的网格" class="level1" data-number="4"><h1 data-number="4">
<span class="header-section-number">4</span> 编排设计中的网格</h1>
<ul>
<li><p>有一个规则是：插图在尺寸上的差别越小，设计就越能创造出一种平和感。作为一种控制系统，网格系统提供了一种更为简单的方式来理性地组织二维和三维空间。</p></li>
<li>
<p>总之，一个合适的网格之所以可以使设觉设计变得更容易。是因为：</p>
<ol type="1">
<li><p>可以通过视觉传达的手段客观地建构主题；</p></li>
<li><p>可以系统和逻辑地构建文本和插图类材料；</p></li>
<li><p>可以在一个紧凑的空间中根据文本和插图的特点建立节奏关系；</p></li>
<li><p>可以将所有设觉材料组织在一起，使其在易读易懂的同时还具备视觉张力。</p></li>
</ol>
</li>
</ul></section><section id="网格的目的是什么" class="level1" data-number="5"><h1 data-number="5">
<span class="header-section-number">5</span> 网格的目的是什么？</h1>
<ul>
<li><p>
在编排设计中，清晰、逻辑地呈现标题、副标题、文本、插图和图注等信息，不仅可以使阅读变得更快速和更容易，还可以让信息更容易被理解和记忆。这是一个被科学验证的真理，每个设计师都应铭记于心。&lt;&gt;</p></li>
</ul></section><section id="纸张的尺寸" class="level1" data-number="6"><h1 data-number="6">
<span class="header-section-number">6</span> 纸张的尺寸</h1>
<ul>
<li><p>标准尺寸的印刷品源自 A、B、C、D 四种系列。</p></li>
<li><p>A 型纸是其他集中纸张型号的基础，B 型纸是纸张未裁切的尺寸，C 型纸是转为 A 型纸定制的信封尺寸。C 型纸和 D 型纸也被成为附加纸张型号。</p></li>
<li><p>A 型纸印刷品可以放进用 C 型纸印刷的信封中。C 型纸的信封可以放进用 B 型纸印刷的包装中。</p></li>
</ul></section><section id="排版中的度量系统" class="level1" data-number="7"><h1 data-number="7">
<span class="header-section-number">7</span> 排版中的度量系统</h1>
<ul>
<li><p>
在一个字体家族中通常会有窄体（condensed）、中等体（medium）、宽体（expanded）、特窄体（extra-condensed）、特宽体（extra-expanded）。但一般来说，中等体都是最易阅读的字体。
</p></li>
</ul></section><section id="字体样式" class="level1" data-number="8"><h1 data-number="8">
<span class="header-section-number">8</span> 字体样式</h1>
<ul>
<li><p>“无衬线”这一名称是因为这类字体除去了字母起步和收笔处的装饰“衬线”。</p></li>
<li><p>Times New Roman 是在 1923 年专为《泰晤士报》（The Times）的印刷而设计的。这款字体即使被印刷在粗糙的纸张上，也能保持高度的易认性，因为其字母具有短小、有力而尖锐的衬线。无论大小写字母都显得非常清晰。</p></li>
</ul></section><section id="栏的宽度" class="level1" data-number="9"><h1 data-number="9">
<span class="header-section-number">9</span> 栏的宽度</h1>
<ul>
<li>当使用大字号的字体排版时，必须注意不要把版面的页边距设置得太窄。无论在什么情况下，都应在字体与版面的边缘之间保留一定的距离。因为如果两者太贴近的话，就会影响到版面的整体设计。</li>
</ul></section><section id="行距" class="level1" data-number="10"><h1 data-number="10">
<span class="header-section-number">10</span> 行距</h1>
<ul>
<li>
<p>行距太窄就会削弱阅读的速度，因为读者会通过眼睛同时接收上下两行的文本信息，而眼睛又无法精确地对焦在过分接近的两行之上，所以每一行文本周围都应该预留一定的视觉区域。如果读者的视觉焦点无法集中，那么他们的注意力就会浪费在错误的地方，阅读起来也会更容易产生疲劳感。</p>
<p>同样的道理，行距也不能设置得太宽。因为过宽的行距会让读者很难把文本中的上下两行联系起来，并让人产生不确定性和疲劳感。一个适当的行距能引导读者的视觉从一行自然地移动到另一行，并在阅读的过程中建立信心和稳定性，这都会让文本自身更易被读者吸收和记忆。当阅读变得更顺畅和简单时，文中的内容也自然能被读者更清晰地掌握，同时还能传达出文本的表情与品质，在脑中留下更深刻的印象。</p>
</li>
<li><p>相对来说，大段的文本不仅需要有较宽的行距，还需要利用段落来进行区分。在视觉上，段莉可以通过在段落之间空行，或者在首行缩进，或者利用首字母和小型大写字母等方式来区分。</p></li>
</ul></section><section id="页边距" class="level1" data-number="11"><h1 data-number="11">
<span class="header-section-number">11</span> 页边距</h1>
<ul>
<li><p>页边距的设置一方面受制于技术，因为书籍在装订时会有 1 到 3mm 左右的外边被误裁掉。通常，我们都会为页面留有 5mm 的出血位置来平衡这种误差。所以，如果页边距设置不当，就会因裁切误差导致文本残缺不全。另一方面，页边距的设置也有审美的因素，因为比例协调的页边距可以提高读者阅读时的愉悦感。几个世纪以来，所有经典的排版作品都有着一个完美的页边距，它们都是通过黄金分割或者一些数学公式精确计算出来的。</p></li>
<li><p>对于画册来说，如果版面中的图片需要整版呈现的话，建议可以不设置页边距，也可以对页中采用撑满整个版面的形式。通常来说，这类出血的图片版面会与有页边距的版面混合使用。如果这些版面配合恰当，那么设计会显得十分大气。</p></li>
</ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Design</category>
  <category>Art</category>
  <guid>https://learn.shitao5.org/posts/20240121-grid-systems/</guid>
  <pubDate>Sat, 20 Jan 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240121-grid-systems/cover.png" medium="image" type="image/png" height="92" width="144"/>
</item>
<item>
  <title>Mastering Shiny</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240119-mastering-shiny/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Completed.🎉</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://mastering-shiny.org/" class="uri">https://mastering-shiny.org/</a></li>
<li><a href="https://rstudio.github.io/cheatsheets/html/shiny.html" class="uri">https://rstudio.github.io/cheatsheets/html/shiny.html</a></li>
</ul>
</div>
</div>
<section id="getting-started" class="level1 unnumbered"><h1 class="unnumbered">Getting started</h1>
</section><section id="your-first-shiny-app" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> Your first Shiny app</h1>
<ul>
<li><p>You can enter that URL into any compatible web browser to open another copy of your app.</p></li>
<li><p>Layout functions, inputs, and outputs have different uses, but they are fundamentally the same under the covers: they’re all just fancy ways to generate HTML, and if you call any of them outside of a Shiny app, you’ll see HTML printed out at the console. Don’t be afraid to poke around to see how these various layouts and controls work under the hood.</p></li>
<li><p>The essence of reactivity: outputs automatically react (recalculate) when their inputs change.</p></li>
<li><p>In every kind of programming, it’s poor practice to have duplicated code; it can be computationally wasteful, and more importantly, it increases the difficulty of maintaining or debugging the code.</p></li>
<li><p>You create a reactive expression by wrapping a block of code in <code>reactive({...})</code> and assigning it to a variable, and you use a reactive expression by calling it like a function. But while it looks like you’re calling a function, a reactive expression has an important difference: it only runs the first time it is called and then it caches its result until it needs to be updated.</p></li>
</ul></section><section id="basic-ui" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> Basic UI</h1>
<ul>
<li><p>Generally, I recommend only using sliders for small ranges, or cases where the precise value is not so important. Attempting to precisely select a number on a small slider is an exercise in frustration!</p></li>
<li><p>By default, <code><a href="https://rdrr.io/pkg/shiny/man/plotOutput.html">plotOutput()</a></code> will take up the full width of its container (more on that shortly), and will be 400 pixels high. You can override these defaults with the <code>height</code> and <code>width</code> arguments. We recommend always setting <code>res = 96</code> as that will make your Shiny plots match what you see in RStudio as closely as possible.</p></li>
</ul></section><section id="basic-reactivity" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> Basic reactivity</h1>
<ul>
<li><p>The key idea of reactive programming is to specify a graph of dependencies so that when an input changes, all related outputs are automatically updated.</p></li>
<li>
<p>The <code>ui</code> is simple because every user gets the same HTML. The <code>server</code> is more complicated because every user needs to get an independent version of the app; when user A moves a slider, user B shouldn’t see their outputs change.</p>
<p>To achieve this independence, Shiny invokes your <code>server()</code> function each time a new session starts. Just like any other R function, when the server function is called it creates a new local environment that is independent of every other invocation of the function. This allows each session to have a unique state, as well as isolating the variables created inside the function. This is why almost all of the reactive programming you’ll do in Shiny will be inside the server function.</p>
</li>
<li><p>Unlike a typical list, <code>input</code> objects are read-only. If you attempt to modify an input inside the server function, you’ll get an error.</p></li>
<li><p>One more important thing about <code>input</code>: it’s selective about who is allowed to read it. To read from an <code>input</code>, you must be in a <strong>reactive context</strong> created by a function like <code><a href="https://rdrr.io/pkg/shiny/man/renderPrint.html">renderText()</a></code> or <code><a href="https://rdrr.io/pkg/shiny/man/reactive.html">reactive()</a></code>. It’s an important constraint that allows outputs to automatically update when an input changes.</p></li>
<li><p>It’s important to understand that the order your code run is solely determined by the reactive graph. This is different from most R code where the execution order is determined by the order of lines.</p></li>
<li><p>In Shiny, however, I think you should consider the rule of one: whenever you copy and paste something <em>once</em>, you should consider extracting the repeated code out into a reactive expression. The rule is stricter for Shiny because reactive expressions don’t just make it easier for humans to understand the code, they also improve Shiny’s ability to efficiently rerun code.</p></li>
</ul></section><section id="shiny-in-action" class="level1 unnumbered"><h1 class="unnumbered">Shiny in action</h1>
</section><section id="workflow" class="level1" data-number="4"><h1 data-number="4">
<span class="header-section-number">4</span> Workflow</h1>
<ul>
<li><p>Improving workflow is a good place to invest time because it tends to pay great dividends in the long run. It doesn’t just increase the proportion of your time spent writing R code, but because you see the results more quickly, it makes the process of writing Shiny apps more enjoyable, and helps your skills improve more quickly.</p></li>
<li>
<p>The basic idea of print debugging is to call <code><a href="https://rdrr.io/r/base/print.html">print()</a></code> whenever you need to understand when a part of your code is evaluated, and to show the values of important variables. We call this “print” debugging (because in most languages you’d use a print function), but In R it makes more sense to use <code><a href="https://rdrr.io/r/base/message.html">message()</a></code> :</p>
<ul>
<li><p><code><a href="https://rdrr.io/r/base/print.html">print()</a></code> is designed for displaying vectors of data so it puts quotes around strings and starts the first line with <code>[1]</code>.</p></li>
<li><p><code><a href="https://rdrr.io/r/base/message.html">message()</a></code> sends its result to “standard error”, rather than “standard output”. These are technical terms describing output streams, which you don’t normally notice because they’re both displayed in the same way when running interactively. But if your app is hosted elsewhere, then output sent to “standard error” will be recorded in the logs.</p></li>
</ul>
</li>
</ul></section><section id="layout-themes-html" class="level1" data-number="5"><h1 data-number="5">
<span class="header-section-number">5</span> Layout, themes, HTML</h1>
</section><section id="graphics" class="level1" data-number="6"><h1 data-number="6">
<span class="header-section-number">6</span> Graphics</h1>
<ul>
<li><p>
For hosted apps, you also have to take into account the time needed to transmit the event from the browser to R, and then the rendered plot back from R to the browser.
</p></li>
</ul></section><section id="user-feedback" class="level1" data-number="7"><h1 data-number="7">
<span class="header-section-number">7</span> User feedback</h1>
<ul>
<li><p>An even simpler alternative is to use the <a href="https://github.com/daattali/shinycssloaders">shinycssloaders</a> package by Dean Attali. It uses JavaScript to listen to Shiny events, so it doesn’t even need any code on the server side. Instead, you just use <code><a href="https://rdrr.io/pkg/shinycssloaders/man/withSpinner.html">shinycssloaders::withSpinner()</a></code> to wrap outputs that you want to automatically get a spinner when they have been invalidated.</p></li>
<li>
<p>There are a few small, but important, details to consider when creating a dialog box:</p>
<ul>
<li><p>What should you call the buttons? It’s best to be descriptive, so avoid yes/no or continue/cancel in favour of recapitulating the key verb.</p></li>
<li><p>How should you order the buttons? Do you put cancel first (like the Mac), or continue first (like Windows)? Your best option is to mirror the platform that you think most people will be using.</p></li>
<li><p>Can you make the dangerous option more obvious? Here I’ve used <code>class = "btn btn-danger"</code> to style the button prominently.</p></li>
</ul>
</li>
</ul></section><section id="uploads-and-downloads" class="level1" data-number="8"><h1 data-number="8">
<span class="header-section-number">8</span> Uploads and downloads</h1>
<ul>
<li><p>By default, the user can only upload files up to 5 MB. You can increase this limit by setting the <code>shiny.maxRequestSize</code> option prior to starting Shiny. For example, to allow up to 10 MB run <code>options(shiny.maxRequestSize = 10 * 1024^2)</code>.</p></li>
<li><p>I recommend using <code>.tsv</code> (tab separated value) instead of <code>.csv</code> (comma separated values) because many European countries use commas to separate the whole and fractional parts of a number (e.g.&nbsp;<code>1,23</code> vs <code>1.23</code>). This means `they can’t use commas to separate fields and instead use semi-colons in so-called “c”sv files! You can avoid this complexity by using tab separated files, which work the same way everywhere.</p></li>
<li>
<p>By default, RMarkdown will render the report in the current process, which means that it will inherit many settings from the Shiny app (like loaded packages, options, etc). For greater robustness, I recommend running <code>render()</code> in a separate R session using the callr package:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">render_report</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">params</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rmarkdown</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://pkgs.rstudio.com/rmarkdown/reference/render.html">render</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>,</span>
<span>    output_file <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span>,</span>
<span>    params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">params</span>,</span>
<span>    envir <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/environment.html">new.env</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>parent <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/environment.html">globalenv</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">server</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">report</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">downloadHandler</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>    filename <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"report.html"</span>,</span>
<span>    content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">file</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>      <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">params</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">slider</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">callr</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://callr.r-lib.org/reference/r.html">r</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>        <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">render_report</span>,</span>
<span>        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">report_path</span>, output <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">file</span>, params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">params</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
</div>
</li>
</ul></section><section id="dynamic-ui" class="level1" data-number="9"><h1 data-number="9">
<span class="header-section-number">9</span> Dynamic UI</h1>
<ul>
<li>
<p>There are three key techniques for creating dynamic user interfaces:</p>
<ul>
<li><p>Using the <code>update</code> family of functions to modify parameters of input controls.</p></li>
<li><p>Using <code><a href="https://rdrr.io/pkg/shiny/man/tabsetPanel.html">tabsetPanel()</a></code> to conditionally show and hide parts of the user interface.</p></li>
<li><p>Using <code><a href="https://rdrr.io/pkg/shiny/man/htmlOutput.html">uiOutput()</a></code> and <code><a href="https://rdrr.io/pkg/shiny/man/renderUI.html">renderUI()</a></code> to generate selected parts of the user interface with code.</p></li>
</ul>
</li>
<li><p>You might wonder when you should use <code><a href="https://rdrr.io/pkg/shiny/man/freezeReactiveValue.html">freezeReactiveValue()</a></code>: it’s actually good practice to <strong>always</strong> use it when you dynamically change an input <code>value</code>. The actual modification takes some time to flow to the browser then back to Shiny, and in the interim any reads of the value are at best wasted, and at worst lead to errors. Use <code><a href="https://rdrr.io/pkg/shiny/man/freezeReactiveValue.html">freezeReactiveValue()</a></code> to tell all downstream calculations that an input value is stale and they should save their effort until it’s useful.</p></li>
<li>
<p>If you run this code yourself, you’ll notice that it takes a fraction of a second to appear after the app loads. That’s because it’s reactive: the app must load, trigger a reactive event, which calls the server function, yielding HTML to insert into the page. This is one of the downsides of <code><a href="https://rdrr.io/pkg/shiny/man/renderUI.html">renderUI()</a></code>; relying on it too much can create a laggy UI. For good performance, strive to keep fixed as much of the user interface as possible, using the techniques described earlier in the chapter.</p>
<p>There’s one other problem with this approach: when you change controls, you lose the currently selected value. Maintaining existing state is one of the big challenges of creating UI with code. This is one reason that selectively showing and hiding UI is a better approach if it works for you — because you’re not destroying and recreating the controls, you don’t need to do anything to preserve the values. However, in many cases, we can fix the problem by setting the value of the new input to the current <code>value</code> of the existing control:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">server</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">session</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">numeric</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">renderUI</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">value</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">isolate</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">dynamic</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">type</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slider"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sliderInput</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dynamic"</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">label</span>, value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">value</span>, min <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numericInput</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dynamic"</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">label</span>, value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">value</span>, min <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
</div>
</li>
</ul></section><section id="bookmarking" class="level1" data-number="10"><h1 data-number="10">
<span class="header-section-number">10</span> Bookmarking</h1>
<ul>
<li><p>By default, Shiny apps have one major drawback compared to most web sites: you can’t bookmark the app to return to the same place in the future or share your work with someone else with a link in an email. That’s because, by default, Shiny does not expose the current state of the app in its URL.</p></li>
<li>
<p>There are three things we need to do to make this app bookmarkable:</p>
<ol type="1">
<li><p>Add a <code><a href="https://rdrr.io/pkg/shiny/man/bookmarkButton.html">bookmarkButton()</a></code> to the UI. This generates a button that the user clicks to generate the bookmarkable URL.</p></li>
<li><p>Turn <code>ui</code> into a function. You need to do this because bookmarked apps have to replay the bookmarked values: effectively, Shiny modifies the default <code>value</code> for each input control. This means there’s no longer a single static UI but multiple possible UIs that depend on parameters in the URL; i.e.&nbsp;it has to be a function.</p></li>
<li><p>Add <code>enableBookmarking = "url"</code> to the <code><a href="https://rdrr.io/pkg/shiny/man/shinyApp.html">shinyApp()</a></code> call.</p></li>
</ol>
</li>
<li>
<p>Instead of providing an explicit button, another option is to automatically update the URL in the browser. This allows your users to use the user bookmark command in their browser, or copy and paste the URL from the location bar.</p>
<p>Automatically updating the URL requires a little boilerplate in the server function:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Automatically bookmark every time an input changes</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">observe</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reactiveValuesToList</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">session</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">doBookmark</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Update the query string</span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">onBookmarked</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">updateQueryString</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
</li>
</ul></section><section id="tidy-evaluation" class="level1" data-number="11"><h1 data-number="11">
<span class="header-section-number">11</span> Tidy evaluation</h1>
<ul>
<li>
<p>It’s going to be easier to understand what’s happening if we can disambiguate the two uses by introducing two new terms:</p>
<ul>
<li><p>An <strong>env-variable</strong> (environment variable) is a “programming” variables that you create with <code>&lt;-</code>. <code>input$var</code> is a env-variable.</p></li>
<li><p>A <strong>data-variable</strong> (data frame variables) is “statistical” variable that lives inside a data frame. <code>carat</code> is a data-variable.</p></li>
</ul>
<p>With these new terms we can make the problem of indirection more clear: we have a data-variable (<code>carat</code>) stored inside an env-variable (<code>input$var</code>), and we need some way to tell dplyr this. There are two slightly different ways to do this depending on whether the function you’re working with is a “data-masking” function or a “tidy-selection” function.</p>
</li>
<li><p>Data-masking functions allow you to use variables in the “current” data frame without any extra syntax. It’s used in many dplyr functions like <code>arrange()</code>, <code><a href="https://rdrr.io/r/stats/filter.html">filter()</a></code>, <code>group_by()</code>, <code>mutate()</code>, and <code>summarise()</code>, and in ggplot2’s <code>aes()</code>. Data-masking is useful because it lets you use data-variables without any additional syntax.</p></li>
<li>
<p>Fortunately, inside data-masking functions you can use <code>.data</code> or <code>.env</code> if you want to be explicit about whether you’re talking about a data-variable or an env-variable:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">diamonds</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/stats/filter.html">filter</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">.data</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[[</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">var</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">.env</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">min</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
</li>
<li><p>However, in my opinion, one of the advantages of the tidyverse is the careful thought that has been applied to edge cases so that functions work more consistently.</p></li>
<li><p>As well as data-masking, there’s one other important part of tidy evaluation: tidy-selection. Tidy-selection provides a concise way of selecting columns by position, name, or type. It’s used in <code><a href="https://dplyr.tidyverse.org/reference/select.html">dplyr::select()</a></code> and <code><a href="https://dplyr.tidyverse.org/reference/across.html">dplyr::across()</a></code>, and in many functions from tidyr, like <code>pivot_longer()</code>, <code>pivot_wider()</code>, <code>separate()</code>, <code>extract()</code>, and <code>unite()</code>.</p></li>
<li><p>To refer to variables indirectly use <code>any_of()</code> or <code>all_of()</code>: both expect a character vector env-variable containing the names of data-variables. The only difference is what happens if you supply a variable name that doesn’t exist in the input: <code>all_of()</code> will throw an error, while <code>any_of()</code> will silently ignore it.</p></li>
</ul></section><section id="mastering-reactivity" class="level1 unnumbered"><h1 class="unnumbered">Mastering reactivity</h1>
</section><section id="why-reactivity" class="level1" data-number="12"><h1 data-number="12">
<span class="header-section-number">12</span> Why reactivity?</h1>
<ul>
<li><p>But magic in software usually leads to disillusionment: without a solid mental model, it’s extremely difficult to predict how the software will act when you venture beyond the borders of its demos and examples. And when things don’t go the way you expect, debugging is almost impossible.</p></li>
<li><p>Once you’ve formed an accurate mental model of reactivity, you’ll see that there’s nothing up Shiny’s sleeves: the magic comes from simple concepts combined in consistent ways.</p></li>
<li><p>Reactive programming is a style of programming that focuses on values that change over time, and calculations and actions that depend on those values.</p></li>
<li><p>For Shiny apps to be maximally useful, we need reactive expressions and outputs to update if and only if their inputs change. We want outputs to stay in sync with inputs, while ensuring that we never do more work than necessary.</p></li>
<li>
<p>A reactive expression has two important properties:</p>
<ul>
<li><p>It’s <strong>lazy</strong>: it doesn’t do any work until it’s called.</p></li>
<li><p>It’s <strong>cached</strong>: it doesn’t do any work the second and subsequent times it’s called because it caches the previous result.</p></li>
</ul>
</li>
<li><p>Spreadsheets are closely related to reactive programming: you declare the relationship between cells using formulas, and when one cell changes, all of its dependencies automatically update. So you’ve probably already done a bunch of reactive programming without knowing it!</p></li>
</ul></section><section id="the-reactive-graph" class="level1" data-number="13"><h1 data-number="13">
<span class="header-section-number">13</span> The reactive graph</h1>
<ul>
<li><p>Recall that reactive inputs and expressions are collectively called reactive producers; reactive expressions and outputs are reactive consumers.</p></li>
<li><p>You might wonder how Shiny decides which of the invalidated outputs to execute. In short, you should act as if it’s random: your observers and outputs shouldn’t care what order they execute in, because they’ve been designed to function independently.</p></li>
<li><p>Shiny records a relationship between the output and reactive expression (i.e.&nbsp;we draw an arrow). The direction of the arrow is important: the expression records that it is used by the output; the output doesn’t record that it uses the expression. This is a subtle distinction, but its importance will become more clear when you learn about invalidation.</p></li>
<li><p>Each invalidated reactive expression and output “erases” all of the arrows coming in to and out of it and completing the invalidation phase.</p></li>
<li><p>It may seem perverse that we put so much value on those relationships, and now we’ve thrown them away! But this is a key part of Shiny’s reactive programming model: though these particular arrows were important, they are now out of date. The only way to ensure that our graph stays accurate is to erase arrows when they become stale, and let Shiny rediscover the relationships around these nodes as they re-execute.</p></li>
<li><p>The reactive dependency is established when you read a value from input, not when you use that value.</p></li>
</ul></section><section id="reactive-building-blocks" class="level1" data-number="14"><h1 data-number="14">
<span class="header-section-number">14</span> Reactive building blocks</h1>
<ul>
<li><p>It’s important to note that both types of reactive values have so called reference semantics. Most R objects have copy-on-modify48 semantics which means that if you assign the same value to two names, the connection is broken as soon as you modify one. This is not the case with reactive values — they always keep a reference back to the same value so that modifying any copy modifies all values.</p></li>
<li><p>Reactive expressions cache errors in exactly the same way that they cache values.</p></li>
<li>
<p>Errors are also treated the same way as values when it comes to the reactive graph: errors propagate through the reactive graph exactly the same way as regular values. The only difference is what happens when an error hits an output or observer:</p>
<ul>
<li><p>An error in an output will be displayed in the app.</p></li>
<li><p>An error in an observer will cause the current session to terminate. If you don’t want this to happen, you’ll need to wrap the code in <code><a href="https://rdrr.io/r/base/try.html">try()</a></code> or <code><a href="https://rdrr.io/r/base/conditions.html">tryCatch()</a></code>.</p></li>
</ul>
</li>
<li><p>Observers and outputs are powered by the same underlying tool: <code><a href="https://rdrr.io/pkg/shiny/man/observe.html">observe()</a></code>. This sets up a block of code that is run every time one of the reactive values or expressions it uses is updated. Note that the observer runs immediately when you create it — it must do this in order to determine its reactive dependencies.</p></li>
<li>
<p><code><a href="https://rdrr.io/pkg/shiny/man/observe.html">observe()</a></code> also powers reactive outputs. Reactive outputs are a special type of observers that have two important properties:</p>
<ul>
<li><p>They are defined when you assign them into <code>output</code>, i.e.&nbsp;<code>output$text &lt;- ...</code> creates the observer.</p></li>
<li><p>They have some limited ability to detect when they’re not visible (i.e.&nbsp;they’re in non-active tab) so they don’t have to recompute51.</p></li>
</ul>
<p>It’s important to note that <code><a href="https://rdrr.io/pkg/shiny/man/observe.html">observe()</a></code> and the reactive outputs don’t “do” something, but “create” something (which then takes action as needed).</p>
</li>
<li><p>Shiny provides <code><a href="https://rdrr.io/pkg/shiny/man/isolate.html">isolate()</a></code> to resolve this problem. This function allows you to access the current value of a reactive value or expression <strong>without</strong> taking a dependency on it</p></li>
<li><p><code>invalidateLater(ms)</code> causes any reactive consumer to be invalidated in the future, after <code>ms</code> milliseconds. It is useful for creating animations and connecting to data sources outside of Shiny’s reactive framework that may be changing over time.</p></li>
</ul></section><section id="escaping-the-graph" class="level1" data-number="15"><h1 data-number="15">
<span class="header-section-number">15</span> Escaping the graph</h1>
<ul>
<li><p>
Having a reactive graph that is as simple as possible is important for both humans and for Shiny. A simple graph is easier for humans to understand, and a simple graph is easier for Shiny to optimise.
</p></li>
</ul></section><section id="best-practices" class="level1 unnumbered"><h1 class="unnumbered">Best practices</h1>
</section><section id="general-guidelines" class="level1" data-number="16"><h1 data-number="16">
<span class="header-section-number">16</span> General guidelines</h1>
<ul>
<li><p>Improving your software engineering skills is a lifelong journey. Expect to have frustrations as you start learning them, but understand that everyone experiences the same issues, and if you persevere you’ll get past them. Most people go through the same evolution when learning a new technique: “I don’t understand it and have to look it up every time I use it” to “I vaguely understand it but still read the documentation a lot” to eventually “I understand it and can use it fluidly”. It takes time and practice to get to the final stage.</p></li>
<li>
<p>Being a good programmer means developing empathy for others who will need to interact with this code-base in the future (even if it’s just future-you!). Like all forms of empathy, this takes practice and becomes easier only after you’ve done it many times. Over time, you’ll start to notice that certain practices improve the readability of your code. There are no universal rules, but some general guidelines include:</p>
<ul>
<li><p>Are the variable and function names clear and concise? If not, what names would better communicate the intent of the code?</p></li>
<li><p>Do I have comments where needed to explain complex bits of code?</p></li>
<li><p>Does this whole function fit on my screen or could it be printed on a single piece of paper? If not, is there a way to break it up into smaller pieces?</p></li>
<li><p>Am I copying-and-pasting the same block of code many times throughout my app? If so, is there a way to use a function or a variable to avoid the repetition?</p></li>
<li><p>Are all the parts of my application tangled together, or can I manage the different components of my application in isolation?</p></li>
</ul>
</li>
<li>
<p>Automation takes time to set up, but it pays off over time because you can run the tests more frequently. For that reason, various forms of automated testing have been developed for Shiny, as outlined in Chapter 21. As that chapter will explain, you can develop:</p>
<ul>
<li><p>Unit tests that confirm the correct behaviour of an individual function.</p></li>
<li><p>Integration tests to confirm the interactions between reactives.</p></li>
<li><p>Functional tests to validate the end-to-end experience from a browser</p></li>
<li><p>Load tests to ensure that the application can withstand the amount of traffic you anticipate for it.</p></li>
</ul>
<p>The beauty of writing an automated test is that once you’ve taken the time to write it, you’ll never need to manually test that portion of the application again. You can even leverage continuous integration to run these tests every time you make a change to your code before publishing the application.</p>
</li>
</ul></section><section id="functions" class="level1" data-number="17"><h1 data-number="17">
<span class="header-section-number">17</span> Functions</h1>
<ul>
<li>
<p>In this chapter, you’ll learn how writing functions can help. This tends to have slightly different flavours for UI and server components:</p>
<ul>
<li><p>In the UI, you have components that are repeated in multiple places with minor variations. Pulling out repeated code into a function reduces duplication (making it easier to update many controls from one place), and can be combined with functional programming techniques to generate many controls at once.</p></li>
<li><p>In the server, complex reactives are hard to debug because you need to be in the midst of the app. Pulling out a reactive into a separate function, even if that function is only called in one place, makes it substantially easier to debug, because you can experiment with computation independent of reactivity.</p></li>
</ul>
<p>Functions have another important role in Shiny apps: they allow you to spread out your app code across multiple files. While you certainly can have one giant <code>app.R</code> file, it’s much easier to manage when spread across multiple files.</p>
</li>
<li>
<p>There are two places you might put them depending on how big they are:</p>
<ul>
<li><p>I recommend putting large functions (and any smaller helper functions that they need) into their own <code>R/{function-name}.R</code> file.</p></li>
<li><p>You might want to collect smaller, simpler, functions into one place. I often use <code>R/utils.R</code> for this, but if they’re primarily used in your ui you might use <code>R/ui.R</code>.</p></li>
</ul>
</li>
<li><p>If you’re developing a lot of Shiny apps within your organisation, you can help improve cross-app consistency by putting functions like this in a shared package.</p></li>
<li>
<p>Whenever you have a long reactive (say &gt;10 lines) you should consider pulling it out into a separate function that does not use any reactivity. This has two advantages:</p>
<ul>
<li><p>It is much easier to debug and test your code if you can partition it so that reactivity lives inside of <code>server()</code>, and complex computation lives in your functions.</p></li>
<li><p>When looking at a reactive expression or output, there’s no way to easily tell exactly what values it depends on, except by carefully reading the code block. A function definition, however, tells you exactly what the inputs are.</p></li>
</ul>
<p>The key benefits of a function in the UI tend to be around reducing duplication. The key benefits of functions in a server tend to be around isolation and testing.</p>
</li>
</ul></section><section id="shiny-modules" class="level1" data-number="18"><h1 data-number="18">
<span class="header-section-number">18</span> Shiny modules</h1>
<ul>
<li>Shiny modules have two big advantages. Firstly, namespacing makes it easier to understand how your app works because you can write, analyse, and test individual components in isolation. Secondly, because modules are functions they help you reuse code; anything you can do with a function, you can do with a module.</li>
</ul>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://shiny.posit.co/">shiny</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">histogramUI</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rstudio.github.io/htmltools/reference/tagList.html">tagList</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/selectInput.html">selectInput</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/NS.html">NS</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Variable"</span>, choices <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/names.html">names</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mtcars</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/numericInput.html">numericInput</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/NS.html">NS</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bins"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bins"</span>, value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, min <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/plotOutput.html">plotOutput</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/NS.html">NS</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hist"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">histogramServer</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/moduleServer.html">moduleServer</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">session</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/reactive.html">reactive</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">mtcars</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[[</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">var</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">hist</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/renderPlot.html">renderPlot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/graphics/hist.html">hist</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/data.html">data</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, breaks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bins</span>, main <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">var</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span>, res <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">96</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">histogramApp</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ui</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/fluidPage.html">fluidPage</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">histogramUI</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hist1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">server</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">session</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">histogramServer</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hist1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/shinyApp.html">shinyApp</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ui</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">server</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">histogramApp</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</div>
<ul>
<li><p>Namespacing turns modules into black boxes. From outside of the module, you can’t see any of the inputs, outputs, or reactives inside of it.</p></li>
<li>
<p>Note that the module UI and server differ in how the namespacing is expressed:</p>
<ul>
<li><p>In the module UI, the namespacing is <em>explicit</em>: you have to call <code>NS(id, "name")</code> every time you create an input or output.</p></li>
<li><p>In the module server, the namespacing is <em>implicit</em>. You only need to use <code>id</code> in the call to <code><a href="https://rdrr.io/pkg/shiny/man/moduleServer.html">moduleServer()</a></code> and then Shiny automatically namespaces <code>input</code> and <code>output</code> so that in your module code <code>input$name</code> means the input with name <code>NS(id, "name")</code>.</p></li>
</ul>
</li>
<li><p>Unlike regular Shiny code, connecting modules together requires you to be explicit about inputs and outputs. Initially, this is going to feel tiresome. And it’s certainly more work than Shiny’s usual free-form association. But modules enforce specific lines of communication for a reason: they’re a little more work to create, but much easier to understand, and allow you to build substantially more complex apps.</p></li>
<li><p>You might see advice to use session$userData or other techniques to break out of the module straitjacket. Be wary of such advice: it’s showing you how to work around the rules imposed by namespacing, making it easy to re-introduce much complexity to your app and significantly reducing the benefits of using a module in the first place.</p></li>
</ul>
<div class="cell" data-layout-align="center">
<details class="code-fold"><summary>Code</summary><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://shiny.posit.co/">shiny</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">datasetInput</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filter</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">names</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/ls.html">ls</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"package:datasets"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/NULL.html">is.null</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filter</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/lapply.html">lapply</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">names</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">get</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"package:datasets"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">names</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">names</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/lapply.html">vapply</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filter</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/logical.html">logical</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/selectInput.html">selectInput</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/NS.html">NS</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dataset"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pick a dataset"</span>, choices <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">names</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">datasetServer</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/moduleServer.html">moduleServer</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">session</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/reactive.html">reactive</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/get.html">get</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">dataset</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"package:datasets"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">datasetApp</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filter</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ui</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/fluidPage.html">fluidPage</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">datasetInput</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dataset"</span>, filter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filter</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>,</span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/renderTable.html">tableOutput</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">server</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">session</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">datasetServer</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dataset"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/renderTable.html">renderTable</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/data.html">data</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/shinyApp.html">shinyApp</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ui</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">server</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span></span>
<span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">datasetApp</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div>
</details>
</div>
<ul>
<li>
<p>You can make the life of module user much easier with a quick and dirty call to <code><a href="https://rdrr.io/r/base/stopifnot.html">stopifnot()</a></code>. For example, <code>selectVarServer()</code> could check that data is reactive and filter is not with the following code:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">selectVarServer</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filter</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">is.numeric</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/stopifnot.html">stopifnot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/reactive.html">is.reactive</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/stopifnot.html">stopifnot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/reactive.html">is.reactive</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filter</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/moduleServer.html">moduleServer</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">id</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">session</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/observeEvent.html">observeEvent</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/data.html">data</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/updateSelectInput.html">updateSelectInput</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">session</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var"</span>, choices <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">find_vars</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/data.html">data</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filter</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/reactive.html">reactive</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/utils/data.html">data</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[[</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">var</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
</div>
</li>
<li><p>The key challenge of creating modules is creating functions that are flexible enough to be used in multiple places, but simple enough that they can easily be understood. Figuring out how to write functions that are good building blocks is the journey of a lifetime; expect that you’ll have to do it wrong quite a few times before you get it right. (I wish I could offer more concrete advice here, but currently this is a skill that you’ll have to refine through practice and conscious reflection.)</p></li>
<li><p>The main challenge with this sort of code is remembering when you use the reactive (e.g.&nbsp;<code>x$value</code>) vs.&nbsp;when you use its value (e.g.&nbsp;<code>x$value()</code>). Just remember that when passing an argument to a module, you want the module to react to the value changing which means that you have to pass the reactive, not it’s current value.</p></li>
<li>
<p>If you find yourself frequently returning multiple values from a reactive, you might also consider using the <a href="https://github.com/r-lib/zeallot">zeallot</a> package. zeallot provides the <code>%&lt;-%</code> operator which allows you to assign into multiple variables (sometimes called multiple, unpacking, or destructuring assignment). This can be useful when returning multiple values because you avoid a layer of indirection.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;"><a href="https://github.com/nteetor/zeallot">zeallot</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">histogramApp</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ui</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/fluidPage.html">fluidPage</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">...</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span></span>
<span>  <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">server</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">input</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">output</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">session</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span>    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">datasetServer</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">value</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/zeallot/man/operator.html">%&lt;-%</a></span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectVarServer</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"var"</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">data</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">histogramServer</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hist"</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">value</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;"><a href="https://rdrr.io/pkg/shiny/man/shinyApp.html">shinyApp</a></span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ui</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">server</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
</div>
</li>
<li><p>The return value of a module should always be a reactive or, if you want to return multiple values, a list of reactives.</p></li>
<li><p>Another important use of modules is to give complex UI elements a simpler user interface.</p></li>
</ul></section><section id="packages" class="level1" data-number="19"><h1 data-number="19">
<span class="header-section-number">19</span> Packages</h1>
<ul>
<li><p>The core idea of a package is that it’s a set of conventions for organising your code and related artefacts: if you follow those conventions, you get a bunch of tools for free.</p></li>
<li><p>In fact, all a project needs to be a package is a directory of R files and a <code>DESCRIPTION</code> file. A package is just a lightweight set of conventions that unlock useful tools and workflows.</p></li>
</ul></section><section id="testing" class="level1" data-number="20"><h1 data-number="20">
<span class="header-section-number">20</span> Testing</h1>
<ul>
<li><p>As your app gets more complicated it becomes impossible to hold it all in your head simultaneously. Testing is a way to capture desired behaviour of your code, in such a way that you can automatically verify that it keeps working the way you expect. Turning your existing informal tests into code is painful when you first do it, because you need to carefully turn every key press and mouse click into a line of code, but once done, it’s tremendously faster to re-run your tests.</p></li>
<li><p>These levels of testing form a natural hierarchy because each technique provides a fuller simulation of the user experience of an app. The downside of the better simulations is that each level is slower because it has to do more, and more fragile because more external forces come into play. You should always strive to work at the lowest possible level so your tests are as fast and robust as possible. Over time this will also influence the way you write code: knowing what sort of code is easier to test will naturally push you towards simpler designs.</p></li>
<li><p>The art of testing is figuring out how to write tests that clearly define the expected behaviour of your function, without depending on incidental details that might change in the future.</p></li>
<li><p>Note that the second argument to <code>expect_error()</code> is a regular expression — the goal is to find a short fragment of text that matches the error you expect and is unlikely to match errors that you don’t expect.</p></li>
<li><p>A snapshot expectation differs from other expectations primarily in that the expected result is stored in a separate snapshot file, rather than in the code itself. Snapshot tests are most useful when you are designing complex user interface design systems, which is outside of the scope of most apps.</p></li>
<li><p>It’s very useful to verify that your tests test what you think they’re testing. A great way to do this is with “code coverage” which runs your tests and tracks every line of code that is run. You can then look at the results to see which lines of your code are never touched by a test, and gives you the opportunity to reflect on if you’ve tested the most important, highest risk, or hardest to program parts of your code. It’s not a substitute for thinking about your code — you can have 100% test coverage and still have bugs. But it’s a fun and a useful tool to help you think about what’s important, particularly when you have complex nested code.</p></li>
<li>
<p>When should you write tests? There are three basic options:</p>
<ul>
<li><p><strong>Before you write the code</strong>. This is a style of code called test driven development, and if you know exactly how a function should behave, it makes sense to capture that knowledge as code before you start writing the implementation.</p></li>
<li>
<p><strong>After you write the code.</strong> While writing code you’ll often build up a mental to-do list of worries about your code. After you’ve written the function, turn these into tests so that you can be confident that the function works the way that you expect.</p>
<p>When you start writing tests, beware writing them too soon. If your function is still actively evolving, keeping your tests up to date with all the changes is going to feel frustrating. That may indicate you need to wait a little longer.</p>
</li>
<li><p><strong>When you find a bug</strong>. Whenever you find a bug, it’s good practice to turn it into an automated test case. This has two advantages. Firstly, to make a good test case, you’ll need to relentlessly simplify the problem until you have a very minimal reprex that you can include in a test. Secondly, you’ll make sure that the bug never comes back again!</p></li>
</ul>
</li>
</ul></section><section id="security" class="level1" data-number="21"><h1 data-number="21">
<span class="header-section-number">21</span> Security</h1>
<ul>
<li>
<p>When securing your app, there are two main things to protect:</p>
<ul>
<li><p>Your data: you want to make sure an attacker can’t access any sensitive data.</p></li>
<li><p>Your compute resources: you want to make sure an attacker can’t mine bitcoin or use your server as part of a spam farm.</p></li>
</ul>
</li>
<li><p>Note that code within <code>server()</code> is isolated so there’s no way for one user session to see data from another. The only exception is if you use caching</p></li>
<li><p>Finally, note that Shiny inputs use client-side validation, i.e.&nbsp;the checks for valid input are performed by JavaScript in the browser, not by R. This means it’s possible for a knowledgeable attacker to send values that you don’t expect.</p></li>
<li>
<p>In general, the combination of <code><a href="https://rdrr.io/r/base/parse.html">parse()</a></code> and <code><a href="https://rdrr.io/r/base/eval.html">eval()</a></code> is a big warning sign for any Shiny app: they instantly make your app vulnerable. Similarly, you should never <code><a href="https://rdrr.io/r/base/source.html">source()</a></code> an uploaded <code>.R</code> file, or <code><a href="https://pkgs.rstudio.com/rmarkdown/reference/render.html">rmarkdown::render()</a></code> an uploaded <code>.Rmd</code>. But these cases are pretty obvious, and are unlikely to be source of real problems.</p>
<p>The bigger challenge arises because are a number of functions that <code><a href="https://rdrr.io/r/base/parse.html">parse()</a></code>, <code><a href="https://rdrr.io/r/base/eval.html">eval()</a></code>, or both, in a way that you’re not aware of.</p>
</li>
</ul></section><section id="performance" class="level1" data-number="22"><h1 data-number="22">
<span class="header-section-number">22</span> Performance</h1>
<ul>
<li><p>This is a feature of Shiny: it allows you to quickly prototype a proof of concept that works for you, before figuring out how to make it fast so many people can use it simultaneously. Fortunately, it’s generally straightforward to get 10-100x performance with a few simple tweaks.</p></li>
<li><p>Benchmarking lets you check the performance of your app with multiple users, without actually exposing real people to a potentially slow app. Or if you want to serve 100s or 1000s of users, benchmarking will help you figure out just how many users each process can handle, and hence how many servers you’ll need to use.</p></li>
<li><p>As well as a flame graph, profvis also does its best to find and display the underlying source code so that you can click on a function in the flame graph to see exactly what’s run.</p></li>
<li><p>The most important limitation of profiling is due to the way it works: R has to stop the process and inspect what R functions are currently run. That means that R has to be in control.</p></li>
<li><p>Begin by resolving any issues where existing code is run more often than you expect — make sure you’re not repeating the same work in multiple reactives and that the reactive graph isn’t updating more often than you expect</p></li>
<li><p>Caching is a very powerful technique for improving code performance. The basic idea is to record the inputs to and outputs from every call to a function. When the cache function is called with a set of inputs that it’s already seen, it can replay the recorded output without recomputing.</p></li>
</ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>R</category>
  <guid>https://learn.shitao5.org/posts/20240119-mastering-shiny/</guid>
  <pubDate>Thu, 18 Jan 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240119-mastering-shiny/cover.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>引爆点</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240116-ybd/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Paused. Current progress 15.82%.⏱</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/35097478/" class="uri">https://book.douban.com/subject/35097478/</a></li>
</ul>
</div>
</div>
<section id="推荐序一-理解流行" class="level1 unnumbered"><h1 class="unnumbered">推荐序一 理解流行</h1>
<ul>
<li><p>“为何流行”这个问题，决定着哪些东西会被购买，哪些东西会无人问津。资本主义甚至专门发明了广告和营销行业来解决这个问题。</p></li>
<li><p>对一位有新意的变革者来说，重要的是提出理解世界的新方法，甚至因此而改变人们的生活方式。</p></li>
</ul></section><section id="推荐序二-在每个人都想成为网红的时代如何创造红" class="level1 unnumbered"><h1 class="unnumbered">推荐序二 在每个人都想成为网红的时代，如何创造“红”</h1>
<ul>
<li><p>所有的潮流都存在着一个引爆点，它与观念、产品、信息和行为方式相关，它的到来虽出人意料，却有迹可循。</p></li>
<li>
<p>一场流行潮的发起是由少数人驱动的，但是它未必来自一个中央系统，甚至也不是来自超级人物，而是来自一个“角色组合”。格拉德威尔把这个组合里的角色定义为联络员、内行和推销员。</p>
<p>联络员是指那些交际广泛，一旦传递信息，就有无数人接收到的人；内行是那些对某个领域研究得特别透彻的意见领袖；推销员则是乐于传播的活跃分子。在流行过程中，内行是数据库，他们可以为其周围的人提供信息；联络员是社会黏合剂，他们会四处传播信息；推销员则负责说服大家。</p>
</li>
<li><p>附着力因素法则指的是流行事物本身应该具有让人过目不忘或者至少给人留下深刻印象的附着力。</p></li>
<li><p>当一个社群的规模超过 150 人时，组织成员之间的沟通就会开始出现问题，协作便走向低效。因此，150 人是环境威力发挥最佳效用的边界。</p></li>
</ul></section><section id="推荐序三-刷屏时代的流行方法论" class="level1 unnumbered"><h1 class="unnumbered">推荐序三 “刷屏”时代的流行方法论</h1>
<ul>
<li><p>
品牌传播的终极目标是通过传播活动扩大品牌的知名度，形成品牌的美誉度，从业者们每天都绞尽脑汁希望能够做出“刷屏”的优秀案例，让其服务的品牌能用最小的投入获得最大的收益；品牌危机则是时时悬在品牌头上的“达摩克利斯之剑”，尤其是移动互联网技术的普及更是加快了品牌危机暴发的速度并加剧了其对品牌的危害程度，这使品牌危机管理工作成为众多企业在现阶段不可回避的一个颇为棘手的问题。
</p></li>
</ul></section><section id="前言" class="level1 unnumbered"><h1 class="unnumbered">前言</h1>
<ul>
<li><p>
感染性是一种所有事物都具备但却难以被预知的性质。
</p></li>
</ul></section><section id="流行三法则个别人物法则附着力因素法则和环境威力法则" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 流行三法则：个别人物法则、附着力因素法则和环境威力法则</h1>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Sociology</category>
  <guid>https://learn.shitao5.org/posts/20240116-ybd/</guid>
  <pubDate>Mon, 15 Jan 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240116-ybd/cover.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>详谈：赵鹏</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240106-xtzp/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Completed.😀</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/35523118/" class="uri">https://book.douban.com/subject/35523118/</a></li>
</ul>
</div>
</div>
<section id="总序" class="level1 unnumbered"><h1 class="unnumbered">总序</h1>
<ul>
<li><p>
采访、记录和研究的目的是对抗遗忘，让后来的人可以真正做到站在前人的肩膀上前行，而不至于陷入不断重蹈覆辙或者不断重新发明轮子的怪圈中。
</p></li>
</ul></section><section id="创业和产品" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 创业和产品</h1>
<ul>
<li><p>当时所有团购网站全遇到了这个问题：一爆全都有，不爆全没有，留不下流量。用户只对价格敏感，对平台没有忠诚度，所以是典型的“剩”者为王。</p></li>
<li><p>进攻难，体体面面地撤退更难。什么叫体面？以后作为一个自然人要见人，作为一个做事的人要做事，两项都顾住了，就叫体面。咱们撤退的时候要像个正规军的样子。</p></li>
<li><p>如果让我抽象地说什么是正事，大概就是，与越多的人有关的、越重要的事，就是正事。</p></li>
<li><p>帮别人花钱的事没有帮别人赚钱的事重要。</p></li>
<li><p>其实信任感的关键叫闭环，说好的就是说好的，正心诚意，知道的就是知道，不知道的就是不知道，聊正事不能临时想答案，说好的答案就一定要给人家闭环，要 deliver （践行）。</p></li>
<li><p>创始人重要不重要？很重要。但到底有多重要？我看也没多重要。要弄明白你吃谁的饭，你把牛人组织在一起，且让人家心情愉快，有成长感，有成就感，有归属感，这些是你厉害的地方。创始人充其量就是一个部落的酋长，你打仗有战士厉害吗？采摘有大姐厉害吗？跳个大神你也跳不过祭司。需要有你这么一个酋长，但是可不能妄自尊大。最不妄自尊大的方法就是把利益分了，所以我们是勇敢地分。</p></li>
<li><p>你其实不知道你一定能行，创业的本质就是瞎子摸象，千万别还没出发呢，就弄了个顶层设计，第三年就已经把 model （模式）说清楚了。</p></li>
<li><p>我们看三类现象，第一，在朋友圈发招聘信息的人，请问是经理人多，还是创业公司老板多，还是职业招聘者多？肯定是老板多。第二，在饭局上说，哎呀，你们给我推荐个人啊，最近可愁了。请问这种人是创业者多，还是职业招聘者多？肯定是创业者多吧。第三，从我们平台上来看，正月初一在那里聊牛人的，也是老板多得多。所以这就是生活，生活中本来就是直聘的，就是小公司的大老板、大公司的 line manager （部门经理、业务主管）自己来找人的。</p></li>
<li><p>任何企业，今天不管多有品牌，多给得起 offer （出价），都千万不要把自己当甲方，只要你想追的是那个前 20% 的人，你就绝不是甲方。</p></li>
<li><p>非常多的创新其实是利用现代意义上的技术和产品，给了一个可以还原的、简单而优美的东西的场景。</p></li>
<li><p>创业要珍爱生命，远离模式，远离顶层设计，远离确定性，远离用确定性的方法去考核事情。</p></li>
<li><p>要按牌理出牌，敬畏无常，拥抱不可知。创业按牌理出牌是有的，比方说钱永远是不够的，融资是不能停的，除了热爱用户以外，其他都是瞎扯，你吃谁的饭你就敬着谁，你不知道吃谁的饭，或者知道了还不敬着，那就是早死晚死的问题，这都算是按牌理出牌。</p></li>
<li><p>我们伺候的是用户，不是某一个“帝国”，不是某座城墙范围内的疆土。用户是不会被任何人锁在他的城墙里的。</p></li>
<li><p>负向方法论的意思是说，败了就败了呗。我们家常自问一个问题，这一组创新如果败了，试问咱公司还在不在？这一组创新败了，试问你的锐气还在不在？这一组创新败了，试问团队的荣誉感还在不在？综上都在，你就干。有一个不在了，你就想想再干。</p></li>
<li><p>我们不弄一堆“官”，“官”在企业里面是非常害人的，企业一定不是靠权力去驱动的。</p></li>
</ul></section><section id="人和资本" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> 人和资本</h1>
<ul>
<li><p>企业最大的成本是沟通成本，企业任何的组织架构设计，汇报线设计，只要让沟通成本变高的，就一定是不划算的。</p></li>
<li><p>我们把审批流分为真批和假批。真批是什么意思？这个上级比你懂，比你懂的人帮你批，是有意义的，他知道怎么批，批还是不批。</p></li>
<li><p>创始人这种“鬼东西”其实是非常危险的。为什么？一个企业的创始人理论上是无所敬畏的，除了国家法律不能触犯，跟董事会说好的不要去碰，其他谁管你啊？一不小心就没有人管着你。一个企业 200 人，就觉得自己是神一般的存在，这是创始人这个物种，所以企业文化和企业规则千万不要认为是用来管员工的，一定是用来管创始人的，明明白白说好，贴到墙上，就不要去犯。权力是非常害人的东西，创始人是一个有权力的岗位，所以千万要管住自己。我们家的一个方法就是各干各的。</p></li>
<li><p>工业上的聪明：第一，总是能明白人家啥意思；第二，总是能让人家明白自己啥意思；第三，遇到一个课题能够相对快速地形成思路去解决；第四，始终能稳在重点上，不机会主义，不跑偏。综上，在一个工业生产的环境下就是一个聪明人。</p></li>
<li><p>技术上一个人非常优秀，但在他的工作领域长期被埋没，这种情况通常是一个假命题。一个厂子可能最近在战略上遇冷，但是人家能够从零崛起到这个地位，一定是下过童子功的。如果是一个技术公司，那它的工程师文化和工程师培养上，也一定是下过童子功的。在这个层面，一个人永远起不来，非说是这个企业文化有问题，埋没人才，通常不要相信，不要有侥幸心理，这是一个负面的例子。</p></li>
<li><p>其实公众不断在迭代，不断在革新，你要对个标的话，最好对一点 ability 层面的。锋哥（一位算法工程师）告诉我，判断工程师特简单，上大学的时候认真练了童子功，认认真真敲了几年代码，认真琢磨计算机是怎么工作的，人跟计算机是怎么工作的，然后到现在为止，虽然已经 30 多岁，仍然以敲代码为乐趣，尚未出现“敲代码敲下去永远敲不过年轻人”的中年危机，这就是好工程师，熟不熟悉你们家的路子，没关系的。</p></li>
<li><p>做一个事的人，攻克一个难题的人，不需要有那么多经验。但是管一堆人的人，我觉得有点年龄、有点阅历是好事。所以你让我弄一个 24 岁刚毕业两年的人去一个分公司管 100 人，我真的不敢。他需要时间去积累对人与人之间互动规律的认知，甚至直觉。但是有一个技术难题放在这儿，一个 24 岁的人给办了，一点都不奇怪。</p></li>
<li><p>离开业务场景，离开解决实际问题，离开创造价值，那不是企业，是实验室。企业当然可以供养实验室，但既然是企业，就不要离开工业谈别的。</p></li>
</ul></section><section id="市场和竞争" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> 市场和竞争</h1>
<ul>
<li><p>创业者能创则创，创无可创，就坐下来聊商业。商业对于创业者来说是一个结果，既不是第一追求，也不是底层追求，更不是每天的乐趣。所以创有可创，为什么不创？创无可创，为什么不合？</p></li>
<li><p>快和准是衡量人才资源与岗位资源配置效率提升的两个维度。</p></li>
<li><p>一个人哪怕再有本事，来到一个新组织，就是弱势群体。你不去有计划地安排，努力让人成为这个组织的一员，实质上就是对他进行孤立。</p></li>
<li><p>离开用人权的授权就是耍流氓，离开招聘权的用人权就是耍流氓，不是从一开始就接触，只能三面的招聘权就是耍流氓。</p></li>
</ul></section><section id="公司历程" class="level1" data-number="4"><h1 data-number="4">
<span class="header-section-number">4</span> 公司历程</h1>
<ul>
<li><p>创业公司的幸福就是，这个月挣的钱比花的钱多一块，这是一个决定性的拐点。</p></li>
<li><p>0 到 1 的时候，最怕不知道哪儿对了、哪儿错了，也就是怕噪音。</p></li>
<li><p>当你可以给这个行业创造一个数量级的价值，但收的是低一个数量级的价格时，你一定是站着挣钱的。当你给人家创造了一个 10 数量级的价值，却问人要一个 10 数量级的价格时，你一定是趴着挣钱的，蹲都蹲不起来。</p></li>
<li><p>消红点模型，就是说任何人的微信本来都很干净，可是某一天累积到一定程度，就都不再去消微信红点了。这个模型告诉我们，当一个求职者的红点多到懒得消的地步，他就不会回你了。所以你一定要控制这个数量。</p></li>
<li><p>一个企业要想保持创新、创造，一定要有多个人说话，要有各自发展的机会，一定不要弄成一个人拿着尺子衡量所有人，那就完蛋了。</p></li>
<li><p>一个职业人是没有职业收获期这一说的，只要你还在干，就是成长期。职业人始终是年轻的。基于这样一个基本观点，我对 rank （层级）这个东西就没有那么敏感。</p></li>
<li><p>企业的 rank 不是通货，企业以解决问题为核心，比解决问题更牛的事发现并定位问题。</p></li>
<li><p>企业是靠权力运转的吗？如果靠权力运转，逻辑上我们就认为官大的一定牛，那请问自下而上的决策何以实现？所以创造型的企业尤其应该去 rank 化。拿 rank 给小朋友搭建职业成长路径，可能是又老又大的企业干的事，又新又大的企业都未必这么干。</p></li>
<li><p>我觉得人类社会，有良知的人占绝大多数，因此任意一个企业，有良知的人都占绝大多数。如果你摔了飞机还不好好干，你这个企业还有什么向心力？因为一个企业在成长过程中遇到的最大的挫折，乃至于不可逆的挫折，乃至于让它元气大伤的挫折，一定是员工的荣誉感挂掉了。就是我到底是何人，竟然在此地干着此事，挣这点钱？</p></li>
<li><p>创业者希望寻求决战，我觉得往往是焦虑的表现。其实是没有这种机会的。</p></li>
<li><p>我说你就守住这两条线，上不祸及父母，下不殃及子女，挣这个钱就好了。所以三观其实很简单，都是老百姓草根的东西。</p></li>
<li><p>投资吧，其实就是一个胜算的判断方式，赔率的判断方式。如果赔率很高，胜算很低，就不会真的有人投。所以投资人其实是要研究你这个事情的确定性，但创造型公司最大的价值在于它的不确定性，这又是一组悖论。设法把你的不确定性中的确定性找出来，然后按照投资人的模型、结构、算法，翻译成能够让他同意的过程，是财务顾问、是 FA 的价值。当然如果你在投资界有认认真真的几个好朋友，他们也会说我们的语言大概是这样说的，你那套语言是不 work 的。每个创业者都要面对资本市场，也是个学习的过程。</p></li>
<li><p>这个组织凝聚了一拔优秀的人，这拔优秀的人能够按照一个大家比较认可的规则一起做事，从而能够有一些发现新问题、定义新问题、解决新问题的能力，简称进化力。这是这个组织唯一有所谓护城河的地方，也就是它的组织能力。</p></li>
<li><p>组织中的人相信组织的 leader 吗？他凭什么相信你？是因为他笨，你洗了他的脑吗？不是吧？所以我觉得这是最难建设的力量，但是一旦建起来以后，人对了，事早晚就对了。人不对，事再对，早晚也是去沟里了。所以你说有没有护城河，我也不觉得这是护城河，这算生命力吧。河焉以护城，长城焉能挡住匈奴铁骑，还是得靠人。所以我们能攻则不守，绝不守。</p></li>
</ul></section><section id="个人和早年经历" class="level1" data-number="5"><h1 data-number="5">
<span class="header-section-number">5</span> 个人和早年经历</h1>
<ul>
<li><p>你说你是个十几年的销售组织管理者，你是一个或许能排到前几名的 CMO （首席营销官），这些讲了半天都是技能。我说我是个 leader，我最大的成就感不来源于我自己怎么样，而一定来源于团队成员怎么样，我整日乐此不彼。</p></li>
<li><p>譬如说雇主品牌的建立以准为美，不以大为美，你是谁就是谁，说你有多么了不起反而害你。比如说雇主品牌的传播，以在职和离职员工及其家人朋友的口碑传播为主，离职员工对雇主品牌的传播“一夫当关，万夫莫开”，你发一万篇文章都不如这件事情管用。所以看准网衡量雇主品牌最重要的指标，是离职员工愿意推荐自己的亲友去该企业工作，这一个指标金球制胜。所以什么是雇主品牌？它的本质其实是雇主关系这件事情的外化，从而雇主品牌建设一定是由内而外的，一定是从正心诚意开始的，它不是术，是道。</p></li>
<li><p>俗话说男怕入错行，入错行毁一生，是因为入错了又不敢勇敢地跳出，从而失去了自己或许能到达的高度、看世界的宽度，以及认识问题的深度。所谓职业成长，归根到底是人的成长。每一个人都要发展，每一个人都对别人的发展负有一定的责任——当然首先是对自己的发展负有根本的责任。</p></li>
<li><p>人要有一技傍身。CEO 在家里面不是一个虚的存在，创业公司的 CEO 一定要扎扎实实带一件工作。我今天自己带着的是销售。当然其他工作人家也尊重我，有时候也跟我来合计合计。</p></li>
<li><p>你自诩为一个高手的话，就能在万人中发现那个高手，然后心里就会敬佩他。稍微交交手，互相就能产生一种尊重感。内心把人家当乙方，是一个十分错误的想法。选他以前把他当乙方，好像你还能摆摆架子，大家都已经一起合作了，人家真的是乙方吗？你不知道你多重要的事情在人家手里吗？何其不自信的人，才会整天摆甲方心态来满足自己。我们很自信，不需要摆甲方心态。你越这样尊重别人，人家也越这样尊重你。</p></li>
<li><p>综上就是一次营销。四步，你的底子是你的用户存留和口碑传播，没有这个底子，千万不要去拉新，白花钱。有了这个底子，你要找到时机，用足够的钱，买到足够多且足够便宜的量。第三是你物料的记忆度和信息传播的清晰度要够。第四，整个过程中，在单位时间内揪住某位同学的频次要足够，否则就是水过地皮湿。</p></li>
<li><p>其实整了半天，底子是好产品，好产品直指人心。你解决人家问题了没有，这是结果，你解决的过程中人家舒不舒服，这是感受，结果加感受构成了 NPS。所以我觉得，做产品，想着苹果就好了，人家都不需要解释，就是桃李不言下自成蹊，腹有诗书气自华。</p></li>
<li><p>其中有一个战术性的问题，离职的时候与其说见员工人品，还不如说见公司司品。人家要离职，不管主动被动，公司一定要厚道，一定要细致，除非人家真是踩了你的红线。</p></li>
<li><p>我觉得一个创始人兼 CEO 存在感太强的话，这个组织很快就被锁死了。我特别相信 timing 这个东西，该等待时机的等待时机。我很少强力去弄一个什么东西，一定要怎么怎么样。</p></li>
<li><p>基于人性的企业管理，最宝贵的是让更多人有探索和实现自由意志的机会，而不是说围着贪嗔痴慢疑搞什么个性化管理，我做不到。人性是懒的，所以发明一个非常懒的懒人工作法，我做不到。</p></li>
<li><p>职业规划的本质就是一个人要发展，要活得更大，活得更高，换句话说，要看更大范围的世界，要站在更高的楼上看世界，要看到更本质的世界。人活一辈子，能把这几个事越弄越明白，岂不美哉？</p></li>
<li><p>我对所有大学刚毕业的小孩的第一个建议是，你千万找一个你喜欢的事，而且要喜欢的是这个是的 daily （日常），而不是这个事的结果。</p></li>
<li>
<p>两个事情的本质，不管是跟一个老板四年，还是兴趣驱动，都是能稳在一个事情上足够久，从而验证一万小时定律。在一件事情上花一万小时，就可以让一个小孩有一技傍身，至少在一个问题上有点真知灼见。而不是说这儿弄了半年，那儿弄了四个月，说啥都知道，干啥啥不行，这是对人的极大不负责，也是对人的最大浪费。</p>
<p>所以我对小孩的建议很清楚，原点是一万小时定律，为了实现这个定律，要兴趣驱动，兴趣要在 daily，不在结果，然后这个老板、师傅要带你，所以要花足够的时间，找一个你愿意跟他四年的人。如果在本科毕业之后，26 岁，你能实现一万小时定律，你放心，去哪儿都有人抢着要你。</p>
</li>
<li>
<p>当人们谈大厂的时候其实谈的是三句话。第一是有足够的钱发工资。关于这句话，我想反问，你现在是职业收获期还是职业成长期？在职业成长期，不要太去看大厂的所谓高工资。第二是面子，我在哪儿哪儿工作。那我要问，这个面子对于一个年轻人来说有这么重要吗？你现在要面子还是要里子？第三是培训成长体系，这点我们要给大厂以严重肯定。但是同理，这个人原来是一个阿里 P8，现在在一个创业公司当技术总监，能亲自带你。你到大厂去，有相当于阿里 P8 的人带你吗？所以你预期承认一个培训成长体系，不如承认跟对了师傅对你一辈子的影响。</p>
<p>最后还有一点，其实是最容易被击破的，叫安全感。在大厂工作真的安全吗？什么叫安全？真正的安全感不是你去了一个水波不兴的水域游泳，而是你游泳的技能可以应对各种水域。大厂创新业务线的人噼里啪啦地掉落，这个事罕见吗？有经验的招聘者看大厂员工，一定会看他原来在哪儿。</p>
<p>所以，当我们谈到大厂的时候，是在谈收入，谈面子，谈培训，谈安全感，这些创业公司样样都可以谈，而且可能谈得更好。所以我不觉得年轻人一定要去选所谓大厂。</p>
</li>
<li><p>公文的遣词达意，不能以文害意，文宜简不宜繁，宜用浅显词不宜用典，能直接说就别绕着说，能顺着说就别排着说，这是有训练的。写字写清楚的，是有训练的，除了语文课上训练以外，就是靠工作训练。</p></li>
<li><p>给领导做文稿服务，好的文章写完之后，脱了稿能讲，不是背出来的，是因为这个东西很顺，讲道理讲的是顺的道理，说知识说的是浅的知识。与其说是文字训练，不如说是思维训练、逻辑训练。</p></li>
<li><p>现在有的年轻管理者，认为他是因权力而实施管理，这是一个很大的误解。你奖励一个人还是处罚一个人，归根到底是因为规则。你是一个规则的看守者和执行者，而不是一个可以随意运用规则去打击谁的人。</p></li>
<li><p>老谷歌人真心诚意信奉的是依靠技术的力量去解决简单的复杂问题。所谓简单一定是众人皆知，不需要广播也知道它是无数人的问题；所谓复杂就是用传统方法根本解决不好的问题。然后用技术的力量去解决，这是一种信仰。</p></li>
<li><p>人类社会这种高度的城市化、现代化、分工化的发展，本身是一种进步，而所有的进步都会带来问题，对职业的困惑就是其中的一种。这个问题怎么解决？是进步的产物，那就靠进步去解决。靠人类驾驭巨大的算力，去帮助解决。如果没有计算机技术的发展，这个问题就只是一个问题。</p></li>
<li><p>我为用户创造价值。铁打的用户，流水的股东。用户永远在，只要你为世界、为用户创造了价值。股东来是为了走，10 块钱来的，1000 块钱走，很开心。人家不走，是走得不划算，又对你有信心，这个钱放在别人那儿还不如放在你这人；人家要走，是人家的自由。</p></li>
<li><p>我不觉得一个科技公司要建立 50 年长盛不衰的理想，这可能恰恰是屠龙少年最后长了一身鳞甲的表现。我不喜欢壁垒这种词，我们今天的心态就是一个创业者，己所不欲，勿施于人，弄那么多壁垒干什么？如果一个企业存在的最大价值，是让它的十几万人比中国的十几亿人都活得好，那这种价值是这个世界所不支持的。如果这个世界的运作就是为了支持这种事情的存在，那还是跟埃隆·马斯克去火星吧。</p></li>
</ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Management</category>
  <category>Interview</category>
  <guid>https://learn.shitao5.org/posts/20240106-xtzp/</guid>
  <pubDate>Fri, 05 Jan 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240106-xtzp/cover.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>行为设计学1</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240106-xwsjx1/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: 26.92%.</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/30390604/" class="uri">https://book.douban.com/subject/30390604/</a></li>
</ul>
</div>
</div>
<section id="前言-何为创意黏性" class="level1 unnumbered"><h1 class="unnumbered">前言 何为创意黏性？</h1>
<ul>
<li><p>所谓“黏性”，是指你的创意与观点能让人听懂，能被人记住，并形成持久的影响。（换言之，它们能够改变受众的思想或行为。）</p></li>
<li><p>事实上，众多天生就有黏性的观点中，最古老的类别恐怕要数谚语了：谚语就是一种能流传后世并能跨越文化的浓缩智慧。举例而言，“无风不起浪”这句谚语就可以在全球至少 55 种语言里找到相似的版本。</p></li>
<li><p>简单，并不是一味追求至简，甚至断章取义，而是努力提炼精要箴言。我们必须让表达既简短又深刻。黄金法则是简单的终极模型：一句话如此深刻，以至于一个人可以花一生的时间去学习跟随它。</p></li>
<li><p>单靠出乎意料并不能持久，要让想法延续下去，我们必须激发他人的兴趣和好奇心。如果让你来教本学年的第 48 堂历史课，你如何才能吸引学生的注意力呢？要长时间保持听众的好奇，我们可以先系统地给学生挖下一系列知识的“缺口”，然后再逐一填满。</p></li>
<li><p>信息具体化，是确保每一位对象都能真正接收到同等观点的唯一办法。</p></li>
<li><p>创意要有黏性，必须具备相应的信用背景。我们必须设法帮助他人亲自证实这些构想，也就是观念世界中“先试再买”的行事哲学。</p></li>
<li><p>研究表明，人们总是更愿意捐助一个一贫如洗的人，而不是整片的穷乡僻壤。人们更容易产生感觉的对象往往是人，而不是抽象的事物。有时候，困难之处在于引发哪种情绪最有效。举例来说，想劝青少年戒烟，仅用威慑恐吓的方式给他们灌输吸烟导致的可怕后果，大概很难奏效，但如果激起年轻人对大烟草公司（Big Tobacco）欺诈行径的憎恨之情，就比较容易达成戒烟的目的。</p></li>
<li><p>问题就在于，击节者一旦事先掌握了某种知识（比如歌曲名），就很难想象缺乏这种知识的情形。击节者击打节奏时，想象不出听猜者听到的是一个个离散的敲击声，而不是连贯的歌曲旋律。这就是“知识的诅咒”。我们一旦知道某种知识，就无法想象不知道这种知识时会发生什么，我们的知识“诅咒”了我们。我们很难与他人分享这些知识，因为我们无法轻易摸透听猜者那一方的心理状态。</p></li>
<li><p>事实上，只有两种办法能真正克服“知识的诅咒”：第一种是什么也不学，什么都不知道；第二种则是彻底改造你已有的观点。</p></li>
<li><p>你要是希望把自己的想法传达给他人，就应该遵循多年来已让各种想法先后获得成功的规则。你需要发明的是新构想，而不是新规则。</p></li>
</ul></section><section id="简单-精炼核心信息" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 简单 精炼核心信息</h1>
<ul>
<li><p>简单是指我们应该“找到创意的核心”，剔除那些多余的干扰因素，因为我们在不可预测和混乱的情况下是很难做出明智的决定的。</p></li>
<li><p>“指挥官意图”绝不会悉数阐明诸多琐碎的细节，否则将在突发状况下失去用武之地。科蒂茨也说：“无法执行原定计划倒也无妨，但你永远有责任执行原定意图。”</p></li>
<li><p>简单原则追求的是简练精确和轻重有序，而绝对不是化智为愚。</p></li>
<li><p>在导语之后，其他信息按照重要性递减的顺序呈现。新闻从业人士称之为“倒金字塔”结构，亦即最重要的信息（金字塔最宽处）位于最顶端。</p></li>
<li><p>一篇稿子写得越久，就越容易迷失方向。你会变得像盲人摸象一样，只见树木不见森林，最后连文章主旨都给忘了。</p></li>
<li><p>心理学家研究发现，过度的复杂性和不确定性会使人做出不理智的决策。</p></li>
<li><p>切勿埋没导语。不要为了吸引读者而用有趣但不相干的段落开篇。相反，应该设法让核心信息本身变得更吸引人。</p></li>
<li><p>找到了核心并不等于就能把核心传达给别人。管理阶层可能知道如何排定问题的优先次序，但也可能根本做不到分享和执行这些优先次序。</p></li>
<li><p>信息的简化既要寻找核心，又要尽量精炼。</p></li>
<li><p>面对具有共同标准的不同环境，谚语有助于指导人们做出具体的决策。这些共同的标准通常是指伦理道德层面的。谚语可以为人们的行为提供经验教训。“己所不欲，勿施于人”这条黄金戒律正是因其含义深刻，从而能影响人一生的行为。</p></li>
<li><p>大部分技术和产品设计工程项目都免不了要对抗“功能蔓延”；功能蔓延指的是让产品越来越复杂，乃至无法正常操作基础功能的一种倾向。</p></li>
<li><p>我们已经见识过精炼的观点比较具有黏性，但想法光有精炼并没有太多价值，精炼还得有深度才会有意义。那么，要让有深度的想法变得精炼，就得在简短的信息中装进更多的内容。具体怎么做呢？请用插旗子的办法。唤起受众脑中已有的记忆，运用对方已有的知识。</p></li>
<li><p>心理学家将“图式”定义为某种概念或类别的一般属性集合，“图式”由我们记忆中预先储存的海量信息组成。</p></li>
<li><p>图式可以提供有深度的简单信息。 好老师本能地就会运用许多图式。</p></li>
<li><p>一则信息要是无法用来做预测或做决定，那么它就毫无价值，不论它有多么精确或全面。</p></li>
<li><p>人们总想一下子就精准无比地告诉对方一切，但实际上我们应该做的是，先告诉对方能够承受的信息，然后再一点一点慢慢增多。</p></li>
<li><p>高概念营销策划正是好莱坞版的核心谚语。正如大多数谚语一样，高概念也吸取了类比的力量。这些谚语唤起现成的图式（如《大白鲨》的人物、情节和布景等），从根本上加速了电影人制作新片时所需的学习过程。</p></li>
<li><p>要求员工把自己的角色想象成舞台演出而非维护工作，这正是迪士尼乐园如日中天的重要原因。在迪士尼乐园里，“员工就是演员”是一则成功推行了 50 余年的生成性类比。</p></li>
<li><p>生成性类比和谚语的力量都来自同一种巧妙的替代法：用简单易懂的东西替换复杂的东西。</p></li>
<li><p>先“找到核心”，再用“精炼观点”的形式表达出来。这工夫绝对花得物超所值，也会带来持久的效力。</p></li>
</ul></section><section id="意外-吸引和维持注意" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> 意外 吸引和维持注意</h1>
<ul>
<li><p>传递信息时最首要的问题就是我们如何吸引别人的注意。这时我们就需要找到人们知识上的缺口：当人们想知道一些事却无法实现时，他们会执拗地想消除这种痛苦，把知识的缺口填满。因此，我们的创意需要出人意料，就好像寂静时发出的清脆响声。</p></li>
<li><p>大多数时候，我们没办法强求别人注意，我们只得吸引别人注意。吸引注意无疑是更难的挑战。“你不能强迫人们注意”，这是一种常识。</p></li>
<li><p>要吸引他人注意最基本的方法：打破常规。我们适应规律性事物的速度很快，持续不变的感官刺激往往让我们视而不见且听而不闻。不妨想一想空调的嗡嗡声、交通噪声、蜡烛的气味或者书架的摆放。唯有事物发生变化时，我们才会有意识地注意到这些东西。比如空调突然坏了，或家人重新整理过书架了。</p></li>
<li><p>如果我们想要传达的信息无法从纷乱无序中突出重围，吸引他人的注意，那就无法获得成功；或者，我们的信息非常复杂，如果不能维持他人的注意，我们也很难成功。 要弄清这两个问题的答案，我们得先理解两种基本情绪：惊讶和兴趣。天生具有黏性的观点通常都能激起这两种情绪。</p></li>
<li><p>人类情感可以巧妙地帮助我们应对特殊情境，让我们为不同的行为和思考方式做好准备。我们都听说过，愤怒使人迎接战斗，恐惧使人准备逃避。不过，情感和行为之间的联系或许有更加微妙的关系。比如说，最新研究的表明，愤怒的次生效应就是让我们对自己的判断更加坚信不疑。愤怒的时候，我们会知道自己是对的，但凡生过气的人都可以证明这一点。 如果说每种情感都带有各自的生理作用，那么惊讶的生理作用又是什么呢？惊讶可以唤醒我们的注意力。图式工作失灵就会触发惊讶，惊讶还能帮我们弄清图式失效的原因。当我们的预测机器失灵，惊讶就会抓住我们的注意力，好让我们将之修复，以备后用。</p></li>
<li><p>意外的事件往往黏性很强。因为惊讶让我们集中注意力思考，这份注意和思考将意外事件烙印在我们的记忆中。惊讶能吸引我们注意，这种注意有时短暂，有时却能持久。惊讶能促使我们去挖掘事件背后的原因，去想象其他的可能，去设法避免今后再发生同类的事情。</p></li>
<li><p>要让人惊讶，事情就必须“不可预测”；令人惊讶和可以预测总是对立的两极。但是要让人获得满足，惊讶又得要“可以预测”。此间妙处在于，事前怎么都料想不到，事后一旦想通便可领略个中奥秘。</p></li>
<li><p>从日常应用角度来说，归根结底就一句话：你要想让观点产生黏性，就得先破坏他人的预测机器，然后再将其修好。但是在使人大吃一惊、破坏预测机器的同时，该怎样避免沦为狼群广告那样的噱头式惊讶呢？要想避免弄巧成拙，同时确保意外观念也具有内涵，最简单的办法就是将目标锁定在听众预测机器中与我们核心信息相关的那部分。</p></li>
<li><p>如何让你的想法及创意更具黏性呢？请遵照如下办法：（一）确定你所要传达的中心信息（找到核心）；（二）找出信息中违反直觉的部分（即核心信息中令人意外的含义是什么？为什么事情现在并没有照此发展？）；（三）在重要而又违反直觉的层面上破坏听众的预测图式，从而传递信息。然后，一旦预测图式失效，就帮助他们修好图式。</p></li>
<li><p>新闻报道不只是机械地复述事实，还得想出事情的关键点在哪里。光知道何人、何事、何时与何地远远不够，还得了解它有什么意义，还有它的重要性在哪里。</p></li>
<li><p>悬疑谜题教学的一大好处是“解开谜题的过程和科学研究的过程非常相似”。因此，老师这样做不仅能提高学生对课程知识的兴趣，也等于训练学生像科学家一样去思考。</p></li>
</ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Psychology</category>
  <guid>https://learn.shitao5.org/posts/20240106-xwsjx1/</guid>
  <pubDate>Fri, 05 Jan 2024 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240106-xwsjx1/cover.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>荣格自传</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20231228-rgzz/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: 9%.</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/25793666/" class="uri">https://book.douban.com/subject/25793666/</a></li>
</ul>
</div>
</div>
<section id="译序" class="level1 unnumbered"><h1 class="unnumbered">译序</h1>
<ul>
<li><p>在人的精神或人格中，基本或基础性的东西乃是伊德所代表的潜意识。无论自我还是超自我均派生自它。所以潜意识是第一性的，意识是第二性的，每一种心理过程最初都是潜意识的，只是经过一定条件和一定时间，才发展成为意识的。但是潜意识的心理过程并不一定都能变成有意识的心理过程。而有意识的心理现象往往是虚假的、象征性的，其真正面目、动机、目的只有通过精神分析，求之于潜意识这个特殊的精神领域。弗洛伊德的伟大贡献之一，就在于把心理学的研究范围扩大到了潜意识的领域。</p></li>
<li><p>荣格认为，人的心理是通过进化而预先确定了的。个人因而同往昔联结到了一起，不仅与自己童年的往昔，更重要的是还与种族的往昔相联结，甚至还与有机界的整个漫长的进化过程相联结。这一往昔，并不只是个人的潜意识，而主要是“集体的”潜意识。集体潜意识的发现，是荣格的卓越成就，是心理学史上的一座里程碑。</p></li>
<li><p>弗洛伊德所发现的潜意识，实际上只是“个人潜意识”，是潜意识中的一部分，潜意识中的“集体潜意识”，才是一个包容更广的天地。</p></li>
<li><p>集体潜意识的发现扩大了人们对人的精神与心理的了解。集体潜意识与个人潜意识一样，也是一个贮存所，它所贮存的是大量初始的或本源性的潜在意象。集体潜意识是一种心灵虚像，它只有与相对应的客观事物相结合，才能成为意识中的实在。它犹如一个公式，是一种“没有内容的形式”，虽然是虚的，但一与代入的具体内容相结合，就会在实际中发生作用。因此后天习得的经验越多，潜在于潜意识中的虚像得以显现的机会便越多。教育与学习上的机会与环境越丰富，集体潜意识的各方面便可以变得个性化并成为自觉的意识。</p></li>
</ul></section><section id="绪论" class="level1 unnumbered"><h1 class="unnumbered">绪论</h1>
<ul>
<li><p>他那些主观性的表述只有对于有相似体验的人来说才是可以接受的——或用另一种方式来说，只对在其精神里上帝的形象带有着同样的或相似的特征的那些人才是可以接受的。</p></li>
<li><p>这本‘自传’是我一生的记载，是从我据我的科学研究中所获得的知识来观察的。这二者是一回事，因此这本书对那些不懂得或不理解我的科学观点的人们提出了很高要求。我的一生在某种意义上是我所写的一切的结晶而不是相反。我存在的方式及我写作的方式是一个整体。我的所有观念及我所有的努力就是我本人的写照。因此，这本‘自传’只是‘我’这个字上的一‘点’就是了。”</p></li>
<li><p>荣格是不断地以新的及不同的方式来定义他的概念的，因为他感到，作出终极性定义是不可能的。他认为明智的做法是让总是附于精神现实的各种无法解释的要素像谜或神秘的东西那样原封不动地保留着为好。</p></li>
</ul></section><section id="序言" class="level1 unnumbered"><h1 class="unnumbered">序言</h1>
<ul>
<li><p>到了最后，在我一生中唯一值得讲述的事件，是那永远不会毁灭的世界闯进了这个转变性的世界的那些事件。这就是何以我主要谈些内心体验的原因，这其中便包括了我的各种梦及幻觉。</p></li>
<li><p>我们是一种我们所无法控制的或只是部分地有能力加以引导的精神过程。因此，对于我们自己或我们的生命，我们无法拥有任何终极性的判断。我们要是拥有，那我们就会无所不知了——但这最多只不过是一种自以为是的借口而已。在心底处，我们是决不会知道这一切到底是怎么回事的。一个人的生命的故事始于某处，始于某个我们碰巧记得的特定的某一点；而且甚至就在那时，它就已经是高度复杂的了。我们并不知道生命的结果将会是什么。因此，这个故事是没有开头的，而其结局也就只能含含糊糊地加以暗示而已。</p></li>
</ul></section><section id="童年" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 童年</h1>
<ul>
<li><p>这一类姑娘后来成了我潜意识中异性人格化的一个组成部分。她所传达的那种既生疏又始终为人所认识的感觉，是后来在我心中象征女性本质的那个形象的一种特征。</p></li>
<li><p>对于这些行为的意义，或者究竟该怎样解释它们，我毫不在意。我满足于有一种安全感，满足于占有某种别人不知道而又无法获得的东西。这是一种永远不能背叛的秘密，因为我生命的安全由它掌握。为什么如此，我没有问过自己。事情就是这样。</p></li>
</ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Psychology</category>
  <guid>https://learn.shitao5.org/posts/20231228-rgzz/</guid>
  <pubDate>Thu, 28 Dec 2023 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20231228-rgzz/cover.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>何为良好生活</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20231228-hwlhdsh/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Paused. Current progress 6%.⏱</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/26363926/" class="uri">https://book.douban.com/subject/26363926/</a></li>
</ul>
</div>
</div>
<section id="序言" class="level1 unnumbered"><h1 class="unnumbered">序言</h1>
<ul>
<li><p>
我一直对自己期望不高，更希望的倒是有几个读者能与作者一样感到诚实的思考实是人生一大乐事。“生今之世，承诸圣之表章，经群英之辩难，我得以坐集千古之智，折中其间，岂不幸乎？”
</p></li>
</ul></section><section id="伦理与伦理学" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 伦理与伦理学</h1>
<ul>
<li><p>伦理和道德有一层细微而重要的区别：在说到伦理的时候，我们更多联系于特定的社会形态，而不同社会有个殊的伦理关系和伦理规范，而说到道德，我们倾向于把某些伦理规范从个殊的伦理关系中抽离出来，把道德视作某种独立的、普遍的东西。</p></li>
<li><p>在我看来，道德植根于伦理并与伦理生活交织在一起，伦理则植根于一般社会生活并与一般社会生活交织在一起。</p></li>
<li><p>哲学追索根本道理，而很多根本道理凝结在我们的语言之中。因此，哲学家在阐论其学说时，几乎都会用语言中的实例作证。</p></li>
</ul>


<!-- -->

</section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Philosophy</category>
  <guid>https://learn.shitao5.org/posts/20231228-hwlhdsh/</guid>
  <pubDate>Wed, 27 Dec 2023 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20231228-hwlhdsh/cover.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>我在通用汽车的岁月</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20231226-wztyqcdsy/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Paused. Current progress 6%.⏱</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/1435907/" class="uri">https://book.douban.com/subject/1435907/</a></li>
</ul>
</div>
</div>
<section id="导论" class="level1 unnumbered"><h1 class="unnumbered">导论</h1>
<ul>
<li><p>作为最大的私营工业企业——1962年，通用汽车公司拥有超过100万名股东，大约60万名雇员，92亿美元的资产，146亿美元的销售收入以及14.6亿美元的利润——通用汽车公司树大招风，也会因此成为某些人的政治目标。我很高兴能够碰到关于公司规模的问题，因为在我看来，一家企业的规模庞大是该企业业绩优异、富有竞争力的结果；而且，只有规模庞大的企业，才能够为广阔的国内市场和世界市场大批量提供诸如汽车、机车等产品。我们还必须意识到，这些产品的价格相对较高，即使是一家“小”汽车生产商也能够跻身于美国工业百强企业。</p></li>
<li><p>在任何一个行业中，想要永远保持非同寻常的成功或者想要维持远超其他企业的领导地位，有时比取得最初的成功或领导地位要难得多。</p></li>
<li><p>仅仅依靠组织结构的设计依然无法保证管理的有效性。负责组织管理及权力分配的人比组织结构本身更重要。即使是在一个分权的组织结构中，他们也可能将该组织转变为集权性质，甚至是独裁性质的组织。</p></li>
<li><p>变革意味着挑战，而应对变革的能力则是优质管理的标志。我们必须对在产品、需求及外部压力方面影响深远的变革做出回应，以维持通用汽车公司的成长和繁荣。实际上，通用汽车公司目前的管理工作就是迎接并处理好这个时代所特有的新问题。</p></li>
</ul></section><section id="第一部分" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 第一部分</h1>
<section id="重大的机遇1" class="level2" data-number="1.1"><h2 data-number="1.1" class="anchored" data-anchor-id="重大的机遇1">
<span class="header-section-number">1.1</span> 重大的机遇（1）</h2>


<!-- -->

</section></section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Management</category>
  <category>Autobiography</category>
  <guid>https://learn.shitao5.org/posts/20231226-wztyqcdsy/</guid>
  <pubDate>Mon, 25 Dec 2023 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20231226-wztyqcdsy/cover.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>苏世民</title>
  <dc:creator>Shitao5 </dc:creator>
  <link>https://learn.shitao5.org/posts/20240105-ssm/</link>
  <description><![CDATA[ <div class="callout callout-style-default callout-note callout-titled" title="Progress">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Progress
</div>
</div>
<div class="callout-body-container callout-body">
<p>Learning Progress: Completed.🥳</p>
<!-- 读后感：[读《管理行为》](https://shitao5.org/posts/glxw/)。 -->
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled" title="Learning Source">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Learning Source
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li><a href="https://book.douban.com/subject/34952676/" class="uri">https://book.douban.com/subject/34952676/</a></li>
</ul>
</div>
</div>
<section id="条工作和生活原则" class="level1 unnumbered"><h1 class="unnumbered">25条工作和生活原则</h1>
<ul>
<li><p>在年轻的时候，请接受能为自己提供陡峭的学习曲线和艰苦的磨炼机会的工作。最初的工作是为人生打基础的，不要为了暂时的声望而轻易地接受一份工作。</p></li>
<li><p>处于困境中的人往往只关注自己的问题，而解决问题的途径通常在于你如何解决别人的问题。 （2023-12-06 星期三 22:59:01）</p></li>
<li><p>时间会对所有交易造成负面影响，有时甚至产生致命影响。一般情况下，等待的时间越久，意料之外的事情就越多。特别是在艰难的谈判中，要让所有人都在谈判桌上协商足够长的时间，以此达成协议。 （2023-12-06 星期三 23:02:24）</p></li>
<li><p>要在准备好时做出决定，而不是在压力之下。或为了达到个人目的，或因为内部政治斗争，或因为一些外部需求，其他人总会催促你做出决策。但几乎每次你都可以这么说：“我需要更多的时间来考虑这个问题。我想清楚了再回复你。”即使是在最艰难、最令人不快的情况下，这种策略也非常有效。 （2023-12-06 星期三 23:03:39）</p></li>
<li><p>尽可能雇用10分人才，因为他们会积极主动地感知问题、设计解决方案，并朝着新方向开展业务。他们还会吸引和雇用其他10分人才。10分人才做什么事都会得心应手。 （2023-12-06 星期三 23:04:33）</p></li>
</ul></section><section id="前言-所有并非天生" class="level1 unnumbered"><h1 class="unnumbered">前言 所有，并非天生</h1>
<ul>
<li><p>每个企业家都会有这样的体会：有时现实与自己想象的生活和事业之间存在巨大差距，这一差距会压得人喘不过气，几乎令人绝望。然而，一旦取得成功，人们只会看到成功的光环，如果失败了，他们也只会看到失败的黯淡，却很少有人关注到那些可能彻底改变人生轨迹的转折点。可正是在这些转折点上，我们学到了事业和人生中最重要的经验和教训。 （2023-12-06 星期三 23:10:29）</p></li>
<li><p>优秀的高管是在后天磨炼中成长起来的，没有人是天生的。他们吸收信息，研究既往经验，从错误中吸取教训，不断进步。 （2023-12-06 星期三 23:11:13）</p></li>
<li><p>一个人可以学着做管理者，甚至可以学着当领导者，却无法通过学习成为企业家。 （2023-12-09 星期六 15:58:36）</p></li>
</ul></section><section id="追梦" class="level1" data-number="1"><h1 data-number="1">
<span class="header-section-number">1</span> 追梦</h1>
<section id="小有作为" class="level2" data-number="1.1"><h2 data-number="1.1" class="anchored" data-anchor-id="小有作为">
<span class="header-section-number">1.1</span> 小有作为</h2>
<ul>
<li>
<p>我坚信，如果你足够渴望一件事物，即使没有条件，也总会找到方法达成所愿。只要你努力，只要你坚持，就会变不可能为可能，就会功到自然成。</p>
<p>但仅仅有欲望是不够的。追求高难度目标，有时难免会事与愿违、不得其所。这是志存高远的代价之一。 （2023-12-09 星期六 16:02:01）</p>
</li>
<li><p>我相信教育是一门学科。这门学科的目标是学习如何思考。一旦掌握了这一点，就可以将其应用于学习投身一项事业、学习欣赏艺术、学习阅读书籍。教育赋予我们能力，让我们欣赏上帝之手写就的千回百折的剧情——生活本身。在我们离开教室后，教育仍在继续。与朋友联系、参加俱乐部，这些都能增加我们的知识储备。事实上，学习伴随我们的终生。我和我的干事们只是希望在座的各位能够正确认识教育的目的，并在你们的余生中遵循教育的基本原则，不断质疑，持续思考。 （2023-12-09 星期六 16:07:03）</p></li>
<li><p>我还不确定自己想追求什么，虽然田径曾经塑造了我，但现在似乎已经不再是我达成理想的途径和方式了。 （2023-12-09 星期六 16:13:16）</p></li>
<li><p>我和小安东尼在阿宾顿的经历教会了我重要的一课，而我一生都在重复这一课：做大事和做小事的难度是一样的。两者都会消耗你的时间和精力，所以如果决心做事，就要做大事，要确保你的梦想值得追求，未来的收获可以配得上你的努力。 （2023-12-09 星期六 16:18:20）</p></li>
</ul></section><section id="一切都是相连的" class="level2" data-number="1.2"><h2 data-number="1.2" class="anchored" data-anchor-id="一切都是相连的">
<span class="header-section-number">1.2</span> 一切都是相连的</h2>
<ul>
<li><p>他告诉我，我可以做任何我想到的事情。他说，在人生的某些阶段，我们必须弄清楚自己是谁。越早认清自我越好，只有这样，我们才能找到适合自己的机会，而不是活在他人创造的梦幻中。但如果我要把自己有价值的理想变为现实，成为一个有信息大量流入的如电话交换机一般的人，那么我需要去赚钱。 （2023-12-10 星期日 00:55:02）</p></li>
<li><p>储备军的经历加深了我对等级制度的怀疑，也坚定了我在发现问题时挑战权威的信心。大家在波尔克堡不同的命运也让我意识到运气的重要性。无论你多么成功、聪明或勇敢，都有可能身陷困境。人们常常认为自己是唯一的现实，但每个个体都有自己的现实。见得越多，就越有可能理解他人的处境。 （2023-12-10 星期日 01:07:06）</p></li>
<li><p>我从军队中学到的另一条人生经验是，我们的服役人员所做出的承诺和牺牲必须毫无例外地得到尊重。 （2023-12-10 星期日 01:07:53）</p></li>
<li><p>我向自己保证，如果我经营一个组织，一定会尽可能降低人们与我见面的难度，我会一直实事求是，无论情况多么困难，只要你能够保持诚实、理性，能够解释自己的想法，就没有理由感到不自在。再聪明的人也无法单独解决所有问题，但是一群聪明的人如果能够彼此坦诚地沟通，就会战无不胜。 （2023-12-10 星期日 01:14:55）</p></li>
<li><p>在哈佛商学院的求学经历使我确信，虽然我在帝杰出师不利，但可能我还是适合做金融的。在我们研究的案例中，我能够发现模式、感知问题，也能提出潜在的解决方案，而不会迷失在数据中。课外活动加深了我对自己的认识——我喜欢和他人一起努力应对困难，甚至是完成不可能的挑战。尽管我在帝杰的开局很差，尽管我的数学技能平平（当时和现在都还是平均水平），但随着毕业的临近，我决定在华尔街再试一次。 （2023-12-12 星期二 07:15:03）</p></li>
<li><p>人生早先遇到的人、交到的朋友，总会在后来的人生中以另外的方式再次出现。 （2023-12-12 星期二 07:23:08）</p></li>
</ul></section><section id="我的成功面试规则" class="level2" data-number="1.3"><h2 data-number="1.3" class="anchored" data-anchor-id="我的成功面试规则">
<span class="header-section-number">1.3</span> 我的成功面试规则</h2>
<ul>
<li>
<p>任何企业家都需要具备诸多关键技能，其中最重要的技能也许就是可以高屋建瓴、客观公正地对人才进行评估。从早年在华尔街参加面试开始，我就一直在思考如何做好面试官。</p>
<p>在金融这个行业，能力出色、雄心勃勃的人比比皆是，他们希望成就大业、雁过留声。然而只有能力是远远不够的。在对黑石候选人进行面试时，我会分析这个人是否符合我们的文化。至少，这个人得通过机场测试：如果我们乘坐的航班延误，我是否愿意跟这个人一起在机场等候？ （2023-12-12 星期二 07:25:55）</p>
</li>
<li><p>事实上，这些都是为了评估他们应对不确定性问题的能力。金融圈，尤其是投资界，是一个变化万千的世界，从业人员必须迅速适应新的信息、人员和情况。如果候选人不能在一场对话中表现出与人共鸣、深度交流、随机应变和转换话题的能力，那么这个人在黑石也应该不会表现很好。 （2023-12-12 星期二 07:35:15）</p></li>
</ul></section><section id="实践是学习的最佳路径" class="level2" data-number="1.4"><h2 data-number="1.4" class="anchored" data-anchor-id="实践是学习的最佳路径">
<span class="header-section-number">1.4</span> 实践是学习的最佳路径</h2>
<ul>
<li><p>投资者一直在寻找极好的投资，你越是降低他们决策的难度，每个人获得的利益就越大。 （2023-12-15 星期五 20:47:15）</p></li>
<li>
<p>当杰克开始跟我学习金融知识时，我只花了一分钟时间，就发现雷金纳德·琼斯的判断完全正确：杰克正是最佳人选。和杰克·韦尔奇一起工作，大脑就好像被接上了一个吸尘器，他会吸走你知道的一切。我再也没有见过像他这样的人，他对学习充满渴望，孜孜以求，总是无休无止地提出这样那样的问题；他善于思考，思维敏捷，能立刻理解一个想法与另一个想法之间的联系，即使这两个想法对他来说都是全新的知识。他就像人猿泰山似的以极快的速度抓着藤蔓穿梭于树木之间，从不失手，学的比我教的还快。</p>
<p>通过了解杰克，观察他的行动，我更为确信，商业中最重要的资产就是信息。你知道得越多，你拥有的视角越多，可以建立的连接就越多，进行预测的能力就越强。 （2023-12-15 星期五 20:54:17）</p>
</li>
<li><p>如果你以一所优秀的学校或一家大公司为起点，与你们这一代最优秀的人交往，你将来就会不断地再次遇到他们。我在耶鲁大学、哈佛商学院、陆军预备队和华尔街早期结识的许多朋友现在都还是我的朋友。我在生命早期交到的朋友，用他们的信任和理解，以我无法预测的方式极大丰富了我的生活。 （2023-12-15 星期五 20:54:53）</p></li>
</ul></section><section id="所有交易都暗藏危机" class="level2" data-number="1.5"><h2 data-number="1.5" class="anchored" data-anchor-id="所有交易都暗藏危机">
<span class="header-section-number">1.5</span> 所有交易都暗藏危机</h2>
<ul>
<li>
<p>刚进入金融行业时，我对工作压力没有足够的思想准备。其实，每次谈判中的每一节点都是一场战斗，有人赢，也有人输。这个行业的人对瓜分蛋糕、给每人都分一点儿不感兴趣，他们想要的是整个蛋糕。我留意到，当周围人的音量飙升、脾气爆发，而此时又需要我做决策时，我就会心跳变快，呼吸变浅，工作效率变缓，自我认知能力和应变能力的把控也随之下降。</p>
<p>我找到的缓解压力的方法是专注于自己的呼吸，减缓呼吸速度，放松自己的肩膀，直到呼吸变得深长。这一做法效果惊人，我的思路渐渐变得清晰，对眼前形势的认识变得更为客观和理性，也更加清楚自己如何才能获得胜利。 （2023-12-15 星期五 23:09:54）</p>
</li>
<li><p>在压力管理方面，我学到的另一个诀窍就是花点时间让自己舒缓下来。人们总愿意给我一点额外的时间，这似乎能够让他们放下心来。一旦我准备好，他们就会更加渴望听到我要说的话。所以我停顿了一下，然后开始。 （2023-12-15 星期五 23:14:08）</p></li>
<li><p>这是你职业生涯中一个巨大的突破。很多人都会嫉恨你。不过，别担心。你与他们不一样，不要让这些事情干扰到你！ （2023-12-15 星期五 23:20:31）</p></li>
<li><p>你现在有责任在公开场合发表自己的意见。当看到可以纠正的错误时，你要大胆地说出来，不要畏缩，因为这是一些人的社会责任。我是其中一个，你现在也是其中一个。 （2023-12-15 星期五 23:19:19）</p></li>
</ul></section><section id="寻找竞争最小机会最大的领域" class="level2" data-number="1.6"><h2 data-number="1.6" class="anchored" data-anchor-id="寻找竞争最小机会最大的领域">
<span class="header-section-number">1.6</span> 寻找竞争最小、机会最大的领域</h2>
<ul>
<li><p>如果每天要花12个小时办公，那么我希望自己的办公室能够帮我疏解工作带来的一切心理压力，是一个舒舒服服的空间，就像英式房子里漂亮的起居室或图书馆。 （2023-12-15 星期五 23:22:31）</p></li>
<li><p>对我而言，倾听他人的看法是理所应当的做法，这却让我在华尔街独树一帜。在与他人交往过程中，我从不急于表达自己的观点，极力推销自己手里的东西，而总是选择倾听。我会静静等待，关注对方要什么、想什么，然后着手满足对方的需求。我很少在会议上做笔记。我只是非常关注对方说话的内容和表达的方式。如果可以的话，我会尝试找到一些可以与对方产生联系的触点，一些一致之处，或一些共同的兴趣或经历，让公对公的交流变得更富有人情味。这种做法听上去是常识，但在实践中，显然很少有人能够做到。 （2023-12-15 星期五 23:28:07）</p></li>
<li><p>人们最感兴趣的话题永远是“自己的问题”。如果你能发现对方的问题所在，并提出解决方案，那么他们一定愿意跟你沟通，无论他们的等级或地位如何。问题越困难，解决方案越少，你的建议就越有价值。为人人避之不及的问题提供解决方案，才是竞争最小、机会最大的领域。 （2023-12-15 星期五 23:29:19）</p></li>
<li><p>我刚开始在雷曼兄弟工作时，一位合伙人告诉我：“在雷曼兄弟，没有人会在背后捅你。他们会走到你面前捅你。”公司内部充满争斗，人人为己。我从公司的建筑风格看出了这点，也在哈佛商学院的论文里写过。但我曾经喜欢过这一点。所有内斗都有一丝黑色幽默的味道。 （2023-12-15 星期五 23:39:10）</p></li>
<li><p>那时，我已经非常了解自己了。从高中到耶鲁大学、哈佛商学院，以及在雷曼兄弟一次又一次的经历，事实证明，几乎任何困难都压不倒我。我可以构思出有价值的伟大设想，并把设想变为现实。阿姆斯特朗教练让我理解了坚持的价值，他教导我，额外的付出一定会换来意外的收获，每次都要让我多跑几英里，让我付出额外的努力。日久天长，日积月累，这些付出逐渐变成了一种志在必得的信念，一种锲而不舍的精神。这就是我无形的资产，当我需要的时候它就会在那里供我撷取，取之不尽，用之不竭。此时此刻，我已经想好利用这些无形的资产进行怎样的投资，以此推进我的职业生涯。 （2023-12-15 星期五 23:42:44）</p></li>
</ul></section></section><section id="决策" class="level1" data-number="2"><h1 data-number="2">
<span class="header-section-number">2</span> 决策</h1>
<section id="为人所不为为人所不能" class="level2" data-number="2.1"><h2 data-number="2.1" class="anchored" data-anchor-id="为人所不为为人所不能">
<span class="header-section-number">2.1</span> 为人所不为，为人所不能</h2>
<ul>
<li><p>通过观察父亲经营小店的做法和得失，以及凭借后来为很多企业和企业家提供咨询建议的经验，我得出了关于创业的重要结论：创立和运营小企业的难度和大企业相差无几。一个企业的创立，无论规模大小，都有一个从无到有的过程，你会承受相同的经济负担和心理压力。筹集资金并找到合适人才的难度也同样大。在同样的困难和压力面前，要确保创业成功，唯一的办法就是全身心的投入。因此，如果你要将自己的生命奉献给一个公司，就应该选择一个发展潜力巨大的企业。 （2023-12-16 星期六 01:03:16）</p></li>
<li><p>在金融界，突如其来的运气逆转，一笔糟糕交易，一笔不良投资，都可能将你击垮。我们不会在一艘随时都有可能倾覆的小船上开始创业之旅。我们希望因卓越而广受赞誉，而不是靠勇猛而草率起航。 （2023-12-16 星期六 01:05:44）</p></li>
<li><p>典型的杠杆收购是这样的：一个投资者决定收购一家公司，部分资金自付，类似于购房的首付款，剩余的资金进行借款，即加杠杆。如果被收购的公司是上市公司，收购后，公司就会退市，其股份也会私有化，变为私募股权。公司通过自己的现金流支付其债务利息，而为了公司发展，投资者会改善企业运营的各个方面。投资者收取管理费，在投资最终变现时，获得部分利润。投资者所采取的运营改进措施包括：提高制造、能源利用和采购效率，新产品线投产，新市场拓展，技术升级以及公司管理团队的领导水平提升。几年之后，如果这些努力能够获得成功，公司就会取得长足发展，投资者可以以高于收购价格的定价将公司出售，或者可能再次使公司上市，从而获得原始股权投资的利润。这就是杠杆收购的基本主题，围绕这个主题可以衍生很多变化，但基础不会变化。 （2023-12-16 星期六 01:08:47）</p></li>
<li><p>即使经济衰退，我们也可以幸存下来，如果幸运的话，甚至还会发现更多的机会，因为恐慌的人会以低价出售他们的优质资产。 （2023-12-16 星期六 01:11:48）</p></li>
<li><p>得8分的人是任务执行者，得9分的人非常擅长执行和制订一流策略。如果公司都是9分人才，就可以获得成功。但10分人才，无须得到指令，就能主动发现问题、设计解决方案，并将业务推向新的方向。10分人才能够为企业带来源源不断的收益。 （2023-12-16 星期六 01:19:45）</p></li>
<li><p>创业的成败往往取决于时机。创业太早，客户还没准备好。创业太晚，竞争对手又太多。 （2023-12-17 星期日 23:25:04）</p></li>
<li><p>不是每个人都喜欢成为大型公司的一部分。在大公司工作，职员会失去彼此认识的亲密感，也感觉不到是在为一个整体连贯的实体工作，他们会从灵活团队的一员变为庞大的官僚机构的一部分。 （2023-12-18 星期一 23:18:37）</p></li>
<li><p>我和彼得相信，大型企业的文化变化会导致优秀人才和伟大创意的流失。如果这些人才与我们类似，那么他们会另寻出路。我们要为接受这样的人才做好准备。 （2023-12-18 星期一 23:19:16）</p></li>
</ul></section><section id="保持开放思维抓住罕见机会" class="level2" data-number="2.2"><h2 data-number="2.2" class="anchored" data-anchor-id="保持开放思维抓住罕见机会">
<span class="header-section-number">2.2</span> 保持开放思维，抓住罕见机会</h2>
<ul>
<li><p>我体悟到一个实实在在的道理：无论我们之前取得了什么成就，现在，我们都是一家初创企业。我已经深深体会到创业维艰，而我尚未体验到的是，所有烦琐庞杂的工作，我用铅笔和滑尺建立自己的金融模型所耗费的职业生涯，我从同事那里学到的所有与金融有关的知识和技能，都即将显现其宝贵价值。 （2023-12-18 星期一 23:39:34）</p></li>
<li><p>我开始在投行工作，后来自己做投资，在这个过程中，我发现问题越难，竞争就越有限。如果问题很简单，那么愿意帮忙解决的人总会很多。但如果问题很棘手，大家都避之唯恐不及。可以解决此类问题的人非常罕见。有难题的人会找你，出大价钱让你解决问题。为人所不为，为人所不能，以此建立自己的声誉。对于两个试图寻求突破的企业家来说，解决困难问题将成为自我证明的最佳方式。 （2023-12-18 星期一 23:40:58）</p></li>
<li><p>初入职场，我就像其他大多数雄心勃勃的年轻人一样：我相信成功是一条直线。作为婴儿潮的一代，我在成长过程中，看到的只是发展和机遇。成功似乎是必然的。但是，在经历了20世纪70年代和80年代初的经济起伏后，我逐渐明白，成功就是充分利用你无法预测的那些罕见的机会，但抓住这样机会的前提是你必须时刻保持开放的思维、高度的警觉和严阵以待的姿态，并愿意接受重大变革。 （2023-12-18 星期一 23:47:14）</p></li>
<li><p>作为营销人员，我学到，仅靠一次推销是不行的。你对事物存在信念，但并不能保证其他人也这样。你必须一遍又一遍地推销你的愿景。大多数人不喜欢改变，你必须用你的论点和个人魅力压倒他们。如果你相信你推销的东西，对方却拒绝，你应该假设他们并没有完全理解，所以你要再给他们一次机会。 （2023-12-18 星期一 23:48:14）</p></li>
</ul></section><section id="独辟蹊径" class="level2" data-number="2.3"><h2 data-number="2.3" class="anchored" data-anchor-id="独辟蹊径">
<span class="header-section-number">2.3</span> 独辟蹊径</h2>
<ul>
<li><p>处于困境中的人往往只专注于他们自己的问题，而使自己脱困的途径通常在于解决别人的问题。 （2023-12-23 星期六 14:22:45）</p></li>
<li><p>金融界有一种说法：时间会对所有交易产生负面影响。等待的时间越长，越有可能出现意料之外的棘手事件。我讨厌拖泥带水，喜欢速战速决。即使任务不紧急，我也希望尽快完成任务，以避免因为延迟而带来不必要的风险。 （2023-12-23 星期六 14:28:45）</p></li>
</ul></section><section id="不要错过良机" class="level2" data-number="2.4"><h2 data-number="2.4" class="anchored" data-anchor-id="不要错过良机">
<span class="header-section-number">2.4</span> 不要错过良机</h2>
<ul>
<li><p>在黑石创立之初，我和彼得就达成了一致意见：公司永远不会进行恶意交易。我们认为，企业是由值得尊重的人组成的。作为收购方，如果一味地大幅削减成本，不断从企业抽取资金，直到企业破产，那么你会伤害到员工、他们的家庭和所在的社区。你的声誉也会受损，体面的投资者会对你嗤之以鼻，并避之不及。但是如果你投入资金以改善所收购的公司，那么公司的日益强大不仅会使员工受益，也会让你的声誉得到提升，这些将会给你带来更高的长期回报。我们把这一理念称为“恶意环境中的友好交易”，还把这句话放在了《华尔街日报》的广告中。 （2023-12-23 星期六 14:31:53）</p></li>
<li><p>为了取得成功，你必须有勇气打破边界，进军自己无权进入的行业和领域。如果失败了，你就摇摇头，承认失误和不足，然后从自己的愚蠢中吸取教训。仅仅凭借锲而不舍的意志力，你就可以让世界筋疲力尽，做出让步，把你想要的东西给你。 （2023-12-23 星期六 14:44:22）</p></li>
</ul></section><section id="周期通过市场涨落判断投资机会" class="level2" data-number="2.5"><h2 data-number="2.5" class="anchored" data-anchor-id="周期通过市场涨落判断投资机会">
<span class="header-section-number">2.5</span> 周期：通过市场涨落判断投资机会</h2>
<ul>
<li><p>任何投资的成功与否在很大程度上取决于所处经济周期的节点。周期会对企业的成长轨迹、估值及潜在回报率造成重大影响。 （2023-12-26 星期二 00:29:36）</p></li>
<li><p>要确定触底的具体时间并非易事，投资者最好不要轻易尝试。原因在于，经济真正从衰退中走出来通常需要一到两年的时间。即使市场开始出现转机，资产价值仍需要一段时间才能恢复。这意味着如果在市场触底前后进行投资，那么投资者可能在一段时间内无法获得投资回报。 （2023-12-26 星期二 00:31:43）</p></li>
<li><p>避免这种情况的方法就是，当价值从低点回升至少10%时再开始进行投资。随着经济获得动力，资产价值往往会随之上扬。最好放弃市场刚开始复苏时10%~15%的涨幅，以确保在恰当的时间买入资产。 （2023-12-26 星期二 00:32:24）</p></li>
<li><p>从表面上看，随大流可以避免遭人指责。这些投资者往往不会在市场底部附近投资，而是在市场顶部进行投资，但这样做恰恰与“赚钱”的投资理念背道而驰。他们喜欢看着资产价值上扬，这样心中会感觉舒适而安全。价格越高，越多投资者相信资产会继续升值。出于同样的原因，在一个周期的底部前后，新企业的上市几乎是不可能的，但随着周期的发展，IPO的数量、规模和估值都会出现爆炸式增长。 （2023-12-26 星期二 00:33:32）</p></li>
</ul></section><section id="如何做正确的决策" class="level2" data-number="2.6"><h2 data-number="2.6" class="anchored" data-anchor-id="如何做正确的决策">
<span class="header-section-number">2.6</span> 如何做正确的决策</h2>
<ul>
<li><p>对任何组织而言，失败是最好的老师。一个企业绝对不能掩饰自己的失败，而是要进行开诚布公的讨论，分析导致错误的原因，以此学习新的决策规则。失败可能是巨大的礼物，它就像催化剂可以改变一个组织的发展进程，造就组织未来的成功。 （2023-12-26 星期二 23:57:38）</p></li>
<li><p>金融圈到处都是充满魅力的人。他们的演示材料做得漂亮，嘴皮子也非常利索，思路和语速快到让人跟不上，你必须要叫停这样的表演。为了保护企业和组织，你需要打造决策体系、改善决策质量。决策系统不应再受制于一个人的能力、感受和弱点。企业需要摒弃“单人决策”的做法，审查并收紧企业流程，制定规则来剔除投资流程中的个人化因素。 （2023-12-26 星期二 23:59:02）</p></li>
<li><p>我开始认识到投资应该像没有投球时限的篮球赛，只要手里有球，我们需要做的就是一直不停地传球，直到确定可以得分的时候再出手。其他球队可能会失去耐心，在三分球线外失去重心后，投出一些命中率低的球，就像我们的埃德科姆交易一样。而黑石不一样，我们要继续传球，继续观察，直到把球传给站在篮筐正下方身高7英尺的中锋手中。我们要执着而认真地分析每个潜在交易的各个不利因素，直到确保万无一失。 （2023-12-27 星期三 00:00:51）</p></li>
<li><p>接下来，黑石颁布规定：任何提案都必须以书面备忘录的形式提交，备忘录必须完整翔实，并至少提前两天提供给参会人员，以便大家对其进行细致理性的评估。之所以要求至少提前两天，是因为这样研究备忘录的人可以有时间进行标注、发现漏洞、梳理相关问题。我们还规定，除非有重大的后续发展，否则不得在会议上对备忘录进行任何补充。我们不希望开会的时候还有新增材料传来传去。 （2023-12-27 星期三 00:02:06）</p></li>
<li><p>洞悉人的心理是我作为投资者的优势之一。我不需要记住分析中的每个数字。我可以观察和聆听那些知道具体细节的人，通过他们的姿势或语调判断他们的感受。 （2023-12-27 星期三 00:04:26）</p></li>
</ul></section><section id="黑石的人才战略" class="level2" data-number="2.7"><h2 data-number="2.7" class="anchored" data-anchor-id="黑石的人才战略">
<span class="header-section-number">2.7</span> 黑石的人才战略</h2>
<ul>
<li><p>在黑石，投资决策的核心在于程序严格、冷静稳健的风险评估。这不仅是一个流程，更是一种思维方式，也是黑石文化不可分割的一部分。 （2023-12-27 星期三 07:05:58）</p></li>
<li><p>黑石投资委员会的职责是发现交易、探讨交易，但没有批准权。因为是否推进业务的决策是共同制定的，所以没有人会仅仅因为个人喜好而兜售一笔交易。 （2023-12-27 星期三 07:09:28）</p></li>
<li><p>由于黑石还没有设立成体系的部门和岗位，我需要亲自参与面试，和新晋员工一起工作。在这个过程中，我发现了金融业的一个真理：这个行业鼓励人们自欺欺人。大家认为自己很厉害，也会告诉你他们很棒，上一份工作从来没有搞砸过，现在只是在寻求“更多的机会”。在聘用他们后，你就会发现，他们一般能力都不行。于是，你必须让他们离职，再找更多的候选人。你必须再从第二组人中进行筛选，可能到了第三组才能找到自己想要的人。而第一组和第二组的人会告诉其他人，在你的公司工作太难了，这进一步增加了招聘公司的难度。 （2023-12-27 星期三 07:11:39）</p></li>
<li><p>1991年，黑石招聘了首批MBA毕业生，我认为这是公司开始优化招聘和培训流程的机会。这一刻我就知道黑石必将成功——这些把职业生涯交给我们的前途无量的年轻人，就是黑石的未来。为了回报他们，我们有责任打造一种企业文化，让他们能够在这里实现自己的抱负。 （2023-12-27 星期三 07:14:53）</p></li>
<li><p>卓越意味着一切都要做到100%，这意味着“零失误”。黑石与学校不同，在学校，答对95%的题就可以拿到A。在黑石，对我们的投资人来说，5%的表现不佳都意味着巨大的损失。 （2023-12-27 星期三 07:16:35）</p></li>
<li><p>不要浪费自己的时间重新制造轮子。你周围有很多现成的轮子，在等着你加大马力、提高转速，朝着新的方向推进。 （2023-12-27 星期三 07:17:13）</p></li>
<li><p>我给新人发出警告：“如果我在黑石抓住你们做类似的事情，那么我会亲自把你们送进监狱。”我这样说，不是为了吓唬他们，而是为了帮助他们。我在消除他们的疑惑，让他们更容易做出正确的决策。 （2023-12-27 星期三 07:19:46）</p></li>
</ul></section></section><section id="掌控" class="level1" data-number="3"><h1 data-number="3">
<span class="header-section-number">3</span> 掌控</h1>
<section id="我的经验与教训" class="level2" data-number="3.1"><h2 data-number="3.1" class="anchored" data-anchor-id="我的经验与教训">
<span class="header-section-number">3.1</span> 我的经验与教训</h2>
<ul>
<li><p>作为一个缺乏经验的首席执行官，我犯下了错误，任由我们之间的差异不断扩大。我坚持不能稀释黑石持有的股权，因为我认为尊重原始协议的条款是道德原则。其实，我应该认识到，当情况发生变化、业务表现极好时，调整有时也是必要的。 （2023-12-30 星期六 18:20:18）</p></li>
<li><p>当第一次想到增加黑石的业务线时，我们的宗旨就是要有选择性地进入新领域。新业务不仅本身要表现出色，还能让整个公司获得更多信息、知识和技能。我们相信，我们从不同的业务领域学到的东西越多，公司的发展就会越好。这是哈佛商学院传授的一个理念：在商界，一切都是相互联系的。与竞争对手相比，我们寻求机会、分析市场的角度和方法会有所不同。我们的视角会更加多样、分析会更为深入。我们公司的信息来源越多，我们知道的就越多。知道的越多，我们就越聪明，想要与我们合作的人就越多。 （2023-12-30 星期六 18:21:22）</p></li>
<li><p>跟不认识的人聊天，无论聊什么，都应当始终保持耐心，持续提问，直到找到一个共同点。 （2023-12-30 星期六 18:24:31）</p></li>
<li><p>当进入新市场时，公司做出的每个选择都是一种信号，包括聘用的人员、租用的办公室。这些都是公司品牌的重要组成部分。我下定决心让新的欧洲总部充分体现黑石的价值观：追求卓越、诚实守信、关怀所有与我们有关的人——我们的员工和投资人。 （2023-12-30 星期六 18:29:18）</p></li>
<li><p>如果办公室不完美，我是不会罢休的。拥有美丽的办公空间，吸引最优秀的人才，让客户对我们的能力更有信心，这些回报要远远超过支付额外费用来完成交易的成本。要想获得自己想要的东西，最好的方法就是先弄清楚能提供给你这个东西的人想要什么。我消除了业主对租金下降的担忧，于是得到了我想要的办公空间。 （2023-12-30 星期六 18:32:19）</p></li>
<li><p>这样的相遇也再次提醒了我：在生命早期无意中结识的人，会在生命后期不断出现，并给你带来惊喜。 （2023-12-30 星期六 23:59:22）</p></li>
<li><p>人生中重要的一点是始终对新体验持开放态度，即使这些体验并非完全在自己的规划内。 （2023-12-31 星期日 00:00:32）</p></li>
</ul></section><section id="创业维艰" class="level2" data-number="3.2"><h2 data-number="3.2" class="anchored" data-anchor-id="创业维艰">
<span class="header-section-number">3.2</span> 创业维艰</h2>
<ul>
<li><p>创业是那样艰辛、那样劳心费力，所以我从来不理解为什么有人想成为“连续创业者”。一次就已经够难的了。 （2023-12-31 星期日 10:55:05）</p></li>
<li>
<p>如果你们想创业，就必须通过三项基本测试：</p>
<p>第一，你的设想必须足够宏大，足以值得你全身心投入。你要确保自己的创意有潜力发展成一个规模巨大的企业。</p>
<p>第二，企业的产品或服务应该是独一无二的。当人们看到你提供的东西时，他们应该对自己说：“我的天哪，我需要这个。我一直在等待这个东西，真的很吸引我。”如果你的产品和服务没有让人喜出望外、拍案叫绝，你就是在浪费自己的时间。</p>
<p>第三，时机必须是正确的。这个世界其实不喜欢开拓者，所以如果进入市场太早，失败的风险就会很高。你所瞄准的市场应该有足够的发展势头，这样才能帮助你取得成功。</p>
<p>如果你通过这三项测试，那么你将拥有一个具有巨大潜力的企业。这个企业可以提供独特的产品或服务，也能够在合适的时间进入市场。然后，你必须做好准备，迎接痛苦。没有创业者会设想到未来的痛苦，也没有人想要痛苦，但现实就是，新事物的诞生必然伴随着阵痛，这是不可避免的。</p>
<p>真正的企业不是自然而然出现的。筹集资金和招募优秀人才非常困难。但是，即使公司规模很小、资源极为有限，找到合适的人也是重中之重的任务。初创企业通常无法获得最优秀的人才——他们在其他公司工作，拿着更高的薪酬。你必须要想方设法充分利用能招到的人。这至少意味着你要把标准一降再降，只问一个简单的问题：这个人是否像你一样，对壮大企业的使命抱有同样的热忱，愿意付出同样的努力？ （2023-12-31 星期日 10:56:24）</p>
</li>
<li><p>如果你充满雄心壮志，就必须为公司招募9分人才和10分人才，并委以重任。最后，创业要想成功，你必须是偏执狂，必须要认为自己的公司，无论现在规模大小，都始终是一家小公司。一旦你开始扩大规模、取得成功，挑战者就会出现，他们会拼尽全力抢走你的客户、打败你的公司。你认为自己取得了成功的一刻，就是公司最容易受到冲击的一刻。 （2023-12-31 星期日 11:00:29）</p></li>
</ul></section><section id="抓住每个跳动的音符" class="level2" data-number="3.3"><h2 data-number="3.3" class="anchored" data-anchor-id="抓住每个跳动的音符">
<span class="header-section-number">3.3</span> 抓住每个跳动的音符</h2>
<ul>
<li><p>我们当场决定不再推进西班牙的房屋交易。一些同事露出困惑的表情：印度的土地价格与西班牙公寓有什么关系？我有自己的逻辑——在日益全球化的经济中，必须能够找到一些10年前甚至两年前不存在的关联。现在，成本低廉、方便快捷的信贷几乎是无国界的，这些信贷在全球各地寻求机会。如果西班牙和印度出现房地产泡沫，那么其他国家也可能会出现。没必要在过热的市场买入价格过高的房地产。 （2023-12-31 星期日 11:03:43）</p></li>
<li><p>我一直把忧虑视为一种积极的心理活动，它可以开阔人的思路。由于忧虑，你在任何情况下都可以对不利因素进行准确识别，并采取措施消除其消极影响。我们建立了黑石，就是让我们能够有充分的原由去忧虑，有大量的机会搜集丰富的原始数据，这样我们就可以寻找异常情况和固有模式，不断提升我们获得、理解和运用知识的能力。在最好的状态下，忧虑是一种有趣好玩、引人入胜的情感体验，在这种时候，一个人的精力是高度集中的。 （2023-12-31 星期日 12:56:14）</p></li>
</ul></section><section id="规避风险稳赚不赔" class="level2" data-number="3.4"><h2 data-number="3.4" class="anchored" data-anchor-id="规避风险稳赚不赔">
<span class="header-section-number">3.4</span> 规避风险，稳赚不赔</h2>
<ul>
<li>作为家长，你一方面要努力工作，取得事业成功，另一方面还要陪伴家人，关心孩子的精神世界，两者需要平衡。身处其中，你不知道自己做得好不好，因为多年以后才能看到结果。回顾我60岁的生日之夜，那些跟我最亲近的人对我的记忆，我觉得自己做得不算差。 （2024-01-01 星期一 00:23:05）</li>
</ul></section><section id="推进上市" class="level2" data-number="3.5"><h2 data-number="3.5" class="anchored" data-anchor-id="推进上市">
<span class="header-section-number">3.5</span> 推进上市</h2>
<ul>
<li><p>我们不是唯一一家正在研究上市的同类公司。但如果要上市，我们就必须得是第一个。第一个进入市场的公司会吸引最多的资金，其他公司只能抢残羹冷炙了。 （2024-01-01 星期一 00:30:28）</p></li>
<li><p>水满则溢，在市场火爆的背后，必然会隐藏天大的危机。 （2024-01-01 星期一 00:42:18）</p></li>
<li><p>创业的初期，公司会跌宕起伏、充满变数，而在发展到某一个阶段后，创始人必须允许公司引入相关管理人才和系统，允许他人助推企业向前发展。 （2024-01-01 星期一 00:42:25）</p></li>
<li><p>投资原则 勿失良机 如果有机会不期而至，不要与其失之交臂，这体现了公司的投资原则：不要错过良机。 （2024-01-01 星期一 00:42:32）</p></li>
<li><p>如果有机会不期而至，不要与其失之交臂，这体现了公司的投资原则：不要错过良机。 （2024-01-01 星期一 00:42:37）</p></li>
</ul></section></section><section id="准则" class="level1" data-number="4"><h1 data-number="4">
<span class="header-section-number">4</span> 准则</h1>
<section id="做市场的朋友" class="level2" data-number="4.1"><h2 data-number="4.1" class="anchored" data-anchor-id="做市场的朋友">
<span class="header-section-number">4.1</span> 做市场的朋友</h2>
<ul>
<li><p>在埃德科姆交易失败后，我已经感受到了这种困境的痛苦，因为我必须确保黑石把贷款还给银行。如果当时我们没有以完全正确的方式来处理这个问题，那么在以后的交易中，我们会花费更多的时间和金钱，才能赢回信任。 （2024-01-01 星期一 11:16:41）</p></li>
<li><p>能源与房地产一样，都属于周期性行业。投资人必须要清楚，周期的低谷可能会很深很长，当市场达到顶峰时，也不能忘乎所以。 （2024-01-01 星期一 12:48:06）</p></li>
<li><p>这就是现实世界解决问题的方式：在遇到问题时，不是惊慌失措，急于宣布进入紧急状态，而是呼吁各方保持冷静，给大家一点时间，共同寻找解决问题的办法和途径。 （2024-01-01 星期一 13:09:04）</p></li>
</ul></section><section id="化危机为机遇" class="level2" data-number="4.2"><h2 data-number="4.2" class="anchored" data-anchor-id="化危机为机遇">
<span class="header-section-number">4.2</span> 化危机为机遇</h2>
<ul>
<li><p>生命之旅是漫长的，在他人需要的时候施以援手，这一偶然的善举往往会以最出乎意料的方式回报你，因为每个人都永远不会忘记那些在艰难时刻扶危济困的朋友。 （2024-01-01 星期一 13:40:28）</p></li>
<li><p>每年，我们都会组织各个业务部门的新人去外地团建，我们便想利用这个机会请托尼来鼓励他们，告诉他们一切都会好起来的，给他们以信心，让他们振作精神。但这不是托尼的风格，相反，他告诉这些新人，他们非常幸运，在职业生涯开始时，就能从这场历史性的经济危机中得到磨砺，如果他们够聪明，就会从中学到很多经验教训，并把学到的东西应用于自己的整个职业生涯。他说，成功会令人骄傲自满，不思进取。你只能从失败中学习，在逆境中成长。 （2024-01-01 星期一 13:46:57）</p></li>
<li><p>作为一名企业家，我了解到金融行业其实很简单——如果有人要求你提供新产品，那么这个人是地球上对这一产品唯一感兴趣的人的概率是零。如果有人向你提出这样的要求，那么这背后可能代表了一个巨大的机会。那些提出要求的人并不知道，他们只是在关注自己的需求。但是，如果这些需求具有合理性，而你又设计了满足这些需求的正确产品，那就可以对这种产品进行大范围推广，而你的竞争对手只能好奇你是怎么找到解决方案的。 （2024-01-01 星期一 13:58:37）</p></li>
</ul></section><section id="付出" class="level2" data-number="4.3"><h2 data-number="4.3" class="anchored" data-anchor-id="付出">
<span class="header-section-number">4.3</span> 付出</h2>
<ul>
<li><p>创业经历有一点很棒，那就是随着时间的推移，如果一切顺利，生活就会变得更简单容易。随着公司业务的成熟，周围人的素质和能力会日益提升，公司的各个系统也会变得更具一致性。公司一旦采取了正确的风险控制措施，找到了热爱和倾力于企业发展的接班人，便会声名鹊起，客户也会不速而至，良性循环随之加速。 （2024-01-01 星期一 16:27:14）</p></li>
<li><p>在确认项目细节的时候，我回想起自己接受高等教育时的情形——我经常在课堂上辛苦地学习，却得不到什么回馈和鼓励；我在华尔街的前几个月没有接受过任何培训或指导。那段经历告诉我，第一份工作表面声望的重要性远远比不上我丧失的学习技能的机会。我最终在雷曼兄弟找到了自己需要的东西，而在雷曼兄弟的经历成为我日后成就最高水平的基础。 （2024-01-01 星期一 16:35:10）</p></li>
</ul></section><section id="斡旋" class="level2" data-number="4.4"><h2 data-number="4.4" class="anchored" data-anchor-id="斡旋">
<span class="header-section-number">4.4</span> 斡旋</h2>
<ul>
<li><p>政治资本就像头发，剪了之后还会长，只要你做得对，最终会赢得理解和支持。 （2024-01-02 星期二 07:44:35）</p></li>
<li><p>无论政要的党派如何，他们都只是寻找答案的人。如果你有提供答案的能力，就应当提供答案。 （2024-01-02 星期二 07:44:58）</p></li>
<li><p>世界领袖与其他任何人都没有什么不同。如果你谈论困扰他们的问题，并提出一些有用的建议，他们就会倾听，无论这个人是民主党人还是共和党人、王子还是总理。 （2024-01-02 星期二 07:45:32）</p></li>
<li><p>作为投资者，我已经习惯于危机的出现。从雷曼兄弟的投资银行业务，到创立黑石、见证公司各个阶段的发展和变化，我不仅学会了应对危机，而且学会了为自己和客户制造危机，并以此为契机引发变革、改变现状，达到因破而立的目的。但企业高管恰恰相反，他们习惯于依赖规则、维持秩序，些许的风吹草动，都很容易让他们感到不适，尤其是当负面舆情出现，或面对客户施加压力时。他们非常厌恶被广为关注的公共事件卷入其中，尤其是像这种饱受争议、引发民愤的事件。 （2024-01-02 星期二 07:48:50）</p></li>
</ul></section><section id="识人用人" class="level2" data-number="4.5"><h2 data-number="4.5" class="anchored" data-anchor-id="识人用人">
<span class="header-section-number">4.5</span> 识人，用人</h2>
<ul>
<li><p>上一代管理团队掌权太久，下一代人会倦于漫长的等待，变得心灰意懒，不思进取，公司的发展会因此失去动力，而恢复公司发展势头总是比维持势头更难。因此，如果领导团体不希望出现倦怠情绪，那么在公司的动力、智力和竞争力尚未达到顶峰时，就要着手进 （2024-01-03 星期三 23:43:26）</p></li>
<li><p>她首先问我，黑石是如何保持创业精神的。我告诉她，诀窍是找到了很棒的人，让他们有机会把自己的专长发挥到极致。 （2024-01-03 星期三 23:50:19）</p></li>
<li><p>下属需要知道你非常欣赏他们，你也需要让他们自我感觉良好，这一点非常重要，因为自信是出色表现的基础。 （2024-01-03 星期三 23:51:34）</p></li>
</ul></section><section id="使命" class="level2" data-number="4.6"><h2 data-number="4.6" class="anchored" data-anchor-id="使命">
<span class="header-section-number">4.6</span> 使命</h2>
<ul>
<li><p>
我一直认为，教育是通往更加美好生活的阶梯。良好的教育可以改善受教育者的人生。我们每个人不仅有责任学习和传承知识，还有责任改进和发展知识，让知识对后代更有用、更有影响力。 （2024-01-04 星期四 07:20:58）
</p></li>
</ul></section><section id="结语" class="level2" data-number="4.7"><h2 data-number="4.7" class="anchored" data-anchor-id="结语">
<span class="header-section-number">4.7</span> 结语</h2>
<ul>
<li><p>建立和传播强大的公司文化既是企业发展的应有之义、必要之举，也可能是任何企业家和创始人所面临的最大挑战之一，但如果能找到正确的方法，打造企业文化也是最令人心满意足的事情之一。我对我们建立的公司感到无比自豪，每一天，当我看到黑石终身学习不怠、永远追求卓越和不断奋勉创新的企业文化变成实实在在的行动时，我就知道，黑石最好的时刻尚未来临。 （2024-01-04 星期四 07:23:28）</p></li>
<li><p>无论你的职业生涯如何开启，都要知道，你的生活不一定会直线前进，这一点非常重要。你必须认识到，这个世界是不可预测的。有时，甚至像你们这样有天赋的人也会遇到意料之外的磨难。在人的一生中，会难以避免地出现诸多困难和艰辛。面临挫折时，你必须要想方设法继续前进。能够定义你个人品质的，永远是你在逆境中展现的百折不回的精神和永不言弃的态度，而不是逆境本身。 （2024-01-04 星期四 07:24:46）</p></li>
<li><p>把时间和精力投入自己热爱的事物上。热情所至，卓越必成，单纯为了他人的敬仰和尊重而做事，则很少能带来成功。如果你对追求梦想充满热情，如果你能勇往直前，如果你以帮助他人为己任，你的人生就会充实而有意义，你也永远有机会建功立业、成就不凡。你为他人付出的善意和努力，最终会给你自己、你所爱的人以及整个社会带来福报。 （2024-01-04 星期四 07:25:05）</p></li>
</ul></section><section id="苏世民带领黑石走向巅峰的十大管理原则" class="level2 unnumbered"><h2 class="unnumbered anchored" data-anchor-id="苏世民带领黑石走向巅峰的十大管理原则">苏世民带领黑石走向巅峰的十大管理原则</h2>
<ol type="1">
<li><p>坚持成长就要不断提出问题，预测事件、审时度势，主动寻求进步和变革。</p></li>
<li><p>优秀的企业文化兼具规模优势和小公司的灵魂，员工可以自由表达想法。</p></li>
<li><p>不断创新，才能永远不被淘汰。</p></li>
<li><p>为了取得成功，你必须有勇气打破边界，进军自己无权进入的行业和领域。</p></li>
<li><p>谨慎做出决策：每一个微小的行为都有可能对其他人造成深远的影响，无论好坏。</p></li>
<li><p>对企业进行精英管理，追求卓越、保持开放、坚守诚信，并竭力聘用拥有同样信念的人。</p></li>
<li><p>创业的三项基本测试：你的设想必须足够宏大，企业的产品或服务应该是独一无二的，时机必须是正确的。</p></li>
<li><p>企业的一切要素都相互关联。企业如果要取得成功，那么每一个部门既需要独立运转，又需要与其他部门顺利协作。系统中任何一环出现问题都有可能造成亏损或破产。</p></li>
<li><p>创业的重要结论：创立和运营小企业的难度和大企业相差无几。一个企业的创立，无论规模大小，都有一个从无到有的过程，你会承受相同的经济负担和心理压力。筹集资金并找到合适人才的难度也同样大。在同样的困难和压力面前，要确保创业成功，唯一的办法就是全身心的投入。</p></li>
<li><p>企业“八九十”人才观：得8分的人是任务执行者，得9分的人非常擅长执行和制订一流策略。如果公司都是9分人才，就可以获得成功。但10分人才，无须得到指令，就能主动发现问题、设计解决方案，并将业务推向新的方向。10分人才能够为企业带来源源不断的收益。 （2024-01-04 星期四 07:27:01）</p></li>
</ol>


<!-- -->

</section></section><a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Management</category>
  <category>Autobiography</category>
  <guid>https://learn.shitao5.org/posts/20240105-ssm/</guid>
  <pubDate>Mon, 25 Dec 2023 16:00:00 GMT</pubDate>
  <media:content url="https://learn.shitao5.org/posts/20240105-ssm/cover.jpg" medium="image" type="image/jpeg"/>
</item>
</channel>
</rss>
