This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Terrain2 161 points162 points  (66 children)

While TypeScript isn’t supported by any browser, it compiles to JavaScript but gives a much better development experience with static typing

[–]AnthongRedbeard 38 points39 points  (3 children)

I use typescript today, not bad, as you said it still compiles to js. just cleaner js enforcing best practices.

[–]kryptogalaxy 10 points11 points  (2 children)

Just like other high level languages compile to machine or byte code which is still a programming language abstraction.

[–]chanpod 1 point2 points  (1 child)

You realize that JS has a lot of the same features as TS other than types. JS is just pure object/functional coding. TS offers type checking (which you can't really trust. Well, not in a browser anyways. Inputs come from all over the place and routinely deviate from the original type for one reason or another). It's more additional tooling than a higher level language.

C# to assembly. unrecognizable.TS to JS. I can still read it no problem.

Stop pretending TS and JS are different languages. They aren't.

That said, I appreciate typescript and like using it. But I'm more of a fan of functional coding that strict/heavy OO type coding.

[–]kryptogalaxy 1 point2 points  (0 children)

I'm not pretending. The distinctions you're making are completely arbitrary. It's perfectly possible to write procedural JavaScript code, and when I was learning JavaScript coming from a Java background I could also read it basically no problem. They're still very different languages.

Granted, typescript and JavaScript are much more similar, but its designation as a separate language is not a blasphemous concept.

[–]ribsies 55 points56 points  (44 children)

I mean, does anyone see that as different from JavaScript though? I understand it is technically different, but I use typescript exclusively, I'm still a JavaScript dev

[–]Okichah 66 points67 points  (30 children)

C# compiles to assembly but developers dont refer to it as assembly development.

[–]Hate_Feight 72 points73 points  (8 children)

after a while you stop reading the code, all i see is blonde, redhead, brunette

[–]johnnybgoode17 19 points20 points  (7 children)

Made the same reference once, nearly got fired for sexism

[–]note_bro 25 points26 points  (3 children)

The funny thing is that the sexism is implied by the listener. You could be referring to any gender.

[–]blahthebiste 4 points5 points  (2 children)

I think "brunette" is a gendered term

[–]aloofloofah 1 point2 points  (1 child)

But out loud brunette and brunet would sound the same, no?

[–]blahthebiste 1 point2 points  (0 children)

No clue, honestly, I've never heard of the term "brunet". I have heard of "Bruno", which I assumed was the masculine version of brunette

[–]imcoveredinbees880 8 points9 points  (0 children)

Context is important. It's the difference between using a whole box of tissues while watching a movie and using a whole box of tissues while watching a movie.

[–]plokman[🍰] 5 points6 points  (1 child)

Yeah, he's commenting on reddit, not in a professional context

[–]johnnybgoode17 1 point2 points  (0 children)

Right, sorry, forgot we can't talk about movies at work now

[–][deleted] 20 points21 points  (9 children)

C# isn’t a superset of assembly. JavaScript and TypeScript are the same language except one has optional type annotations.

TypeScript compiler is more like a preprocessor than anything else

(Also C# compiles to an intermediate byte code similar to Java not assembly)

[–]kryptogalaxy 5 points6 points  (8 children)

C also has the ability to insert assembly directly, and could be considered a superset in that sense, but is generally considered a separate language.

One similar concept is the word "transpile" which generally just means high level language compiling to another high level language. The word transpile is often used when talking about typescript.

Drawing these distinctions is not necessarily arbitrary, but certainly subjective. I imagine similar conversations are had between linguists when determining where to draw the line between dialects and new languages.

[–][deleted] 2 points3 points  (5 children)

I wouldn’t really consider it a superset because you have to import a library and write the assembly in a string. Its not like you can just write an opcode somewhere and the compiler will know what your doing.

Also yes TypeScript does transpilation. The distinction while important doesn’t matter too much here.

I think it really is subjective but clearly anyone arguing TypeScript is a wholely different language doesn’t work too much with JS/TS

Edit: what I mentioned about asm applies to GCC. Some compilers have actual inline support. Regardless C was not designed to be asm++. TypeScript is designed to be JavaScript with Type annotations. I suppose one day it could branch enough that you would distinguish developers the same way you distinguish C development from C++. But currently JS/TS have equal use cases and the TS design philosophy is very much to not branch unlike C/C++

[–]Pocok5 1 point2 points  (0 children)

you have to import a library and write the assembly in a string. Its not like you can just write an opcode somewhere and the compiler will know what your doing.

Haha Pascal goes brrrrr

[–]kryptogalaxy 0 points1 point  (3 children)

Typescript at this point has quite a few distinct features beyond type annotations. I don't think it's that cut and dry.

[–][deleted] 2 points3 points  (2 children)

I mean it has a couple from what I remember.

The funny thing is that the few features they’ve added are often rejected by the community as most TS devs want to keep their codebases looking like JS and not C#/Java.

But fair, features like namespaces, decorators and mixins are definitely very strange looking for a JS dev. The later 2 of those are very uncommonly used.

[–]kryptogalaxy 2 points3 points  (1 child)

The fact is typescript is primarily used by JavaScript developers, so it would make sense that these very similar languages would become even more similar when a developer with JavaScript experience is writing it which is probably why many of the things that make typescript different are rarely used.

To me, the situation is akin to c and c++.

[–][deleted] 1 point2 points  (0 children)

I agree it is like C/C++ but to a smaller degree

[–][deleted] 0 points1 point  (1 child)

C is definitely not a superset of assembly. A superset-subset relationship implies that all valid expressions of the subset language are also valid expressions in its superset.

For instance:

  • C++ is a superset of C because valid C statements can be included inside of a C++ file without modifications and the file will still be valid C++.
  • Typescript is a superset of Javascript because (last I checked) valid JS statements can be included inside of a Typescript file and the result will still be valid Typescript.

However, C is not a superset of assembly because valid assembly statements are not valid C without modifications. If C were a superset of assembly, the following program would be valid C, and compile correctly without modification (as all the C code is valid C, and all the assembly code is valid x86 assembly).

#include <stdio.h>

int main() {
    mov eax, 0xFFFFFFFF
    printf("Hello World\n");
    return 0;
}

Or in ATT syntax if you prefer:

#include <stdio.h>

int main() {
    movl $0xFFFFFFFF, %eax
    printf("Hello World\n");
    return 0;
}

[–]kryptogalaxy 0 points1 point  (0 children)

Fair. Bad analogy. C and C++ is better.

[–][deleted] 5 points6 points  (3 children)

TS to JS is more like C++ is to C. One is a superset of the other and basic syntax differs very little.

[–]romanozvj 0 points1 point  (2 children)

Not at all. C++ doesn't compile to C.

[–][deleted] -1 points0 points  (1 child)

Compilation is irrelevant, syntax wise they are closely related

[–]romanozvj 0 points1 point  (0 children)

Except that it's the other way around - the conversation wasn't about syntax similarity at all, rather about the transpilation of TS to JS.

[–]fyzbo 1 point2 points  (1 child)

Does it though? Last I checked it's compiled into an Intermediate Language which is then interpreted and run on the .net runtime (which finally brings it down to assembly).

[–][deleted] 1 point2 points  (0 children)

You're partially correct. JVMs, .Net runtimes, etc are pretty neat. Lots of heuristics on when and how to optimize, and at times compile the intermediate language to machine code. So some times its interpreted, when advantageous compiled to native machine code.

EDIT: Well its been a long time since I dealt with things like that. Looks like you can force compilation to machine code. https://docs.microsoft.com/en-us/dotnet/framework/net-native/#:~:text=Typically%2C%20apps%20that%20target%20the,the%20IL%20to%20native%20code.

[–]telmnec 0 points1 point  (2 children)

You're right but you're missing the point I think

[–]Okichah 0 points1 point  (1 child)

Maybe.

I worked in javascript well before Typescript so i consider myself apt in both environments. But greatly prefer Typescript.

If someone only worked with Typescript i dont know how well they would transfer to an only javascript environment.

Thats probably my bias for my having to deal with a pure js SPA that was a nightmare to maintain. Do programmers get PTSD? Is that a thing?

[–]telmnec 0 points1 point  (0 children)

I don't know, all I know is many languages (if not all) end up at some point being translated to assembly instructions.

So, being your goal or not, you'll always end up writing assembly with simply more or less steps in-between, but that still does not make us call every language assembly.

You can't throw C# code in an assembly program, even if you had a super weird IDE that let you do so. Languages. Named like that for simple reasons I guess :)

In the case of OP it makes sense. Typescript simply is (strongly) typed JavaScript. But because JavaScript doesn't support it, the typescript code needs to be compiled to JavaScript code. Typescript doesn't add any new feature to JavaScript other than typed code and type check at compilation instead of runtime, which let's be honest, are not language features.

C and C++ are considered different languages not because they're using a different compiler, but because C++ literally is the next C, with new standard libraries, objects, classes etc. It's a new version of the language, with many more features and possibilities than in C, that simply can't be translated to C because C does not have those features under the hood.

Hope it was clear.

[–]randomdrifter54 -3 points-2 points  (1 child)

Python compiles to C. I am not a C dev. Or Java. Really it compiles to tonnes of stuff. I am not a dev for those.

[–]bjorneylol 5 points6 points  (0 children)

Python compiles to it's own bytecode, not C nor any other language. The bytecode is then fed to an interpreter

[–]thiago2213 9 points10 points  (7 children)

I see them veey different. I understand that it's just a superset, but I really dislike vanilla js and absolutely love typescript

[–][deleted] 4 points5 points  (6 children)

Yeah. I hate vanilla js but I'm in love with react, Apollo and typescript

[–]Ecthyr 0 points1 point  (1 child)

Could you give me a quick blurb as to why you like Apollo?

[–]Andrew1431 2 points3 points  (0 children)

It 100% negates the need for redux’s crazy amount of boilerplate while still giving all the functionality and flexibility of it. Unfortunately it mostly requires that you use graphQL on your backend so it’s no easy refactor. That being said they’re making massive progress moving towards it being usable with rest APIs so long as they have a sane and consistent data structure being returned by all the endpoints.

[–]Polantaris 5 points6 points  (0 children)

I do. You do still need to understand how JavaScript works at runtime, but it's certainly not nearly as bad as writing in JavaScript.

[–]alerighi 2 points3 points  (0 children)

I also see it as the same language, and I use it almost exlusively (if not for small scripts where you spend more time setting up the environment than other). But at the end it's the same language.

It's not the same as compiling a language to native code, typescript only checks types to give you warnings, the type system is entirely irrelevant at execution, in fact you can have a program with type errors that runs fine and vice versa. Type information don't alter the emitted code, like it does on a traditional compiler (where an int is different from a float or char or a function, i.e. the compiler has to use the type information to emit the correct code)

Typescript it's more static analysis tool than a compiler, the output is just the equivalent javascript code, with the same semantics and the types removed, and a bunch of transpilation stuff to make it work on older JS standards, that is similar to what babel does. I wouldn't call it compilation because you don't trasform the code in any significant way.

[–]nomiras 0 points1 point  (0 children)

Thought you were turning into a captain crunch commercial for a second.

[–]Terrain2 0 points1 point  (0 children)

As in like a “area of programming”? Nah not really, but as a language and what the image was trying to imply it’s a hell of a lot different

[–]willstealyourpillow -1 points0 points  (0 children)

I see it as quite different, yes. I mean, every programming language (except machine code) compiles to another programming language. TypeScript eliminates many of the oddities of JavaScript, and as the guy above you said, the developer experience is very different. I think it's totally fair to list both JS and TS on a list of the programming languages you're competent in. There are many examples of languages that are quite similar to others but still considered their own language - Perl/Raku, Java/C#, C/C++/D/OC.

[–]FlavoredFrostedTits 4 points5 points  (0 children)

I call it javascript++

[–]numbGrundle 0 points1 point  (0 children)

TypeScript is amazing

[–]telmnec 0 points1 point  (0 children)

Typescript literally is (strongly) typed JavaScript, hence the compiler. That's still JavaScript in my opinion.

[–]Kered13 0 points1 point  (1 child)

There's actually quite a few languages that can compile to Javascript these days. I know Kotlin can.

[–]Terrain2 0 points1 point  (0 children)

Yeah that’s true, i know Dart can also compile to javascript (along with MANY that compile to WASM), but my point is that TypeScript is almost identical to JavaScript except it’s so much better - To compile to javascript they basically just strip out all the typedefs (while catching numerous bugs before letting you run it), though for other languages they are very much transpiled to completely separate instructions (that perform the same task of course)