News for hackers. Stuff that matters.
Re:A look at Unison: a revolutionary programming language by michaelmior on Tuesday January 10, 2023 @09:20PM (#34334276)
> Unison does away with builds. Completely!

> It has a canonical representation for all code,

Isn't generating that canonical representation the build step?

> The important thing is that now, I can actually compile and run this program

Now I'm confused whether there is or isn't a build step.

Re:A look at Unison: a revolutionary programming language by naikrovek on Tuesday January 10, 2023 @09:43PM (#34334438)
JavaScript doesn't have a build step either. sounds like it is interpreted and you reference methods by hash instead of by name. sorta?
Re:A look at Unison: a revolutionary programming language by __MatrixMan__ on Wednesday January 11, 2023 @12:26AM (#34335303)
I'm not an expert at JS internals, but I'm under the impression that if you call a function ten times, its code has to be interpreted ten times, so you get ten, temporary, abstract syntax trees. Such is life in interpreter-land--the code is authoritative, the instructions are ephemeral.

My impression of Unison is that if you want to call a function ten times, you just need to evaluate that code into an AST once. Once you have the hash of that AST, you can delete the code and still call the function 9 more times without having to bother with building the tree each time.

I don't know what to call it, but I don't think it's interpreted because you don't need the code to run it (except the first time, which is how you know find the hash of the function).

Re:A look at Unison: a revolutionary programming language by goto11 on Wednesday January 11, 2023 @01:35AM (#34335750)
> I'm not an expert at JS internals, but I'm under the impression that if you call a function ten times, its code has to be interpreted ten times, so you get ten, temporary, abstract syntax trees.

This is not the case even in an interpreted language. You only need to build an AST once, at parse time. In JavaScript the AST is then compiled into byte code or machine code depending on the implementation.

Re:A look at Unison: a revolutionary programming language by __MatrixMan__ on Wednesday January 11, 2023 @02:06AM (#34335892)
Sorry, let me rephrase.

In JS, if 1 developer and 9 users with a total of 10 separate browser instances all call the same function, the code will be parsed 10 times.

In Unison, the AST is generated by the developer, cached, and the 9 users can call it by hash (assuming they have access to that database where the AST lives) without reparsing the code.

Re:A look at Unison: a revolutionary programming language by goto11 on Wednesday January 11, 2023 @11:28AM (#34340269)
So the AST is transferred over the wire? How is it serialized?
Re:A look at Unison: a revolutionary programming language by zawodnaya on Wednesday January 11, 2023 @06:47PM (#34346804)
It’s a binary-encoded merkle tree
Re:A look at Unison: a revolutionary programming language by __MatrixMan__ on Wednesday January 11, 2023 @11:41PM (#34349302)
It's in a sqlite database. Unison doesn't prescribe how those are passed around, but since everything is content addressed there are never any collisions. You can always merge two of them into one without having to resolve conflicts and without breaking anything.

The way I intend to use it is that users periodically fetch the codebases from all of the developers that they trust. This has no immediate effect because you're still calling the same function that you're used to. So the sync can be very latency tolerant.

Then, when you decided to use the new version of something, you call the new hash. If something goes wrong, you just go back to calling the old hash--atomic upgrade/downgrades, no merge conflicts.

Re:A look at Unison: a revolutionary programming language by osigurdson on Wednesday January 11, 2023 @12:34AM (#34335363)
I think the compiled form is associated with the hash of the source. It can’t be machine code though.
Re:A look at Unison: a revolutionary programming language by zawodnaya on Wednesday January 11, 2023 @06:45PM (#34346785)
It’s bytecode
Re:A look at Unison: a revolutionary programming language by osigurdson on Wednesday January 11, 2023 @10:51PM (#34348960)
Does it require a jit then or more like llvm?
Re:A look at Unison: a revolutionary programming language by brabel on Wednesday January 11, 2023 @02:32AM (#34336036)
JS doesn't type check, generate an AST, or even minifies anything until the user runs the code. If you just write JS in notepad then immediately send it over to your users, then yeah, there's no build in JS.

But if your idea of writing software involves:

* type checking, linting and otherwise ensuring properties of the code before even running it.

* testing code before deploying it.

* turning it from text into a representation that's more compact and safer to run.

* generating documentation.

Then you'll definitely need a build, and a very complex one for that matter, in JS world. Have you ever seen a JS project without any sort of build in a professional context?

And you'll need a big IDE to help you make sense of anything because JS doesn't even have a "compiler" or "helper tool" that'll give you any help to navigate and understand the code base.

Re:A look at Unison: a revolutionary programming language by zdragnar on Wednesday January 11, 2023 @10:18AM (#34339361)
> Have you ever seen a JS project without any sort of build in a professional context?

Imagine a world that pre-dates typescript, node, webpack, browserify, gulp, grunt. You were lucky if you had a server framework that concatenated files for you, otherwise you were stuck with 6000+ line "global.js" files. Then you had to fix merge conflicts in that file because SVN.

Whenever someone complains that frontend JS is too much, I just think back to how it used to be.

Re:A look at Unison: a revolutionary programming language by xtagon on Tuesday January 10, 2023 @10:49PM (#34334808)
I had the same confusion and re-read the article. Best I can understand, what they're trying to say is that it could be used without a build step in the sense that you could just manipulate the database's AST-like structure directly instead of compiling code, and it would be basically incrementally "compiling" each unit as you edit instead of interpreting a code file. But of course that's not a very ergonomic way to do it so there is a language on top, that they used as an example to show off the language.

I can see this being useful for implementing alternative editing interfaces besides just writing code textually. For example, flow-based visual programming or something like that. Adding and connecting nodes in a visual interface would each be small updates to the database, and then there would never be a "build step" because the database you've been editing is already the AST that could either be interpreted or compiled. So it only really does away with the parser, but that doesn't seem revolutionary to me, other languages can already do that. I might be missing something still.

Re:A look at Unison: a revolutionary programming language by dwohnitmok on Wednesday January 11, 2023 @01:14AM (#34335608)
You can think of it as an incremental build step but the crucial key that Unison's content addressing gives you is that canonical representation only needs to be generated once, ever.

So for example if someone publishes a library, no new build step would ever be required for consumers of that library.

Even with CI/CD there would be no build step because the very act of merging one's code into another codebase operates on canonical representations and so they never need to be regenerated.

Re:A look at Unison: a revolutionary programming language by lib-dev on Wednesday January 11, 2023 @02:08AM (#34335899)
Could this be done in other languages too?
Re:A look at Unison: a revolutionary programming language by pharmakom on Wednesday January 11, 2023 @02:38AM (#34336065)
This is one of things Bazel tries to do.
Re:A look at Unison: a revolutionary programming language by brabel on Wednesday January 11, 2023 @02:25AM (#34335997)
kind of. For example, in Java, build tools will normally cache the hash of the source file that generated a class file. That class file is a cached version of the source, basically. IF you could keep both the class file and the hashes of the source around, you could avoid ever re-compiling the source unless you've changed it. This is just incremental compilation, in essence.

However, you'll need quite a lot of tooling around this simple idea: where to store the class files and the hashes, should you commit it into source control, how to distribute the cache, can this be made multi-platform so it works on all developers' machines?

All solvable, but Unison already does all that, and more, with its single tool, the `ucm`.

Re:A look at Unison: a revolutionary programming language by sparkie on Wednesday January 11, 2023 @07:36AM (#34337696)
An issue with many languages is the presence of mutually dependant parts of code, because how do you generate a content-hash for something whose constituent part's content-hashes depend on it? Merkle trees can be generalized to DAGs, but not directed graphs with cycles.

As far as I understand, Unison's syntax has been designed specifically to avoid such cycles, although it supports recursive functions and inductive data types which refer to themselves such as lists. I'm not sure if, and if so, how, it would support mutually recursive functions or data types though. I suspect they're not supported for the reason that content-hashing becomes non-trivial.

If you wanted to generalize the solution to arbitrary languages, you would need to somehow sever the cycles, or come up with another solution to content-hashing which does not have the problem of Merkle-DAGs. Either way, you are looking at something non-trivial compared to having a language which simply forbids the cycles.

Re:A look at Unison: a revolutionary programming language by fwip on Wednesday January 11, 2023 @04:41PM (#34345334)
Unison does allow mutually recursive functions.

https://www.unisonweb.org/docs/faq/#how-does-hashing-work-fo...

Re:A look at Unison: a revolutionary programming language by raggi on Wednesday January 11, 2023 @02:09AM (#34335901)
Not once ever. Once per toolchain version and unique argument set. Perhaps the toolchain starts by attempting to never offer arguments, and perhaps it has lofty goals to release on day 1 with a perfect compilation model. All of my experience suggests these constraints are untenable, so ever is somewhat of an embellishment.

The model also precludes cross-unit optimizations so there's a performance upper bound on compilation model that leaves it in the middle tier of performance without the model being broken (given things we've seen before).

Re:A look at Unison: a revolutionary programming language by goodpoint on Wednesday January 11, 2023 @05:16AM (#34336918)
> You can think of it as an incremental build step but the crucial key that Unison's content addressing gives you is that canonical representation only needs to be generated once, ever.

That's not very different from using ccache. Claiming that there are no builds is simply not true.

> So for example if someone publishes a library, no new build step would ever be required for consumers of that library.

Does that require trusting compiled blobs from 3rd parties? That could make it trivial to inject backdoors.