My books on #JavaScript and #TypeScript are free to read online:
– Exploring JavaScript (ES2024 edition)
– Deep JavaScript
– Tackling TypeScript
– Shell scripting with Node.js
:mastodon: Boosts appreciated!
My books on #JavaScript and #TypeScript are free to read online:
– Exploring JavaScript (ES2024 edition)
– Deep JavaScript
– Tackling TypeScript
– Shell scripting with Node.js
:mastodon: Boosts appreciated!
@functionalscript You would have to write it (my knowledge is limited here). I’d be happy to review!
I’ve always found discrete mathematics (*) much easier to understand than, e.g., calculus or statistics – because it is so similar to programming. Relations, orders, graphs are all part of discrete mathematics.
If you think you don’t like math, you may actually enjoy discrete math.
Math topics that keep being useful for programming: relations, orders, graphs.
Example: You have plugins with conditions such as “plugin A must run before plugin B“.
– These conditions define a partial order: In general, not every plugin can be “compared” with every other plugin.
– If we want to sort an Array with plugins, we need a total order.
– One algorithm that works with a partial order is topological sorting: https://en.wikipedia.org/wiki/Topological_sorting
Announcing the Web Platform Dashboard:
“For the first time you'll have a way to see the entire web platform mapped as a set of features, along with their support in browsers.”
“The Dashboard isn't intended as a replacement for Can I Use or the browser compatibility data on MDN. In your day to day life as a developer, it's likely to be less useful than these places. However, showing the platform in this way creates some interesting possibilities.“
Web apps—topics I’d like to be discussed more:
– Offline capability
– Peer-to-peer operation (syncing etc.)
It’s a shame that most web apps cease to work properly whenever the internet connection is flaky or gone. For me, that happens whenever I travel (train, plane, etc.).
Native apps are better at offline (but not much).
#TypeScript: Arrow functions help with partial evaluation [1] – e.g. a factory for functions for which there already is a type. Then they are more elegant than using .bind() [2]
const functionFactory = (factoryArg: string): FunctionType => (functionArg) => { … }
Note that the type of `functionArg` and the result type of the second arrow function are provided by `FunctionType`.
[1] https://2ality.com/2011/09/currying-vs-part-eval.html
[2] https://2ality.com/2016/02/arrow-functions-vs-bind.html
EOL—'\n' vs. '\r\n':
– With files and strings read from files, you can detect the EOL and use it when writing files.
– On Node.js, you can use os.EOL.
But what about multi-line strings in error messages that must work in browsers and Node.js? Always '\n'?
@functionalscript This API may work for you: https://nodejs.org/api/module.html#customization-hooks
1/ I love #TypeScript’s discriminated unions: https://exploringjs.com/tackling-ts/ch_special-values.html#discriminated-unions
Alas, I often end up switching to classes:
A. The discriminant is not very sticky:
– There is no refactoring for renaming it.
– TS cannot infer the type of an object via a discriminant (only narrow it). In contrast to: new MyClass()
B. Classes provide locations for initialization code and operations. I could put each DU in its own module but that is often too fine-grained for my taste. Future: submodules?
2/ Experiment (not yet sure if I like it):
type CTree = CTreeNode | CEmptyTree;
class CTreeNode {
left: CTree;
right: CTree;
value: string;
}
class CEmptyTree {}
// DU version:
type DUTree = DUTreeNode | DUEmptyTree;
type DUTreeNode = {
kind: 'DUTreeNode',
left: DUTree,
right: DUTree,
value: string,
};
type DUEmptyTree = {
kind: 'DUEmptyTree',
};
1/ #TypeScript:
– My own experience of TypeScript is overwhelmingly positive.
– But I’m also seeing people complain about its complexity.
I think both are true:
1. If you stick with simple types and strict type checking (no `any`), you’ll have a good experience.
2. Alas, some JavaScript APIs can only be described with very complicated types and then things can get ugly.
Definitely Typed has some type definitions that I find too complicated.
Todo files for open source projects:
– My todo files are usually unordered and not ready for public consumption.
– How do you handle yours? Any tips?
#TypeScript: Stale compiled files can cause issues (when you rename an input file, the old output file isn’t removed). That’s why I occasionally do:
npm run build
"scripts": {
"build": "npm run clean && tsc",
"clean": "shx rm -rf ./dist/*",
···
}
shx provides cross-platform shell commands: https://exploringjs.com/nodejs-shell-scripting/ch_package-scripts.html#file-system-operations
#TypeScript – occasionally useful:
type JsonValue =
| null
| boolean
| number
| string
| JsonValue[]
| { [key: string]: JsonValue }
;
Last week’s ECMAScript News summarizes several interesting things that happened:
– Should npm be unbundled from Node.js?
– LLRT, Amazon’s new JavaScript runtime based on QuickJS
– TC39’s February 2024 meeting
– Trailer for “Node.js: The Documentary”
– And more
You can still subscribe for tomorrow’s issue: https://ecmascript.news
#TypeScript—I’m trying out this pattern for “enums” with object values:
const Heading = {
Part: {
key: 'Part',
level: 1,
},
Chapter: {
key: 'Chapter',
level: 2,
},
Section: {
key: 'Section',
level: 3,
},
} as const;
// Discriminated union!
type HeadingType = PropValues<typeof Heading>;
// Name could be `Heading` but that trips up TS language server in
// some cases.
type PropValues<Obj> = Obj[keyof Obj];
Related: https://exploringjs.com/tackling-ts/ch_enum-alternatives.html
Movies and TV: I’d like to see “Roman space empire” instead of “nazi space empire”. Then the story would get more interesting because it wouldn’t simply be about “good vs. evil”—it would have politics in addition to war.
I can’t overstate how pleasant it is to consume various kinds of content via feeds. For example, you can group it into categories, which makes it easy to skip things you’re not interested in at the moment.
Thanks to JSON Feed (*) it is now easier than ever to add feeds to websites. I could even see myself subscribing to a feed instead of an email newsletter to be notified of an important event (such as a product coming out).
1/ #TypeScript & ESM—modern approach that works for me (feedback appreciated!)
## package.json
– Only "exports"—no more "main", "module", "types", "typesVersions"
– Pairings:
– m.d.ts next to m.js
– m.d.mts next to m.mjs
Tree of files:
"exports": {
"./*": "./dist/src/*"
},
Single file:
"exports": {
".": "./dist/src/library.js"
},
## tsconfig.json
"module": "NodeNext",
"moduleResolution": "NodeNext",
## Documentation
– https://nodejs.org/api/packages.html#package-entry-points
– https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports
Topics: #JavaScript #TypeScript #fedi22Other interests:– Languages: German, English, French, Spanish, Dutch, Mandarin– Sustainability, degrowth, permaculture, urbanism– Tiny houses– Education– Psychology, getting out of one’s head, heart-centered living– Minimalist spirituality: Advaita, Daoism, Buddhism, Christian mysticism, J. Krishnamurti, …I live in Munich. http://pronoun.is/heNon-tech:– :pixelfed: Photos: @rauschma– 💬 Languages: @langtales
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.