3 ms·
IMO: Transpilers are compilers, but not all compilers are transpilers. In my book, transpilers are compilers that consume a programming language and target hum
by goranmoomin 11mo ago
IMO: Transpilers are compilers, but not all compilers are transpilers.
In my book, transpilers are compilers that consume a programming language and target human-readable code, to be consumed by another compiler or interpreter (either by itself, or to be integrated in other projects).
i.e. the TypeScript compiler is a transpiler from TS to JS, the Nim compiler is a transpiler from Nim to C, and so on.
I guess if you really want to be pedantic, one can argue (with the above definition) that `clang -S` might be seen as a transpiler from C to ASM, but at that point, do words mean anything to you?
- writebetterc 11mo agoI'd probably say that "transpiler" is not a very useful word with that definition.
- cygx 11mo agoWhy is it useless? 'Compiler' denotes the general category, within which exist various sub-categories: For example, a 'native compiler' outputs machine code for the host system, a 'cross compiler' outputs machine code for a different system, a 'bytecode compiler' outputs a custom binary format (e.g. VM instructions), and a 'transpiler' outputs source code. These distinctions are meaningful.
- goranmoomin 11mo agoI can’t see why — I do think that the word does convey some sort of useful meaning with the above definition.
- deleted 11mo ago[deleted]
- ssrc 11mo agoFor me, the "human-readable" part is key. It's not just that the output is e.g. javascript, but that it is more or less human-readable with about the same organization as the original code. If you implement SKI combinators, or three-address instructions, as functions in javascript, and that's the output of your compiler, I would not call that a transpiler.
- gampleman 11mo agoExactly. For a web dev oriented example, I would call coffeescript a transpiler, since it would transform # some comment myFun = -> alert 'Hello CoffeeScript!' into // some comment var myFun; myFun = function() { return alert('Hello CoffeeScript!'); }; clearly intending the output code to be quite readable (even preserving comments). Whereas Elm is a compiler since it transforms module Main exposing (main) import Html main = Html.text "Hello Elm!" into (function(scope){ 'use strict'; function F(arity, fun, wrapper) { wrapper.a = arity; wrapper.f = fun; return wrapper; } // about 4000 lines ommitted var $author$project$Main$main = $elm$html$Html$text('Hello Elm!'); _Platform_export({'Main':{'init':_VirtualDom_init($author$project$Main$main)(0)(0)}});}(this)); Clearly not intended for (easy) human consumption.
- ethmarks 11mo agoWould it still count as a transpiler if it minifies the code at the end? For example, most SCSS workflows I've worked with converert SCSS source code into minified CSS, which is pretty difficult for a human to read. But I think that SCSS => CSS still counts as transpiling.
- aleph_minus_one 11mo ago> Would it still count as a transpiler if it minifies the code at the end? I would say "yes, but the minimization is an additional step that is not actually a direct part of the transpiling process." :-) So, a program that does this would not a transpiler by itself, but a program that - executes a pipeline of which the transpiling is the most important step, - can also be used as a transpiler by making transpiling the only step in the executed pipeline.
- ethmarks 11mo agoWhat if the minification is inseparable from the transpiler? Like what if it converts the SCSS into some weird graph representation, applies the transpilation features (variables, mixins, etc) on that graph representation, then converts the graph representation into minified CSS? At no point in the process was it ever human-readable CSS. I don't know enough about the internals of transpilers to know if they actually do anything like this, but one could imagine a hypothetical program that does. And furthermore, what if you run Prettier on the minified output, turning it into readable CSS? The pipeline as a whole would input SCSS and output formatted CSS and therefore would be considered a transpiler, but the subprogram that does all of the SCSS heavy lifting would input SCSS and output minified SCSS, making it not a transpiler. P.S. I love your username
- shiomiru 11mo agoI can usually read JS generated by TS, but calling the C Nim outputs "human-readable" is very generous considering it flattens most structured control flow to goto. (It's hard to do it otherwise, Nim has to deal with exceptions and destructors but C has neither.) Classifying Nim as a transpiler also results in weird cases like NLVM[1] which most would consider a compiler even though it is a back-end on the same "level" as Nim's C generator. [1]: https://github.com/arnetheduck/nlvm https://github.com/arnetheduck/nlvm
- monocasa 11mo agoI mean, original Dartmouth BASIC only had if and goto, and was definitely designed as a human readable language.
- skopje 11mo agoI can read 6502 machine code raw hex. Now what. ;-)