by btown · 2w ago · 0 comments
From what I see in https://github.com/expo/exact/blob/main/contract/syntax/src/... and https://github.com/expo/exact/blob/main/contract/syntax/src/... - it's unclear this will scale to the levels of complexity that arbitrary UIs demand.
It looks like a DSL, but it actually isn't - it's just regular javascript/typescript with a very thin 'declarative/markup' veneer. it basically tricks you into thinking you're writing a HTML-like UI-DSL, but it also just so happens to accept arbitrary JS expressions, because it is just regular JS.
But in the end this is a small syntactical difference (how it looks). You could have a custom code viewer that does these translations for you.
till this day you can't use linq to render a sequence of elements. Like people.Select(p => <div>{p.FullName}</div>);
it's such a shame XAML and Razer syntax haven't evolved.
> till this day you can't use linq to render a sequence of elements. Like people.Select(p => <div>{p.FullName}</div>);
In Blazor, you can do it with something like this: <div>
@people.Select(p => @<div>@p.FullName</div>)
</div>
Rendering-wise, it's better to use a @foreach [0], to avoid creating too many rendering fragments, but it works.[0]: https://learn.microsoft.com/en-us/aspnet/core/blazor/compone...
1 - all logic needs to be written in 1 statement. That forces you to use nested ternaries, nullish operators, and array fns where simple workflow controls would read much better.
2 - it’s designed to render html but conflicts with JS and TS, so you can’t have a class attribute, and weird escape hatches around generic fns.
// this
<Box>
{
shouldShowAnswer(user)
? <Answer value={false}>no</Answer>
: <Box.Comment>
Text Content
</Box.Comment>
}
</Box>
// ...can be written like this
const answer = (
<Answer value={false}>
no
</Answer>
);
const comment = (
<Box.Comment>
Text Content
</Box.Comment>
);
const result = shouldShowAnswer(user) ? answer : comment;
<Box>
{result}
</Box>
In React at least, null won't render anything.#2 is a known trade-off, and so marginal and well known that it's almost not worth mentioning it.
Ofcourse you can split every control flow into separate component and combine them together finally, but that means exactly that - that every minute condition or iteration is deferred elsewhere. And it makes the actual render result hard to understand.
Because it's a thin wrapper directly translatable into a JS function call. `className` is JS
React opted for backwards compatibility at the time it came out, and never made the upgrade - you can write `class` in Preact.
Contract actually constrains what it can express rather than having arbitrarily complex expressions. The constraint is actually sort of the point. Because a Contract file is something the compiler fully understands and not arbitrary code it has to run, one source can be type-checked and formally modeled, and behave the same everywhere. For stuff that doesn't fit into these constraints, you use Rust or TypeScript.
In practice, I've found that you do need ways to express stuff like `count > 0 and not loading` and `price.toFixed(2)`, etc., or else you are moving all of that logic into some other programming language which is just worse in terms of being able to express your UI and typically worse in terms of performance.
Contract has literals, templates, field reads, arithmetic, comparison, boolean logic, the conditional, option match, and a set of utility functions like `formatNumber`, `ceil`, `toLowerCase`, etc.
It doesn't have statements, loops, recursion, assignment, first-class closures, reduce and comparator sorts. A fn is a single non-recursive expression.
re: (b). There actually is a formal language specification in EBNF. It's in the repo. And there is a Lean 4 formalization of things.
re: (c) Stdlib across targets. There is a standard lib and it's implemented and tested across all the different targets. Ex. Numbers are IEEE-754 binary64, modeled in Lean, etc.