Better HN
topnewbestaskshowjobs
Log inSign up

phpnode

7,416 karma · joined Oct 23, 2009 (17y ago) · 1,582 submissions

Founder of https://codemix.com/ - authoritative product context which makes sure coding agents build the right thing and humans stay in control.

Email: charles@codemix.com

Submissions

comment 6y ago · link · parent

> I'd say there should be an exception for ransomeware cases where physical safety is being threatened.

doesn't that incentivise attacks on critical services/systems?

comment 6y ago · link · parent

They set up the incentive structure, they're responsible for the effects

comment 6y ago · link · parent

If everything is political then nothing is political and the term loses all meaning

comment 6y ago · link · parent

all of the functionality happens at compile time

comment 6y ago · link · parent

A while ago I built this exact mechanism for Flow, it could be done in TypeScript if there was enough demand for it (it's rather a large effort) https://gajus.github.io/flow-runtime/

comment 6y ago · link · parent

there's the reflect-metadata package but the type information it exposes is very limited, "object" instead of {a: "foo"} and so on.

comment 6y ago · link · parent

I wrote an article about this a while ago: https://codemix.com/opaque-types-in-javascript

comment 6y ago · link · parent

I don't think even ReScript can do this (yet?)

comment 6y ago · link · parent

yep!

comment 6y ago · link · parent

same mechanism, just deal with more edge cases. e.g. whitespace isn't really trimmed correctly at the moment, it doesn't handle escaping quotes in strings and so on. I did think about trying to match postgres's grammar but it's a lot of work and probably implementing a PEG first would make it easier.

comment 6y ago · link · parent

oh let's be clear there's no sensible real world use cases of this thing. it's a demonstration of what TS's type system can do

comment 6y ago · link · parent

it's a bit fragile only due to my laziness, it could be done properly if this were a serious project.

comment 6y ago · link · parent

> The implementation isn't even that horrible

You're making me blush!

The list of integers could be replaced by using tuples and reading their lengths to do basic arithmetic. Might run into recursion limits though.

comment 6y ago · link · parent

hover over the type annotations to see results in the playground, that's the output :)

The errors aren't really errors, just warnings about unused types

495.

Show HN: A SQL database implemented purely in TypeScript type annotations(github.com ↗)

426 points · by phpnode · 6y ago · 191 comments

comment 6y ago · link · parent

I used to be a big fan of the idea of schema.org, but it seems to be used by Google to keep as much traffic as possible on Google properties.

comment 6y ago · link · parent

Writing an alternative babel plugin to do the transform this way would be pretty trivial, but doing so for TypeScript is not (officially) possible. TS is going to choose one and it's going to be the one React uses.

Also the decision to split React's createElement() into jsx() and jsxs() means that to maintain compatibility all libs would have to do the same, and provide both functions, all because of an implementation quirk in React.

JSX should be a standalone thing. It's not intrinsically React, and shouldn't bend to React's needs alone.

comment 6y ago · link · parent

It can be done if you write your code like this:

    function MyThing() {
      return (
        el(A, {value: 123}, [
          el(B, {value: 456, foo: true}, [
            el(C, {awesome: true}),
            el(D, {awful: false})
          ])
        ])
      );
    }
but there's a reason people prefer JSX syntax

comment 6y ago · link · parent

JSX is a tree of deferred function calls. It's nothing to do with HTML, despite them looking similar. Normal function calls are not equivalent

comment 6y ago · link · parent

This is a missed opportunity to make JSX more than solely about UI and I'm pretty disappointed about it.

JSX is really a way to describe a hierarchy of deferred function calls independent of their callers. This could be tremendously useful in a number of different contexts, not just UI. What would a state machine look like if the states could be described in JSX? What would rx.js look like if this mechanism was available?

The current tooling makes experimenting with possible alternate use cases pretty awkward, and so basically no one is doing work in this area.

I believe that these changes, particularly the `jsx` and `jsxs` auto import, will make it even harder to separate JSX as a concept from React and React-like libraries. It'll make it harder to standardise JSX, which is frustrating as it's the most supported ECMAScript syntax extension by a long way.

My modest proposal is that a JSX element desugars to a call to a block scoped identifier called `jsx`, so I can do something like this:

    import { jsx } from 'react';
    import { elementCreator } from 'somelib';

    const someFunction = () => {
      const { jsx } = elementCreator();

      return <iAmNotAReactElement />;
    };

    const MyReactComponent = () => <div>cool</div>;

Taking this alternative approach would give developers a widely supported syntax extension that could allow for some really innovative solutions. The current path is going to do the opposite.

I understand that there are perf optimisations that React can do if they control all of this. But I feel like they're looking at this too narrowly, from only the perspective of UI. They have the power to open up a lot more opportunities.

501.

Show HN: A SQL database engine implemented solely in TypeScript type annotations(twitter.com ↗)

3 points · by phpnode · 6y ago · discuss

comment 6y ago · link · parent

What's motivating your hostility in this thread?

comment 6y ago · link · parent

Larger and with more features, but ultimately lacking the simplicity and elegance of the much older version?

504.

TypeScript adds support for Template String types(github.com ↗)

13 points · by phpnode · 6y ago · discuss

comment 6y ago · link · parent

> There's no portion of the code that does warmups.

This isn't true - Benchmark.js will repeatedly rerun benchmarks until it gathers statistically meaningful results.

> There's no portion of code that "blackholes" the results to keep the JIT from optimizing away the code under benchmark.

True, and there's actually nothing benchmark.js can do to ensure that doesn't happen in the general case but when this does happen the results are usually pretty obvious - we'd see billions of ops/sec. Incidentally the left-pad benchmarks do not suffer from this issue.

comment 6y ago · link · parent

The US is actually at number 17 in the list of milk consumption per capita: https://en.m.wikipedia.org/wiki/List_of_countries_by_milk_co...

comment 6y ago · link · parent

I really feel like default exports were a mistake, everything is simpler without them, they don't even work with things like `export * from './foo'`

comment 6y ago · link · parent

I'm not sure what you're asking, the tools are there for you to replicate their experiment.
1
161718
53