HNHacker News
TopNewBestAskShowJobs

andreypopp

1,040 karma · joined June 30, 2011

just sitting there, looking shiny...

https://github.com/andreypopp https://twitter.com/andreypopp

submissionscomments
andreypopp··on Zheap – Reinvented PostgreSQL Storage
Yeah, transactional DDL is a good thing, the potential problem with this solution though — if you have views pointing to the old table they won’t be updated with the new table and you will have to deal with them as well.
andreypopp··on Zheap – Reinvented PostgreSQL Storage
Such workflows with scheduled DELETE/INSERT often mean that the data is "derived", there's unlogged tables feature for that in PostgreSQL. Table configured with unlogged are not being written to WAL and thus generate much much less I/O. The downside is that after a crash occurs the table might be empty (before it is repopulated by the DELETE/INSERT workflow again).
andreypopp··on Using Askgit – A SQL interface to your Git repository
What would be nice is to add to this a way to plug language specific semantic analysers. Then it could be possible to do queries like "which commits did changes to a specific function" and so on.
andreypopp··on Modularizing SQL? (2007)
Checkout https://github.com/prometheusresearch/baseline-codebase/tree... which does that. Very happy about how it works.
andreypopp··on Personal Wiki for Vim
Also take a look at https://github.com/lervag/wiki.vim which I found to be much simpler and easier to use.
andreypopp··on Hacking the Planet With Notcurses: A Guide to TUIs and Character Graphics [pdf]
Checkout libtickit http://www.leonerd.org.uk/code/libtickit/
andreypopp··on SQL is a better API language than GraphQL – Convince me otherwise
I don't think SQL is a better API language than GraphQL.

1. First of all, they are designed with different compromises in mind, GraphQL is much less flexible language than SQL — no ad-hoc, joins, joins are predefined in the schema, no ad-hoc filters, ...

Now because GraphQL is a less flexible language it allows more freedom on the implementors side. Implementing GraphQL endpoint is as simple as specifying a set fo resolver functions (parent, args) -> result (of course there could be more sophisticated implementation but the point is that you can start just from that). Now if you want to implement a "virtual table" which would work with SQL — it's much more work.

I'd be very cautious to expose SQL based API (because the languages is so expressive). And if I'd have a task to make SQL less expressive to make it fit then it'd probably look a lot like GraphQL but with a weird syntax.

2. Secondly, SQL is not really as ergonomic as GraphQL for nested data. Even given the modern extensions, it is designed for querying relations, not for nested object structures we like to operate in our JavaScript programs.

3. And third, SQL grammar isn't as composable as GraphQL one. Look how GraphQL has fragments in the language to support composability. It'd be very weird to do the same with SQL. Or you'd need to extend it in some way which may be a good option but I haven't see such extension in the wild.

That said I still think there's some class of apps (internal admin UIs, dashboards, ...) which will benefit from having SQL-level expressiveness. For that I'd like to use something like HTSQL[1] — it's a language with GraphQL like grammar which compiles to SQL. HTSQL is quite dated (been around for more than 10 years but isn't popular sadly) but the concept is sound and its original authors are now working on its successor — QueryCombinators[2].

Now back to GraphQL, I actually think that the right way to define GraphQL endpoints which query databases is by mapping database types to GraphQL types using a language like HTSQL. We have that approach implemented here[3] We found it being A. much more flexible than doing automatic DB schema to GraphQL reflection and B. much more easy than writing resolvers manually. Of course on app startups those declaratively defined queries are checked against database schema so we won't have failures at runtime.

[1]: http://htsql.org

[2]: https://querycombinators.org

[3]: https://github.com/prometheusresearch/baseline-codebase/blob...

andreypopp··on Show HN: Esy – fast and simple package management for native ReasonML/OCaml
> So by acting like we use esy on Bucklescript, when we actually use npm, we get a very similar result?

Yeah, we use npm in that case just to fetch deps and layout them in node_modules which bucklescript understands. Otherwise we use esy for native built tools (ocamlmerlin, preprocessors and etc).

andreypopp··on Show HN: Esy – fast and simple package management for native ReasonML/OCaml
Hi Ben,

> It looks like a nice project, but I'm still a little confused about its purpose. You mention your JS background, so is it all about familiarity to npm?

I think familiarity with npm is important here!

I mentioned that npm allows you to have all dependencies of the project local.

Now if we want the same experience for a native project it gets more complex: we can't just install OCaml/Reason/C/C++ code into node_modules, it's not going to work.

So what esy does is it constructs for each package a "perfectly" isolated build environment based on dependencies declared in package.json, which is then used to produce build output (executable or library). Such environment contains things like `$PATH`, `$OCAMLPATH`, `$PKG_CONFIG_PATH` and etc, so these are all environment variable which C/OCaml/Reason/... software can understand.

Now it looks like this (super simplified!):

    esy build: package.json -> isolated build environment -> build output
Now because such isolated build environment depends only on the package.json (I simplify a bit here... later on that) and the build output depends only on its build environment we can easily compute a cache key for each package build output just by looking at package.json of the package.

So esy has smart cache for builds which makes each package build work like this:

      let KEY = hash(package.json) # this is very cheap
      if ~/.esy/store/KEY
        done
      else
        build(package.json, ~/.esy/store/KEY) # this is not cheap!
It means in practice that if you have completely separate esy projects which depend on the same version of `ocaml` (or `gcc` or any other package) then esy will build that version of `ocaml` just once. So those "every local" dependencies are super cheap once you have esy cache warm.

(the key isn't really hash(package.json) but more like hash(package.json + esy.lock) as we need to resolve dependency constraints to concrete versions first using "esy install" command)

> Or are there other things you gain when you run esy on top of dune?

The correct comparison is to dune on top of opam, I think (opam, the command line program, not opam, the registry as esy supports opam registry too!):

- with opam you manage switches manually (switches are like installed package sets), if you need a switch per project - you create a local switch per project

- with opam every time you create switch you need to compile everything from scratch, with esy we try to reuse as much as possible from the build cache

- you use dune with esy the same way you use dune with opam but you need to prefix dune invocations with esy: "esy dune ...", so that way dune sees esy build environment

- with esy you can pull packages from npm/opam/github/tarballs/...

- there's mechanism called `link:`[2] which allows to develop multiple packages as parts of the same project (so called monorepo workflow).

- ...

Some of these things are possible with opam too (not sure about smart cache though and I think it's pretty important) but with esy we've tried to provide the same experience as when you develop with npm/yarn (of course we wanted to solve gigantic node_modules issue and thus we have pnp, and flaky dependency constraints and thus we have a proper SAT solver, the same used by opam). So you might consider this a different UX to develop native code which is focused on Reason/OCaml.

> And my other question? It doesn't run with bucklescript - right? Are there specific reasons?

It doesn't integrate with bucklescript very well now but you still can use esy with bucklescript projects so you can install Merlin (IDE assistant) or other tools from Reason / OCaml ecosystem.

The way how bucklescript works right now isn't compatible with esy - for example we use pnp[1] installation mechanism (same as yarn) so we don't produce node_modules and thus we are fast and package sources are cached globally - for now bucklescript doesn't understand how resolve package sources from pnp.js runtime and thus it can't work with esy directly.

If bucklescript implements support with pnp then it will be perfectly usable with esy but for now you can use package.json for npm/yarn for bucklescript dependencies and esy.json (esy looks for esy.json before package.json) for native dependencies.

[1]: https://github.com/yarnpkg/rfcs/pull/101 [2]: https://esy.sh/docs/en/linking-workflow.html

andreypopp··on Show HN: Esy – fast and simple package management for native ReasonML/OCaml
> And how is the build env recorded for timestamps and env variables? Is all of this standardized?

We do record the build env now in esy's own format, you run:

    esy build-plan PKG
to see the build plan (a-la Nix derivation) which is a JSON with build commands and environment.

As regarding timestamps we don't set SOURCE_DATE_EPOCH yet but we definitely plan to address that.

andreypopp··on Show HN: Esy – fast and simple package management for native ReasonML/OCaml
esy tries hard to enable reproducible builds:

- esy builds are happening in an isolated environment with only specified dependencies available

- esy executes build processes under sandboxing (so builds can't write into arbitrary locations, we have some work to do here though)

- esy has feature which allows to rewrite binaries to remove prefix paths from them.

As for package signing+verification (assuming you are talking about source code) we do only integrity checks now for packages downloaded from npm and via opam.

EDIT: wording

andreypopp··on Show HN: Esy – fast and simple package management for native ReasonML/OCaml
> I'm biased as I've contributed a little bit to the esy,

Well, Bryan is responsible for the Windows support in esy, not a bit!

andreypopp··on Show HN: Esy – fast and simple package management for native ReasonML/OCaml
> I can use Esy to write native OCaml/Reason, but has no use in a compile-to-js environment - there it is npm/yarn.

If you use js_of_ocaml (a compiler from OCaml/Reason to JS) then esy works with it very well (with the help from dune). With Bucklescript (another OCaml/Reason to JS compiler) it's more complicated (see below).

> With Esy I will be using Dune as my build tool, but instead of the opam binary I can use Esy itself which can pull packages from the opam repository. It takes care of both packages and compiler environment just like opam.

This is correct!

But not necessarily dune (though this is a very good choice), you can use almost any build system you want.

> Is there anything in Esy that would make porting native OCaml packages (like say https://github.com/c-cube/qcheck) to Bucklescript?

Unfortunately not, esy works on level higher than build systems, it doesn't built code itself but rather calls an actual build system to do the workd (dune, make, cmake, ...). Bucklescript is unique as it tries to own the whole stack and thus you have to make code compatible with its build system (bsb) manually.

One thing which esy could help though right now with Bucklescript is providing native tools like ppx'es (preprocessors for Reason and OCaml code) or tools for editors like Merlin (autocompletion and etc.).

> It would also be wonderful to see it in action through a short video tutorial.

Agreed. Hope to have something soon.

andreypopp··on Show HN: Esy – fast and simple package management for native ReasonML/OCaml
> - Is there any issues with sharing the same config file with another package manager? Ie. `package.json`?

esy can install JS dependencies just fine but we are supporting plug'n'play installations only (see docs https://esy.sh/docs/en/node-compatibility.html for more info on that).

> - On a similar vein, why JSON, and not a config format that supports comments, like TOML?

Yeah, we thought of that but decided to use JSON for now as it's easy to publish esy projects to npm - you already have package.json ready for publish! We might add support for comments to package.json soon though.

> - Will it be able to do Coq projects as well? I've not had a great experience trying to use Opam with it, and had to resort to using submodules. D:

I think it's possible now (I only use it install Coq itself to work through Software Foundations) but I'm not sure about the details yet.

But considering that Coq ecosystem is moving to dune (the build system of choice in OCaml/Reason native ecosystem) and esy supports dune very well I think Coq is going to have a first class treatment soon in esy!

EDIT: re JS compat: you can esy.json instead of package.json and then esy will use it instead. That way you can use package.json with yarn/npm.

andreypopp··on Show HN: Esy – fast and simple package management for native ReasonML/OCaml
Hi,

I'm one of the developers of esy, would be happy to answer any questions about it.

I have background in JS ecosystem and always liked how npm/yarn allows you to have a set of dependencies installed per project which do not conflict with any other global installations. Then this goes even beyond runtime dependencies and you have tools like eslint/flow and others installed per project in node_modules.

Now enter native development and you won't find the same workflow there. This is what esy tries to solve. It focuses now on Reason programming language but conceptually it works with other platforms/tools too (for example some of our dependencies are C/C++ code and it works nicely with esy too).

Also I want to highlight the following points:

- All dependencies (and devDependencies) are local to a project (like with npm/yarn)

- The cache for built packages is shared between different projects - if you built OCaml 4.06.0 compiler once then the other project will just reuse it (this works similar to Nix package manager)

- To execute some tool within the isolated project environment you prefix it with esy command: "esy ocaml", "esy vim", "esy code"

- esy can install packages from npm, opam (package registry for OCaml ecosystem), github

- esy allows you to develop multiple packages at once (see linking workflow in docs).

- finally... we support Windows (besides Linux and macOS)!

andreypopp··on Show HN: Telepost – Create a blog from a Telegram channel
Created a channel/blog but won't start using it before it adds support for rich formatting (codeblocks, ...). €200/year is ok for me for such a frictionless experience.
andreypopp··on A look at terminal emulators, part 2
Really surprised the didn't include Kitty terminal. It is the fastest I found on macOS (even compared to Alacritty) when using PragmataPro font (which made me switch away from Terminal.app due to slow rendering).
andreypopp··on Deploying a ReasonML React app with Docker
Full type inference, pattern matching with exhaustivity checker, modules, abstract types, ...

But to be honest, it's not very useful to do checklist-style comparisons — writing OCaml/Reason code is a completely different experience.

For me it results in less worry about how my code would sustain under refactorings — this is one of the reasons I feel more productive with it rather than with TypeScript or Flow or (of course!) plain JS. I can start writing code and don't worry about getting everything right upfront — refactorings are cheap.

andreypopp··on Sweet.js – Hygienic Macros for JavaScript
That's not just "AST transform system", Sweet.js provides a way to extend grammar with new productions. That allows to introduce new syntax constructs.
andreypopp··on TypeScript 2.3
Well, I've provided examples where TS demonstrates unsound behaviour while Flow does well. What's your examples from personal anecdote-space?
andreypopp··on TypeScript 2.3
> by explicitly annotating `promisedString` you are widening the type from the inferred `number` to `any`

That's something I don't understand. Isn't that incorrect behaviour? Shouldn't TS try unify RHS and LHS?

andreypopp··on TypeScript 2.3
Yep, reported to Flow issue tracker.
andreypopp··on TypeScript 2.3
Try it in the playground.
andreypopp··on TypeScript 2.3
Not sure — TS doesn't report any errors in the original code so I assume it thinks code is fine but it is not. That's totally different than #2.
andreypopp··on TypeScript 2.3
> your edit, you actually don't need that first typing. Typescript will infer the type of the promisedString

Ok, but still this is confusing, it can't infer the type of RHS given the annotated LHS? Intuitively there's nothing wrong with it and Flow does that well...

andreypopp··on TypeScript 2.3
EDIT 2: This still surprises me...

   let promisedString: Promise<string> = new Promise<string>(
      resolve => {
        // Perfectly valid in TypeScript!
        resolve(undefined)
      }
    )
EDIT: no, I was wrong — Bluebird typings won't allow this behaviour but they force me to annotate both the binding and the Promise constructor call:

    let promisedString: Promise<string> = new Promise<string>(
      resolve => {
        resolve(42) // type error here, ok
      }
    )
That's surprising TS ships with such unsafe typings for ES2015 Promise API...

Hm... no.

First, note that this is with noImplicitAny activated. You can check this in TS playground.

Then if we inspect what typings TS have for ES2015 Promises[1] and for Bluebird[2], you can clearly see that those are identical in this case..

[1]: https://github.com/Microsoft/TypeScript/blob/master/lib/lib....

[2]: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/mast...

andreypopp··on TypeScript 2.3
Ok, I've used TS while contributing to OSS written with TS and I've used Flow extensively in production settings.

The main takeaway for me is that TS is much much less sound than Flow. That means it checks less invariants which in turn makes you less trust it...

Consider the following code which is valid (!) in TS:

    let promisedString: Promise<string> = new Promise(
      resolve => {
        // Perfectly valid in TypeScript!
        resolve(42)
      }
    )
Another downside of TS is poor type inference. It requires to annotate each top level function while Flow only requires to annotate exported functions.

Even the following simple piece of code will make TS ask you to annotate doAddition function:

    export function addition(a: number, b: number) {
      return doAddition(a, b)
    }

    function doAddition(a, b) {
      return a + b
    }
I'm really glad Flow doesn't force me into it.

Edit: spelling

andreypopp··on TypeScript 2.3
In Flow only classes are nominally typed. Objects and interfaces are typed structurally.
andreypopp··on WebAssembly Browser Preview
FWIW you can already use AOT compiled code in Node.js (native modules). Will WASM provide more benefits over that?
andreypopp··on WikiWikiWeb is back online
Works for me (using Safari Tech Preview 16).
← PreviousPage 2 of 5Next →