fupio

Fupio はオンラインで共有する最も簡単な方法です 詳しく見る »

Fupio に参加
Boris Cherny’s Blog

Boris Cherny’s Blog

Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.

Boris Cherny’s Blog
Boris Cherny’s Blog
Derived state for frontend applications comes up a lot. State B depends on State A, so after you update A, by the time you read B you want it to be updated based on the latest value of A. There’s a bunch of ways to model this, involving different tradeoffs:
  • Do you treat derived data and non-derived data the same?
  • Should users interact with the two the same way?
  • Do you re-compute dependent data in a lazy or eager way?
  • How much control do you need over re-computing derived

Boris Cherny’s Blog
Boris Cherny’s Blog
I spent the last year and a half writing my first technical book for O’Reilly (Programming TypeScript). I’d never written a technical book before. In fact, prior to the 300-page book, the longest thing I’d written was a 20-something-page paper in college.
Why’d I write the book? I love TypeScript, and I didn’t see any great resource out there that explained not just the language and build system

Boris Cherny’s Blog
Boris Cherny’s Blog
When typing React component props using TypeScript, I often see code that makes use of optional and nullable fields:
type Props = {
href?: string
onClick?: () => void
text: string
}

function Button(props: Props) {
if ('href' in props) {
return (
<a className="Button" href={props.href}>
{props.text}
</a>
)
}
if ('onClick' in props) {
return (
<button className="Button" onClick={props.onClick}>
{props.text}
</button>
)
}
throw ReferenceError('You must pass either href or onClick to <Button />')
}

let a = <Button text="Click me" href="https://github.com" />
let b = <Button text="Click me" onClick={() => {}} />

// OK. Should be an error
let c = <Button text="Click me" href="https://github.com" onClick={() => {}} />

// OK. Throws an error at runtime
let d = <Button text="Click me" />

Boris Cherny’s Blog
Boris Cherny’s Blog
If you have a tree with a node that has a property P, and all of its parents also need to have property P, then P is contagious.
When can that happen?
  • Exceptions bubble up through the call tree
  • State has to be lifted up to the root of a call tree
  • If a function is async, its ancestors must be too
  • Centralized services also centralize any decentralized services that call them
  • In a physical system, if you know the position and momentum of an object A and it collides with

Boris Cherny’s Blog
Boris Cherny’s Blog
I don’t usually write about politics, but today was a weird day.
Thousands of people gathered outside the Capitol building in Washington DC today, some of them going into the building, some with guns. A woman got shot. All of this in response to Donald Trump’s remark:
We’re going to try and give our Republicans the kind of pride and boldness that they

Boris Cherny’s Blog
Boris Cherny’s Blog
It’s 2021, and data management on the web still sucks. This is crazy!
If you’re building a web app at scale you have plenty of options for data fetching, transport, caching, and management:

Boris Cherny’s Blog
Boris Cherny’s Blog
I just finished Oliver Sacks’ excellent Everything in Its Place. In it, he mentioned as an aside that the Ginkgo biloba tree is hundreds of millions of years old, and its phenotype has been practically frozen since then – a living fossil.
Of course, this is the same tree that grows ぎんなん (Ginkgo nuts), an East Asian delicacy found in many dishes, 茶碗蒸し (Chawanmushi) for example.
Ginkgo has been

Boris Cherny’s Blog
Boris Cherny’s Blog
For the last year and a half, I have been working at Instagram in Japan. It’s a bit of an unusual setup: I live and work remotely from Nara, Japan, in a timezone that few other Meta engineers work in (most of Instagram and Meta are spread across the US and Europe).
I am fortunate to have the opportunity to have a setup like this. How I ended up here is a long story, which I will save for another post. For this post, I’d like to talk about what I have learned about effectively contributing to

Boris Cherny’s Blog
Boris Cherny’s Blog
You often hear that “timing matters”. It helps to think about this as two related concepts: time and timing.
For some things, time is more important than timing:
  • Investing (long term). Investing for the long term is all about holding a diverse set of assets for as long as possible. It doesn’t matter if you invest at discounted

Boris Cherny’s Blog
Boris Cherny’s Blog
Coming back to JavaScript and TypeScript after a few years neck deep in Python and Hack, I kept hitting a number of new, cryptic errors when running NodeJS code in my dev environment:
# when I ran ESM TypeScript code the wrong way:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

# when I imported an ESModule from a CommonJS .js file:
Error [ERR_REQUIRE_ESM]: require() of ES Module .../lodash.js from .../index.cjs not supported

# when I imported an ESModule from a .ts file:
error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls

# when I used ES6 import syntax in a .js file:
SyntaxError: Cannot use import statement outside a module