Hacker News new | ask | show | jobs
by mycall 14 days ago
Being deterministic, a binary executable is just a compressed version of source code.
3 comments

Compressed doesn't sound quite right. Source code contains abstractions which are often then expanded out into many variants in an executable (most obviously by function inlining, but at a smaller scope also by things like loop unrolling etc)
Lossy compression.
No, it goes the other way. Source code is a lossy compression of the billions of machine operations it can be compiled into. Abstraction is a way of compressing, both in the mechanical LoC sense, as well as in comprehension.
gainy expansion?
Many things also expand significantly in binary form. Heavy use of templating, for example.
Good observation!

Another one would be range-based foreach loops.

Is plate of spaghetti a compressed version of a recipe?

Executables are often larger than their source code.

A toolchain that creates repeatable binary builds is difficult to create. And a nonrepeatable build is potentially nondeterministic, in the sense that uncontrolled or hidden inputs impact the output.

This is very analogous to vector vs raster graphics. In a way, the vector format is strictly more powerful than the raster format as it can be rendered smoothly at any size. Thus the raster graphic, despite being larger in size, is a lossy distillation of the vector graphic.

Also it _is_ possible to gzip a file and get a larger file, there’s an inflection point based on the distribution of symbols in the source where the same compression algorithm produces a larger file than the original

A raster is not always larger than a vector; if you try to precisely vectorize an image of the real world (modeling each pixel), the vector version will be larger
Let me make a more rigorous claim: For any image, there is always a vector encoding that is at least as small as the smallest possible raster encoding. The converse is not true.
For a single black pixel, you can encode a raster in 1 byte (for the color). How will you encode that in 1 byte with a vector encoding? Seems to me that you’ll need to specify the color (1 byte) and some coordinates (more).
You can trivially transform any raster encoding into a vector one by adding 1 bit that means "decode the rest of this file as raster".

It's technically not just as efficient but the difference is constant and the smallest possible one. And the majority of images that are more efficient as vectors will compensate for it.

You could do it with less than 1 byte (even assuming color). For example: if the first bit is zero, assume it is a black 1x1 pixel, otherwise, interpret the byte as the width of the image, etcetera ;)
>Executables are often larger than their source code.

Not because they contain more information. Just stuff like inlining or different expression, plus image and other similar assets that we can ignore for this.

The term I would use is “projection” rather than compression.

Code belongs to the domain of source code. Compilation is a projection of that code into the domain of executables, and that involves enough types of transformation and mapping that it is a one-way operation.

From an information standpoint, some information is added (e.g. optimizations that encode knowledge about efficient bytecode) and some information is lost (e.g. the use of types that adapt to the native word size).

Projection as an instantiation, makes sense.