Skip to main content

3 Programming Paradigms

· 2 min read

Structured programming vs. OO programming vs. Functional programming

  1. Structured programming is discipline imposed upon direct transfer of control.

    1. Testability: software is like science: Science does not work by proving statements true, but rather by proving statements false. Structured programming forces us to recursively decompose a program into a set of small provable functions.
  2. OO programming is discipline imposed upon indirect transfer of control.

    1. Capsulation, inheritance, polymorphism(pointers to functions) are not unique to OO.
    2. But OO makes polymorphism safe and convenient to use. And then enable the powerful ==plugin architecture== with dependency inversion
      1. Source code dependencies and flow of control are typically the same. However, if we make them both depend on interfaces, dependency is inverted.
      2. Interfaces empower independent deployability. e.g. when deploying Solidity smart contracts, importing and using interfaces consume much less gases than doing so for the entire implementation.
  3. Functional programming: Immutability. is discipline imposed upon variable assignment.

    1. Why important? All race conditions, deadlock conditions, and concurrent update problems are due to mutable variables.
    2. ==Event sourcing== is a strategy wherein we store the transactions, but not the state. When state is required, we simply apply all the transactions from the beginning of time.

Thinking Software Architecture as Physical Buildings

· One min read

What is architecture?

Architecture is the shape of the software system. Thinking it as a big picture of physical buildings.

  • paradigms are bricks.
  • design principles are rooms.
  • components are buildings.

Together they serve a specific purpose, like a hospital is for curing patients and a school is for educating students.

Why do we need architecture?

Behavior vs. Structure

Every software system provides two different values to the stakeholders: behavior and structure. Software developers are responsible for ensuring that both those values remain high.

::Software architects are, by virtue of their job description, more focused on the structure of the system than on its features and functions.::

Ultimate Goal - ==saving human resources costs per feature==

Architecture serves the full lifecycle of the software system to make it easy to understand, develop, test, deploy, and operate. The goal is to minimize the human resources costs per business use-case.

Knowledge workers, how to take truly restful breaks?

· 2 min read

Why taking breaks?

  • Growth = Pressure + Taking Rests If people take too much pressure but too less rests, then they will burn out. If people take too many rests but too little pressure, then they cannot grow. The high performer should properly assign pressure and rests, in order to achieve high-speed yet sustainable growth.

What does "truly restful" mean?

The most treasurable resources of a knowledge worker are ==willpower and power of attention==. And truly restful breaks should recover these resources.

How to take truly restful breaks?

To recover willpower and power of attention, guiding principles are

  1. Fully switch off. Stay away from the Internet or anything that consumes willpower and attention.
  2. Take short breaks early and often.
  3. Get out of the office. Staff who did any work-related activities at lunch were rated as more fatigued by their colleagues at the end of the day.

Restful breaks vs Unrestful breaks

  1. Restful breaks: relaxation, take a nap, take a walk, social, etc.
  2. Unrestful breaks: eat something, cognition (read the news, check emails, play video games, watch videos, etc.)

Systematic solution

  • Short-term

    1. Being unfocused and get back to default mode network
      1. Take a walk/run outdoor.
      2. Return to nature.
      3. positive constructive daydreaming (PCD)
    2. Pretend to be someone else to encourage myself.
    3. Chat with friends.
    4. Drink a cup of coffee and take a nap immediately for 25 mins.
  • Mid-term

    1. Taking a few days off to recharge and no work at all.
  • Long-term

    1. meditation.
    2. sleep well. Good sleep makes skills and knowledge "grow" in the brain.

How to Get Lucky?

· 2 min read

Self-fulfilling prophecy: Believe that you are lucky, and you will be lucky because you will be more willing to explore opportunities, accept challenges, and persevere; rather than just feeling happy about good outcomes.

Lucky people have three personality traits:

  1. Extroverted
  2. Open-minded
  3. Relaxed (low neuroticism)

How to create good luck?

  1. Participate in new activities and experience new things
  2. Trust your intuition and interests
  3. Be optimistic, when playing soccer, take a few more shots, and you'll eventually score
  4. Be good at finding the silver lining in bad situations

What is the essence of good luck?

Creating opportunities, discovering opportunities, and having the courage to act

What does this have to do with mindfulness?

Mindfulness = stepping out of your subjective perspective and noticing the value of things around you

Buddhist perspective:

  • We oppose the "law of attraction" because fantasizing about good outcomes is actually a form of "greed."
  • We advocate for a systematic approach to probability, which is essentially "form is emptiness."
  • We encourage discovering good luck outside of routine tasks, which actually avoids "delusion."
  • We use holistic thinking to break normalizing biases, which is practicing "no-self."
  • So who says Buddhism is useless? If you truly excel in Buddhism, you wouldn't need to seek the Buddha for trivial matters like promotion and fortune.

Debounce, Throttle and RequestAnimationFrame

· One min read

These are web techniques to optimize UI events handling and make transitions smoother.

  • debounce: Grouping a sudden burst of events (like keystrokes) into a single one.
  • throttle: Guaranteeing a constant flow of executions every X milliseconds. Like checking every 200ms your scroll position to trigger a CSS animation.
  • requestAnimationFrame: a throttle alternative. When your function recalculates and renders elements on screen and you want to guarantee smooth changes or animations. Note: no IE9 support.

What is the difference between debounce and throttle? try here

Why It Is So Hard to Make a Good Decision

· 2 min read

Due to the spotlight effect: ==Daniel Kahneman says “A remarkable aspect of your mental life is that you are rarely stumped,” and mistakenly believe “what you see is all there is.”== People only see what they see and want to see, making it hard to step outside of their own perspective. Therefore, it's important to frequently ask oneself, "Why do I think this way?"

The author identifies four major challenges in the decision-making process and proposes solutions:

  1. Narrow framing <> Broaden options
  2. Confirmation bias <> Test assumptions with facts
  3. Short-term emotion <> View decisions from a distance
  4. Over-confidence <> Prepare for mistakes

Ray Dalio also states, recognize that 1) the biggest threat to good decision-making is harmful emotions, and 2) decision-making is a two-step process (first learning and then deciding).

Examples illustrating how people often make poor decisions:

  • Career choices, for instance, are often abandoned or regretted. An American Bar Association survey found that 44% of lawyers would recommend that a young person not pursue a career in law.
  • A study of 20,000 executive searches found that 40% of senior-level hires “are pushed out, fail or quit within 18 months.”
  • More than half of teachers quit their jobs within four years.
  • One study of corporate mergers and acquisitions—some of the highest-stakes decisions executives make—showed that 83% failed to create any value for shareholders.

What to do? Solve it with a process. ==In decision-making, process is six times more important than analysis.==

  • Because understanding our shortcomings is not enough to fix them.
  • People’s decision-making processes are generally too simplistic.
    • The final decision maker should be both the challenger and the ultimate judge.
    • Franklin’s moral algebra
    • Pros-and-cons

How to Predict Trends?

· 3 min read

There are two ways to gain a strategic high ground that is easy to defend and hard to attack:

  1. Independent innovation
  2. Riding the wave of change

It's easy to be a hindsight expert. To make predictions, one needs to deeply understand the past and present, see beyond the surface to grasp the essence, and thus be able to extrapolate to the next steps. Unfortunately, most people can only see the present.

For example, after the television emerged in the 1950s, everyone could realize that the movie industry was struggling, but very few could predict that the next step would be the rise of independent films. Independent filmmakers could break free from traditional studio ties and focus on making good films, as only good films can attract audiences to theaters.

Cisco rode three waves:

  1. Software and microprocessors
  2. Corporate networks
  3. IP networks

Common trends include:

  1. Skyrocketing fixed costs. For instance, capital-intensive big-budget films gave rise to major film companies. The development costs of large software systems led to the emergence of big software companies.
  2. Deregulation. For example, China's reform and opening up.
  3. Prediction biases.
    1. The illusion of growth. For instance, very few can predict when a business or economy peaks and begins to decline. Growth always has an endpoint; a person who has bought one television is unlikely to buy a second immediately. ==The faster sales grow, the quicker the market saturates.==
    2. The winner-takes-all illusion. Yes, there are winner-takes-all scenarios, but not necessarily; large companies can suffer from internal issues, and external changes can occur.
    3. The winner-always-wins illusion. For example, Yahoo.
  4. Incumbent effects: reluctance to reform for short-term gains, similar to the innovator's dilemma.
  5. ==Attractor state, or "endgame thinking," is the state the market should ideally reach.==

The attractor state is an interesting new concept. Here’s a detailed explanation. It differs from a company's vision in that a vision is unique to a company, while an attractor is the equilibrium that the entire market should achieve. It has two related concepts: accelerants and impediments.

  • A typical accelerant is the "proof effect," such as Napster making people suddenly realize that 2.5MB of music could be downloaded and shared, or Bitcoin making people aware that investing in virtual currencies could lead to wealth.
  • A typical impediment example is the public's fear and opposition to nuclear power plants, despite the knowledge that nuclear energy is the trend of the future.

Let’s analyze the newspaper industry.

Take The New York Times as an example; the printing costs of newspapers are about two to three times the subscription revenue, with printing costs primarily covered by advertising. Since 2009, two problems have emerged: the rise of easily accessible new media leading to a decline in newspaper readership, and the loss of advertising to Google.

Differentiation in news media has three dimensions: space, frequency, and depth. The author of this book believes that the market's attractor leans towards specialization in these niches rather than being broad and comprehensive. In the era of internet + newspapers, from a cost-reduction perspective, The New York Times should leverage its brand to collaborate widely with various information sources rather than relying on a small number of professional journalists. The more precise the readership, the more advertising revenue can be generated.

How to Quickly Build Reputation?

· One min read

Solving the big problems that everyone wants to address but no one can is the true path of a master.

In Gu Long's novel "The Legend of the Moonlight Blade," Ding Peng quickly rises to prominence in the martial world with a single move, the Falling Star. He is highly skilled, and his fame spreads rapidly. There is a supporting character, Guo Yunlong, who is eager to restore his family's reputation and seeks advice from Ding Peng on how to become a top figure.

Ding Peng's response is not only different from traditional teachings but also insightful. He candidly states, "You can perform righteous deeds and gradually build your reputation, but that is too slow. The fastest way is to step up and solve a major crisis when it arises in the martial world, and everyone else is at a loss."

PWA for Mobile Web

· 2 min read

Why Progressive Web App?

  • can be put to home screen by Chrome and Safari
  • work offline with service workers
  • increase engagement with push notification
  • improve the conversion rate for new users across all browsers by 104% and on iOS by 82%

“Progressive” means the improvement is not binary and terminal but evolutionary.

What is it?

PWA = website optimized for mobile + manifest.json + service worker loading and registering

How to add it to your site?

manifest.json is the easy part. Put the following into the example.com/manifest.json

{
"short_name": "Short",
"name": "Longer Name",
"icons": [
{
"src": "favicon.png",
"sizes": "192x192 150x150 144x144 64x64 32x32 24x24 16x16",
"type": "image/png"
}
],
"start_url": "/",
"display": "standalone",
"theme_color": "#de4c4f",
"background_color": "#f3f3f3"
}

And add the following into html <head>

<link rel="manifest" href="/manifest.json"/>
<link rel="apple-touch-icon" href="/favicon.png"/>

Then on both iOS and Android, users can add the site to the home screen.

Then ... service worker loading and registering

The loading part I recommend create-react-app’s service worker loading script, which has good security practices and targets the cache first strategy. And it includes unregister as well.

The registering part is trickier - we added the following webpack plugin to prepare the service-worker.js.

// ...
plugins: [
// ...
new SWPrecacheWebpackPlugin(
{
mergeStaticsConfig: true,
dontCacheBustUrlsMatching: /\.\w{8}\./,
filename: 'service-worker.js',
minify: false,
navigateFallback: '/',
navigateFallbackWhitelist: [/^(?!\/__).*/],
staticFileGlobs: [
`${OUTPUT_DIR}/**`,
],
stripPrefix: OUTPUT_DIR,
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
dynamicUrlToDependencies: {
'/index.html': glob.sync(path.resolve(`${OUTPUT_DIR}/**/*.js`)),
},
}
),
],
// ...

The tricky part here is that if you have SSR as we do - be careful to specify the dynamicUrlToDependencies; otherwise, cache may fail to be updated.

MMRs, Neutralizers and Differentiators

· One min read

There are three types of product features

  • MMRs: minimum market requirements; basic features that every customer expects and demands
  • Neutralizers: mitigate competitive threat
  • Differentiators: competitive advantage

Customers often provide feedbacks on MMRs and neutralizers. ==The product management team must take responsibility for reinforcing the startup’s differentiator.== Once the market recognizes the startup’s advantage, every competitor will race to replicate it. The startup must invest in that differentiation to sustain their market lead.