DEV Community

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

Collapse
 
sancarn profile image
Sancarn

I think we should ask ourselves, what's the definition of a "programming language". Typically, programming languages are formal languages (comprised of syntax and semantics) which perform operations on data. Does typescript tick those boxes? It definitely has a syntax, and that syntax has meaning. The syntax is different to JS so it cannot be seen as the same language as JS.

JSX on the other hand has syntax and semantics, but doesn't perform any operations. The operations are performed by embedded typescript/javascript. So i feel this is the distinction here. The same can be said of HTML <button onclick="var x=1; console.log(x)">, here we have an embedded language which performs operation, but the language HTML doesn't perform this data on its own accord.

Conclusion: TypeScript can be seen as a language with which you can perform operations on data. Therefore it can also be seen as a programming language. JSX, like HTML, can only be seen as it creates a syntax tree (AST/hierarchy) but doesn't perform any operations on data itself.

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

Here's another idea that, for some reason, only occured to me just now:

Is Flow its own language???

I've never heard someone say that they only like to code in Flow. In fact, such a statement would be borderline nonsensical. Because Flow doesn't run by itself. It only runs inside of JavaScript.

Now believe me, I'm not trying to delve into any kinda analysis about Flow vs. TypeScript. From my vantage point at least, it feels like TS, basically, "won". But there's still a lotta Flow-based code hanging around out there. And it's, by no means, a "dead" construct.

If JSX is not a standalone language (and I'm not actually claiming that it is), and if TS is a standalone language, why doesn't Flow have the same status???

Collapse
 
matthewbdaly profile image
Matthew Daly

I think Flow is a better approach than Typescript, because it doesn't try to be more than a type system for Javascript. It's just an add on for the language. However, I think both Flow and Typescript should be considered as transitional solutions.

In the longer term there should be a push in Javascript to add native support for some sort of type annotations for Javascript, and Flow annotations seem like a good starting point for that.

Thread Thread
 
bytebodger profile image
Adam Nathaniel Davis

In the longer term there should be a push in Javascript to add native support for some sort of type annotations for Javascript

This is basically how we got to TypeScript. A good while back, Microsoft was actively participating in the ECMA standards group, and they were all poised to introduce much of what we now call TypeScript as part of the next ECMA spec. But at the last minute, there was a lot of debate and protest and MS's proposed changes got pulled. Eventually, MS released them as its own open source project - and now we have TypeScript.

Collapse
 
jwp profile image
John Peters • Edited

Sancarn,

Nice points. It made me recall an automated testing tool named QTP now renamed UFT.

Their documentation made a big deal of the words Imperative vs. Declarative programming techniques.

Is HTML a language? It's minimally a declarative one, just like JSX. It could be argued that Typescript is a declarative offshoot of Javascript. Ok by me...

No matter what we call this stuff, we have to learn how to 'speak and read it'. In that sense it's a language.

Collapse
 
elmuerte profile image
Michiel Hendriks

HTML is a language, a markup language. But not a programming language. HTML does not result in an executable program. Of course you can make an interpreter for HTML which imposes a specific grammar so that it turns into a programming language, but that would not really be HTML anymore. It would be another esoteric programming language.

Declarative programming languages are commonly based on the declaration of facts, rather than describing a control flow. SQL or Prolog are examples of declarative programming languages.

JSX is JavaScript mixed with markup. Basically syntactic sugar for templating markup. It doesn't not really define a new language as it's basically JavaScript with the requirement of a specific pre-processor for processing the inline templates. So it does make JSX a programming language language, but that's because it's essentially JavaScript.

TypeScript on the other hand is a new programming language. Just because its primary output is a different programming language, for which it also offers interoperability makes no difference. I think you can compare TypeScript to JavaScript as you can compare C++ to C.

To continue on about JSX, TypeScript also has a "JSX" mode where the XML templating of JSX is supported in TypeScript, so basically TSX. Is TSX a new language? no, it's part of TypeScript.

Thread Thread
 
jwp profile image
John Peters

I try to stay away from minute definitions of a language, as I see no value in the discussion. If I need to read, write, speak or hear about something in order to understand and synthesize; then to me, I'm speaking a language.

Some cultures mix English with their native language. To us it a non-understandable mix of two, but to them it's a perfectly legitimate way to communicate.

Thread Thread
 
elmuerte profile image
Michiel Hendriks

I'm a programmer, an engineer. Being as much as correct, or maybe clear, as possible is in our nature. Making clear distinction in kind of languages is important. This isn't about making one kind of language inferior to the other. It's about setting boundaries in domains. Ambiguity is a huge problem. This is a primary reason why natural languages are extremely difficult to process. This is why TypeScript was made, weakly typed languages, like JavaScript, significant issues in correctness which strongly typed languages have not.

I live in a country where English, and other languages, are mixed with out native language. Especially for English we have grammatical rules how these borrow words are supposed to be transformed in various constructions. But mixing Dutch with English, German, and French has no absolutely no effect on the type of language which is applied. It is still the same kind of language, so called natural language. But even with language language, there is a special class dubbed legalese. It's a more formal application of natural language, but way less formal than languages commonly used by software.

Thread Thread
 
jwp profile image
John Peters • Edited

I don't disagree, but I do know that my knowledge of Programming languages has also taken on my own style in using them. It's similar to an accent in a spoken language. I don't feel that any one accent is better than any other; however; accent or not, if there's a violation in what is written or spoken; then that, and only that is of concern. It's exactly why I like Typescript because it makes me more cognizant of making things safer. The last thing I want to do (again) is to release a bug to production because of some really stupid accidental thing I did. I like Typescript coupled with Unit Tests because it builds confidence. I also love C# for Back-end work because it's safe.

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.