7 ms·
Is Nim a Transpiler?
- teleforce 5y agoMy personal opinion is that it will be better to provide seamless support for C rather than compile to C as has been done by C++ and D. D language even goes further by performing CTFE for the latest ImportC feature. Check this Pascal to D transcompilation talk in DConf 2019 [1]. It will be great if similarly R language can be transcompiled to D since the effort has been futile so far to write a better and modern compiler for R [2]. https://youtu.be/HvunD0ZJqiA https://youtu.be/HvunD0ZJqiA [1] DConf 2019 - Transcompilation into D: http://dconf.org/2019/talks/veelo.html http://dconf.org/2019/talks/veelo.html https://youtu.be/HvunD0ZJqiA https://youtu.be/HvunD0ZJqiA [2] Why R? 2020 Keynote - Jan Vitek - How I Learned to Love Failing at Compiling R: https://www.youtube.com/watch?v=VdD0nHbcyk4 https://www.youtube.com/watch?v=VdD0nHbcyk4
- tyingq 5y agoStrange article, since there's not some central arbiter that defines the "transpiler" word.
- tokai 5y agoStrange comment, since the semantics of all words are debatable and no central arbiter can be more than an opinion.
- tyingq 5y agoEr, okay. In the tech space, there are often words that refer back to some real or de-facto owner, or strong pattern of historical use. I'm saying this is a case where that isn't true. Making definitive statements about what is, and what isn't a transpiler, is difficult.
- ch4s3 5y agoIt always seems odd to me that there's the separate word "transpiler" that seems to mean compiler that targets JavaScript. I don't really encounter it anywhere else.
- chrisseaton 5y agoYou can transpile to any language. It isn’t specific to JavaScript.
- ch4s3 5y agoI guess I would just use the. word compile. I'm not sure the "similar level of abstraction" distinction always holds a lot of meaning and just feel like splitting hairs to me. But maybe I'm missing something.
- tyingq 5y agoI think that was an attempt to exclude traditional compilers from being transpilers. Like 'C' is not at a similar level of abstraction to ASM or a compiled executable.
- tyingq 5y agoI'm sure there were earlier references, but the first time I'd heard the word was around z80 <-> 8080 ASM translation tools.
- dagw 5y agoThe first transpilers where used to translate between different assembly dialects to help with porting software between platforms. The term then kind of disappeared until the JavaScript community resurrected it
- ivanbakel 5y agoThis post is oddly adamant about a point that it makes with (what it acknowledges to be) very weak evidence. If the Typescript compiler is really a compiler, then JSweet is surely also a compiler? Both go from a stricter type system to a laxer one, and neither is really reversible. What really comes through is that the author seems to think that transpiler status is somehow lesser, and the whole nitpicking about compilers/transpilers is just an attempt to make sure Nim lands squarely on the compiler side. Maybe the conclusion that should be reached is the one the author is hinting towards at the end - which is that transpiler and compiler don't really have a strong distinction, and their usage is muddied enough that saying whether something is "actually" a transpiler or a compiler is mostly pointless. (And then there would be less worry that people "mistakenly" call Nim a transpiler, eh?)
- PMunch 5y agoAuthor here, I specifically tried to pick projects which self-identified as transpilers in order to not accidentally call a project I didn't know enough about a transpiler incorrectly. I don't in any way think that a transpiler is lesser, but a lot of the questions we've gotten about it in the Nim community has been phrased in a way which makes be believe that some people do. Hence why the article is written with that counter-stance. The conclusion is definitely that these are loose terms that can apply to many different things. But some of the usages are more useful as differentiating terms than others. The very broad definitions of transpilers ends up making most if not all compilers into transpilers which isn't terribly useful, and the in-between ones I've found are so under-defined that the term ends up not meaning anything at all. This was merely my attempt at reaching a definition of transpiler that is not only a useful distinction from a compiler, but also serves as a more concrete term.
- deleted 5y ago[deleted]
- dgb23 5y agoI agree with the article, there is no meaningful distinction between a compiler and what people typically call a transpiler except if you have a two way translation. Also „machine code“ is not even the last step anymore, it gets further cached, interpreted compiled to instructions by the hardware. It’s abstraction layers all the way down.
- jerf 5y agoNo, transpilers are completely different than compilers. For a transpiler, you generally need a tokenizer, then a parser to parse the token stream into an AST, which you will then have some set of transformation steps, often transforming into other ASTs for optimization steps or incremental transforms to the final target, before you take the final AST and serialize it out into the target. Wherease for a compiler, you generally need a tokenizer, then a parser to parse the token stream into an AST, which you will then have some set of transformation steps, often transforming into other ASTs for optimization steps or incremental transforms to the final target, before you take the final AST and serialize it out into the target. If I was hiring for a compiler position and someone showed up with 10 years of transpiler authorship on their resume, I wouldn't even look at them. Such divergent experience would be useless. It would be like hiring someone for a Javascript backend position when all they had was 10 years of intensive Javascript frontend experience. Madness. You'll go out of business making stupid hiring decisions like that.
- dleslie 5y agoYou wouldn't hire someone with near-but-different skills and a decade of competency because they don't fit a niche, highly specific of requirements? I think you'll spend more time and effort hiring than you would've spent training.
- detaro 5y agofind the difference between the two descriptions they posted again and re-evaluate if it might be sarcasm.
- WithinReason 5y agoI'm torn between discussing the article or commenting on how bad the default LaTeX font (Computer Modern) is that it's using
- skrebbel 5y agoPlease do discuss the font, why do you think it is bad?
- mftrhu 5y agoIt's meant to be used in print, and print has bleed. It's too thin, by far, when it is used on screen (or even modern laser printers): see https://www.levien.com/type/cmr/gain.html https://www.levien.com/type/cmr/gain.html
- kjs3 5y agoDon't egg them on.
- skrebbel 5y agoWhy not? I'm interested because I mostly hear good things about the way LaTeX output looks, and as an amateur font geek I'd like to understand people's objections to it. Sure, it's off topic, but that happens aplenty on HN no?
- kjs3 5y agoBecause it's an sorta ironic, off-topic attempt to generate a "vi versus emacs" level argument. Sorry you lack the ability to spot it.
- WithinReason 5y agoIt's too thin, when I print it the "e" and the "c" becomes indistinguishable, and even on a 4K screen it looks bad. A font I've found with similar aesthetics but without these issues is Charis Sil.
- gavinray 5y agoI mean, to me it is a transpiler because it is a "frontend" to several other languages. You choose whether you want to emit C, C++, or JS. There's an experimental, fledgling community LLVM frontend for Nim, that is what I would call a "compiler": https://github.com/arnetheduck/nlvm https://github.com/arnetheduck/nlvm What Jetbrains calls Kotlin -> JavaScript, is "transpilation" What Google calls Java -> JavaScript in j2cl, is "transpilation" But this is all pedantic IMO.
- no_time 5y ago>High-quality gdb/lldb debug information with source stepping, type information etc Very nice. Last time I experimented with Nim the lack of this was the single biggest dealbreaker.
- gavinray 5y agoWell there's major drawback here: > nlvm does not: - understand C - as a consequence, header, emit and similar pragmas will not work - neither will the fancy importcpp/C++ features - support all nim compiler flags and features - do file bugs for anything useful that's missing One of the unique and best things about Nim (IMO) beyond being multi-target, is that you can do things like say "emit this exact C/C++ string", or "import this type from an existing header". With this LLVM backend, that doesn't work, and it doesn't support JS (which probably isn't a big deal to most people). That means you can't do stuff like this: type VectorIterator {.importcpp: "std::vector<'0>::iterator".} [T] = object # std::vector<int>::iterator x; var x: VectorIterator[cint] https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-emit-pragma https://nim-lang.org/docs/manual.html#implementation-specifi... https://nim-lang.org/docs/manual.html#foreign-function-interface-importc-pragma https://nim-lang.org/docs/manual.html#foreign-function-inter... https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-importcpp-pragma https://nim-lang.org/docs/manual.html#implementation-specifi...
- dsrw 5y agoWith the '--debugger:native' flag, the Nim debugging experience isn't too bad. Not on the level of Java or C#, but you can set breakpoints, step in/over/out of code and inspect or watch variables without having to look at C code. There are some issues with type visualization (to see the contents of a string you have to evaluate something like '(char*)variable->data') but Nim ships with a gdb plugin that should help (I haven't actually tried it). It could definitely be better, and hopefully some day it will be, but I use Nim in a debugger quite frequently and it usually works out pretty well.
- fulafel 5y agoThe definition this article puts up is, without references, is: " A transpiler on the other hand is a tool that converts between two languages while keeping the same level of abstraction. A theoretical perfect transpilation is therefore a two-way process where you could go back and forth between languages." Is the level same-level-of-abstraction really part of the usual meaning of the term? Here's a blog post by Lindsey Kuper that finds around 5 meanings, with only one of them (and being an unsourced Wikipedia article to boot) converging to the same idea about abstraction leve: http://composition.al/blog/2017/07/30/what-do-people-mean-when-they-say-transpiler/ http://composition.al/blog/2017/07/30/what-do-people-mean-wh...
- guerrilla 5y agoI've never thought about it but I suppose it should be, otherwise you'd just have a compiler or decompiler. It's mentioned in the first paragraph of the Wikipedia article [1]. 1. https://en.wikipedia.org/wiki/Source-to-source_compiler https://en.wikipedia.org/wiki/Source-to-source_compiler
- Rochus 5y ago> Is the level same-level-of-abstraction really part of the usual meaning of the term? No. That's just a definition by the author. The languages might operate on the same or close level of abstraction, but that doesn't mean that all logical constructs of the source and the transpiled target have to map. Especially the authors conclusion that a "transpilation is therefore a two-way process where you could go back and forth between languages" is not a necessary feature of a transpiler.
- naniwaduni 5y agoIn actual usage, the main difference between a compiler and a transpiler is usually the speaker's affiliation with JS communities.
- deleted 5y ago[deleted]
- jgwil2 5y agoA transpiler is typically converting from one high-level language to another. Assuming that the level referred to by the phrase "high-level language" is level of abstraction, then yes.
- frou_dh 5y agoNim was diagnosed with an Inferiority Complex?
- turbinerneiter 5y agoThey should add a LLVM backend just to break everyones brain.
- jlokier 5y agoHere's one. https://github.com/arnetheduck/nlvm https://github.com/arnetheduck/nlvm
- FpUser 5y agoCompiler / transpiler. The end result is what matters. If it comes with the decent IDE that allows modern source code level debugging then what do I care. If not than I do not care how nice the language itself is. I've had my fun "debugging" machine codes on a long roll of paper and later using print/beep/flashing LED. No more please.
- deleted 5y ago[deleted]
- wiremine 5y agoFun discussion, but it just a lot of "inside baseball"? Is there a wider-ranging purpose to denoting it Nim is a compiler or a transpiler?
- k__ 5y agoI had the impression we already had that discussion with Babel and TypeScript and the conclusion was, transpilers aren't really different from compilers, and we should simply calling them compilers. I think, the background was the word transpiler was used by compiler creators as a way of gatekeeping.
- naniwaduni 5y agoBest I can tell, it's largely the opposite: "transpiler" is mainly used to sound cool and build hype, traditional compiler folks tend to fall on your side and prefer to call them all "compilers". (The usual term of disparagement in this context is "preprocessor"!)
- k__ 5y agoGood to know! Thanks.
- Zababa 5y agoCompilers and transpilers are the same. The term "optimizing compiler" exists, which probably mean that some are non-optimizing. TypeScript is a great example of that (although it does optimize a few things depending on the target). Babel can be used as a macro system for JS, and macros are compilers.
- chrisseaton 5y ago> I think, the background was the word transpiler was used by compiler creators as a way of gatekeeping. Why do you think that?
- k__ 5y agoThe Babel creator said it.
- chrisseaton 5y agoThat's the Babel creator's opinion. Why's it also yours?
- a99c43f2d565504 5y agoasd
- mhd 5y agoI remember Cfront (C++, ye olden times) being called both a "compiler" and "translator". Does this really matter?
- peanut_worm 5y agoSeems like they’re making up their own definition. I think most people consider a transpiler to be high level => high level while a compiler would be high level => low level Nim, JavaScript and C are all high level languages. Do they gain something from being labeled as a compiler?
- maattdd 5y agoGoing from Nim to C is clearly lowering the language. The general agreed definition of a compiler is going from a certain level to a lower level.
- seanw444 5y agoI guess you get less brownie points for not doing all the steps yourself? Weird to me too. If it works great, it works great, and that's commendable. Also, I'd classify C as a more intermediate language, rather than a high level one. It doesn't hold your hand as much as things like Python. So technically high -> intermediate would be going down a level, I suppose. It's really all just playing semantics. I wouldn't mind if they labeled themselves a compiler or a transpiler. Doesn't really matter to me.
- sieve 5y agoI have just as much respect for those who have written a complete transpiler as for those who have built a complete compiler, because, unless the differences between the source and target languages are trivial, much of the pipeline is identical. If your target is something like C/JS, your translation stage must be fully aware of the idiosyncrasies of the target language. If you are targeting machine code, you will have to include optimization and register allocation stages before generating machine code and the final executable/library.
- xboxnolifes 5y agoI'd argue that a compiler is just a subset of transpilers that target direct hardware instructions (CPU/GPU/some niche specific hardware). Every other argument between the two come across, to me, as more of an emotional arbitrariness of what is a "real" compiled language. Of course, this makes Java, and others, to not actually be compiled. That makes sense to me.