DEV Community

Discussion on: Is TypeScript Really... A Language??

Collapse
 
bytebodger profile image
Adam Nathaniel Davis • Edited

I appreciate the feedback. But with all due respect, I think your characterizations of TS & JSX are a bit... incomplete.

I think we should ask ourselves, what's the definition of a "programming language".

I didn't really wanna get into this level of "nerd-dom" in the original post, but there are some pretty good definitions out there of what makes a programming language a "real" language. One of the most commonly used is that of being "Turing complete".

Comp Sci people like to throw around that phrase because it sounds haughty. But if you look into what's needed to be "Turing complete", it's incredibly simple. With the desire and a little bit of research, you, me, or most other programmers could actually spin up our own Turing complete language in a weekend. Most of the features we see in modern languages go farrrrrr beyond what's needed to be "Turing complete".

The syntax is different to JS so it cannot be seen as the same language as JS.

Is it really?? I know I'm oversimplifying here, but the main point where we see differences between JS and TS is in the interface between functions/classes and in the assignation of variables. Granted, in a typical TS (or JS) app, there are a lot of places where we're assigning variables or defining function/class interfaces. But even then, the only "difference" is that, in TS, you have to declare your types. But most of the basic language constructs look the same between TS and JS - because they are JS. TS doesn't have, say, its own syntax for while loops or switch blocks - because those constructs are JS.

For example, if you want to see how TS handles iterators and generators, you can look here: typescriptlang.org/docs/handbook/i...

Hmm... that looks a whole lot like... JavaScript. That's because it is JavaScript. In fact, there's nothing on that page that varies from core JavaScript - because it is JavaScript.

So if the "language" provides some features that allow for additional type security, but the core features (the ones that are needed to be "Turing complete") are all just JavaScript features, have you created a new, standalone language??

To put this another way, when you decide to use TS in your project, you install it, as a package. Correct me if I'm wrong, but I don't believe it's possible to run TS without JavaScript, right??

I'm not saying this kills the idea of TS being its own language. As stated in the original article, PHP only runs in C. But if I want to spin up a PHP project, I don't first say, "Hmm... let me get the C compiler installed and running first, and then I'll install PHP." All that C magic is happening silently in the background.

In fact, it's common to find junior PHP devs who don't even know that PHP ultimately runs in C. The obfuscation is so complete that it's entirely possible to program in PHP for years without ever thinking (or knowing) about the underlying C. Are there any junior TypeScript devs who don't actually know that TS is running in JavaScript? Is that even possible to be so oblivious???

Furthermore, even if you're a master PHP programmer, that doesn't at all mean that you could immediately switch to C and just know what you're doing. Much of PHP's syntax is ported directly from C. But there are still so many differences that the "Master PHP guy", trying C for the first time, would be quite lost for at least a little while.

But if you've only learned TS, and one day, for some reason, someone said, "Hey... this particular thing must only be coded in plain-ol' JS," how long do you think it would take you to switch to base JavaScript? A day? A few hours, maybe? My contention is that the transition would be incredibly swift - because it's the same language.

JSX on the other hand has syntax and semantics, but doesn't perform any operations. The operations are performed by embedded typescript/javascript.

If you're saying that a JSX tag is actually a function call, then yeah, I agree with you there. But just as TS provides some syntactic "flair" to the way that we assign variables, JSX provides its own syntactic "flair" to the way that we call functions.

The same can be said of HTML , here we have an embedded language which performs operation, but the language HTML doesn't perform this data on its own accord.

I'm not quite seeing the analogy. HTML is a markup language. And by browser convention, it can be used to call JavaScript functions based on user actions (or, to embed JavaScript code right alongside the markup).

When you do this in JXS:

<UserDetail userId={someUserId}/>
Enter fullscreen mode Exit fullscreen mode

You're not embedding a JavaScript call inside of some static markup. <UserDetail userId={someUserId}/> is a function call. It's functionally equivalent to:

UserDetail(someUserId);
Enter fullscreen mode Exit fullscreen mode

Maybe this is splitting hairs, but the distinction feels significant (to me).

JSX, like HTML, can only be seen as it creates a syntax tree (AST/hierarchy) but doesn't perform any operations on data itself.

You didn't say this directly, but I feel like this statement conflates the markup of HTML with the function calls of JSX - which are only made to look like markup tags.

None of this is meant to "tear down" your arguments. In typical nerd-like fashion, I find the debate/discussion to be very interesting. And I truly appreciate your feedback.

And despite what might be inferred from my original post, I'm not trying to argue that JSX should actually be considered to be its own language. I'm only questioning whether TS has actually cleared that bar.

Please let me know where I've got it wrong!

Collapse
 
sancarn profile image
Sancarn

I didn't really wanna get into this level of "nerd-dom"

In order to answer the question "Is TypeScript really a programming language", you need to define what you mean by a programming language. I don't see this as nerdy. It's like asking "Is a cod an animal?" will always depend on the definition of what an animal is.

The syntax is different to JS so it cannot be seen as the same language as JS.

Is it really???

A syntax is made from a grammar. The grammar of TS and JS are different. E.G.

function greet(greeting: string): string {
   return greeting + " world";
}
Enter fullscreen mode Exit fullscreen mode

is not valid JavaScript. This is because types are not part of the JavaScript grammar. Because the grammar is seperate, the syntax is seperate and thus the languages are seperate. You wouldn't call C and C++ the same language just because their for loops look the same. C is very different to C++ even though they may act in similar ways.

Correct me if I'm wrong, but I don't believe it's possible to run TS without JavaScript, right??

You can, compile to WASM.

But if you've only learned TS, and one day, for some reason, someone said, "Hey... this particular thing must only be coded in plain-ol' JS," how long do you think it would take you to switch to base JavaScript? A day? A few hours, maybe? My contention is that the transition would be incredibly swift - because it's the same language.

The switch from Java to C# is virtually instant. Arguably more so than from TS to JS. That doesn't mean Java and C# are the same language though.

You're not embedding a JavaScript call inside of some static markup

I beg to differ. I'm not talking about what is actually hapenning under the hood. I'm talking about the semantics of the language. Like let's take a look at HTML:

<button onclick="console.log('hello world')"/>
Enter fullscreen mode Exit fullscreen mode

semantically can be seen as: <button onclick="EMBEDDED JS"/>

Similarly in jsx:

<button onclick={()=>console.log('hello world')}/>
Enter fullscreen mode Exit fullscreen mode

semantically this can be seen as: <button onclick={EMBEDDED JS}/>. Realistically JSX is embedding the JS (with the same syntax as plain JS) between the parenthesis {...}.

Don't get me wrong, HTML and JSX are still languages. They have their own syntaxes and semantics. The difference between them and languages like JS/TS/C/C++/C#/Java/Lolcode is that they merely produce templates, (or at least their common use is in creating templates).

JSX/HTML result in a template (or AST), it isn't generally seen as computing.

TS/JS result in a computed output.

It's a bit of a grey area, I'll give you that much as you might even be able to formulate a JSX expression which does compute, but as this is not its common/typical use case, I would argue it still can't be classified as a real programming language, akin to JS/TS.