Hacker News new | ask | show | jobs
by kfreds 12 days ago
That seems like a brittle approach to transpilation. A transpiler should translate all of the language's semantics, including resolving identifiers as symbols, and then choose legal names for them in the target language. Also, there is so much more to a language than its surface syntax.

I've never designed a transpiler (I'm not a programmer), but surely the correct approach is to transform the source code into its type-checked AST, and then translate to the target language from there?

3 comments

> A transpiler should translate all of the language's semantics, including resolving identifiers as symbols, and then choose legal names for them in the target language.

Yes, it should; but it also makes things much more difficult. This specific transpiler indeed builds an AST, but does not care about identifiers, just emitting them as is [1] (I hope I found the correct place in the code).

[1]: https://github.com/solod-dev/solod/blob/8485bc867ae0f0269d75...

There is a lot of confusion around those words. I personally make a distinction between a "compiler" and a "transpiler".

A compiler preserves the semantics - if you compile Scheme to C, you get a real Scheme program in C, with full semantics.

A transpiler does not have to guarantee that. It is much easier to transpile Python to JavaScript than it is to truly compile Python to JavaScript. A transpiler can tolerate some amount of leakage between worlds (think 'arguments' as a variable name in Python vs JS).

It really depends on your needs. Sometimes a transpiler is okay, sometimes totally inadequate.

I'm really sorry to be harsh but if you don't use programming languages and have never written a transpiler, why should anyone read your comment?

You critique the approach as brittle and yet the approach you propose doesn't solve the thorny problem gp described of a growing ball of reserved keywords.

I've written multiple transpilers and their comment is how I do it. Safely mapping identifiers is one of those many edge cases you discover as you go along
You may have missed this in their comment:

> resolving identifiers as symbols, and then choose legal names for them in the target language

The responsibility for avoiding collision with the target language is in the transpiler; it should mangle identifiers appropriately to ensure you can't accidentally hit a keyword in the target language.

They technically didn't say that they don't use programming languages, they said they're not a programmer. There's plenty of other people who use programming languages regularly, but not necessarily because they're into them.
> I'm really sorry to be harsh but if you don't use programming languages and have never written a transpiler, why should anyone read your comment?

Lots of reasons. If you can't come up with one then you're not the intended audience, and that's fine.

I made the comment for several reasons. Here's two: (1) I had high confidence that my understanding is correct and wanted to share my knowledge with others. (2) In case my understanding wasn't correct I was hoping someone would correct me, resulting in both me and others learning some interesting nuance.

As for why you in particular should read my comment: Curiosity. There are few traits that are as important to strategic thinking, creativity and success in reaching ones goals as curiosity. When I see something that doesn't map to my understanding of the world my reaction is to wonder whether I'm missing something. It has served me incredibly well so far.

It's kind of hilarious isn't it?

"I don't even write code, yet here is my technical assessment of how a tricky software problem should work".

Are you suggesting Ada Lovelace isn't capable of reasoning about a problem?

You can come up with an algorithm or system without knowing programming. Presumably we can agree the opposite, that being a programmer doesn't give you mystical insight into every programming problem.

Ultimately this isn't even a programming problem.

Timmy writes homework, Jimmy writes homework. They can name the homework however they want. Both go in the same pigeon hole. How can the teacher tell who did which homework?

> It's kind of hilarious isn't it?

It is. I too find my competence profile a bit weird.

I've been interested in security since I was 12 yet never worked full time as a software developer. I have done some coding, but that was over a decade ago, and even then it wasn't very much.

On the other hand I understand the theoretical foundations of formal languages quite well, as well as the engineering required to implement them. I'm comfortable talking about any stage of the compiler pipeline, I can recite the Lambda cube and which logics the interesting corners correspond to, and I'm designing a family of programming languages in my free time.

I understand digital design fairly well too for that matter.