r/Deno • • Jun 15 '22

I wish the manual had plain Javascript examples

I think it would be beneficial to the growth of deno if the manual contained Javascript examples as well as Typescript examples.

I even think this would be useful for Typescript people as a kind of easy-read version of code. Let’s face it, Typescript contains more information than Javascript.

I think this would be true even for very simple examples:

function handler(req: Request): Response { 
  return new Response("Hello, World!"); 
}

Is easier to read without the types:

function handler(req) { 
  return new Response("Hello, World!"); 
}

I know it’s not that big of a deal if you know Typescript, but the thing is, a lot of people coming to deno don’t know Typescript. Having plain Javascript there would be good. Maybe a tabbed interface?

Here’s some very advanced visualization technology:

0 Upvotes

29 comments sorted by

26

u/coolcosmos Jun 15 '22

No, that's a very bad idea.

That only gives more power to those who want to use Deno without knowing Typescript. And encourages you not to learn Typescript. The guide must present the right way, not every ways possible including the bas ones.

It's a hard pill to swallow, but you must learn Typescript. If you don't, just use Node.js.

Is easier to read without the types:

It's not about being easy to read or not. Typescript's not hard to read. There are languages that are way more expressive than it.

5

u/snifty Jun 15 '22

I disagree, and I think Ryan disagrees at least to a degree as well; he has mentioned that he sometimes thinks that adding Typescript support into deno distracts from its goal to be as interoperable with browser standards as possible.

2

u/vorticalbox Jun 19 '22

This is probably why typescript checking is off by default when running a file unless you pass --check

12

u/anton966 Jun 15 '22

Typescript is a bonus but it’s not what defines Deno’s core which is es6 modules, no npm and permissions management.

3

u/[deleted] Jun 15 '22

I don’t think it’s a bad idea. I can live without typescript.

2

u/coolcosmos Jun 15 '22

just use Node.js.

4

u/[deleted] Jun 15 '22

No, I like Deno.

1

u/MinusPi1 Jun 15 '22

Then you use Typescript.

4

u/[deleted] Jun 15 '22

Why? I can use Javascript with deno just fine.

2

u/__grunet Jun 16 '22

FWIW I’ve seen similar discussions play out in the past when it comes to teaching people about web topics like in courses and stuff (whether to include TS on top of the topic at hand)

Not sure how those played out but might provide some more inspiration or opinions

2

u/snifty Jun 16 '22

Reminds me a bit of coffeescript days, although that had nowhere near the momentum of Typescript.

4

u/[deleted] Jun 15 '22

I agree. I think we should talk about js unless/until browsers natively support typescript, if it will ever happen at all.

-3

u/coolcosmos Jun 15 '22

Yeah, you don't get it. It's irrelevant if browsers support Typescript.

4

u/snifty Jun 16 '22

So getting it is using only Typescript, I guess. They why does deno support Javascript at all?

By the way, I’m not trying to pick a fight or troll or something with this thread, I just love deno and I want more people to try it. I really don’t like node at all.

1

u/coolcosmos Jun 16 '22

There is no reason why you'd not use it because it's not in the browser. It provides many advantages for minimal effort.

0

u/snifty Jun 20 '22

Thanks for your thoughts, I guess we have differing interpretations of the goals of deno.

1

u/snifty Jun 20 '22 edited Jun 20 '22

Learning Typescript is on personal my list of things to do, but I work in education and I’m trying to teach people to use Javascript in and out of the browser (much easier than teaching them JS in the browser and Ruby or Python or whatever else outside the browser).

Deno is actually really, really good in this niche. Most importantly of all, installation just works, so you can actually start showing people stuff like file I/O and what an HTTP server does in minutes. The overhead and boilerplate for such things is so low, it’s incredible.

Maybe there are other developers who share an interest in education as a goal, but it seems that the predominant response here is “no way, do not even think of doing that, go use node”. I think it’s a missed opportunity for this little gem of a run time, personally. 🤷

2

u/pcjftw Jun 22 '22

If it's education sector you're in, why teach bad habits in the first place?

JavaScript is a dynamic language, and like all dynamic languages there comes a time when we have to throw our hands in the air and say, damn it static types already solved of these problems I'm suffering from, sure it was a fun ride but I'm not willing to pay the price anymore.

1

u/snifty Jun 23 '22

For one thing, I don’t know Typescript well enough to teach it, and for another, it’s not yet standardized. It seems likely that something much like Typescript will become part of Javascript in the future, but right now that’s not the case.

Right now, if you are trying to teach people a single language for the browser and the server, deno is the only game in town, *if* you are using Javascript on both sides. To me, consistency across those two platforms is very *good* habit, because it’s easy for people to understand the back-and-forth.

Thanks for your thoughts, by the way.

2

u/pcjftw Jun 23 '22 edited Jun 23 '22

A couple of things:

  • You can learn TypeScript in literally a few hours.

  • TypeScript is a superset of ECMASCript 2015, thus ANY legal ECMAScript 2015 is also legal TypeScript. I'm not sure what you mean by standardized, there is only one official compiler tsc that is written and maintained by Microsoft, not even sure what your point here is at all?

  • A single language that you can use on the server and browser is NOT just Deno, that is a flat out falsehood because MANY mainstream languages already can compile down to JavaScript thus run on the browser examples include:

  • Clojure(Script)

  • Kotlin (KotlinJs)

  • Java (vi TeaVM)

  • Rust (JavaScript target)

  • C/C++ via Emscripten

  • GhoperJs compile Go code to JavaScript

  • Pyodide allows you to run Python in the browser via WASM

  • Opal, run Ruby code in the browser

  • GraalVM, allows interop between multiple languages including from Java to JavaScript

There are so many options because JavaScript is a compilation target as well a pseudo "runtime" that is so crazy popular that every language has some way to interop with it.

Personally, I wouldn't teach someone a dynamic language first. I would teach them a static language, that way they can eventually learn dynamic languages later on, get burnt by it multiple times and then come back to static types again.

If they learn dynamic languages first, they'll be mentally scared, and spend so much time and effort trying to fight issues due to dynamic typing, that when they eventually end up in a static language, they'll hate they never picked it up earlier. Then they will be filled with regret.

1

u/snifty Jun 23 '22

I probably shouldn’t be prolonging this discussion, since the general opinion here is that I'm on the wrong train (which is fine, I’m just one person.) But…

A single language that you can use on the server and browser is NOT just Deno, that is a flat out falsehood because MANY mainstream languages already can compile down to JavaScript

It’s the “compiling down to Javascript” part that I think is problematic for a learner. Learning to understand what programming is is hard enough. Having to learn to use a complex tooling infrastructure to make that happen is probably too hard for a learner.

One of the great things, at least IMHO, about deno, is that you can use it with very little tooling at all, while a lot of useful functionality handled by toolchains in other systems — testing, linting, etc — is batteries included via a command-line switch if desired. Super easy and learnable. For me this is a major feature in deno.

Personally, I wouldn't teach someone a dynamic language first. I would teach them a static language, that way they can eventually learn dynamic languages later on, get burnt by it multiple times and then come back to static types again.

Fair enough. That’s all I know. I suppose that there is an argument that I shouldn’t presume to teach programming at all for that reason! But I feel like I can do stuff with what I already know that people in my discipline would want to be able to do too, if they could just get started.

As for getting scared early on by dynamic languages, I guess it comes down to what kinds of things people get scared by in the early days. I feel like the JS/HTML/CSS “ecosystem”, if you will (and I know in a lot of ways that’s too generous a term), can be very fun and motivating for learners. In my experience, early-stage learners are much more motivated by (say) making buttons do visual stuff in the DOM than (say) learning to do the fibonacci sequence on the command line.

Honestly not trying to pick a fight with anyone on this, and I’m gonna let it go since we’re drifting more into questions of philosphy of teaching programming than deno itself. Thanks for your thoughts.

2

u/pcjftw Jun 23 '22

I appreciate what you're saying, and I do actually agree that for a learner modern programming is complex and in an ideal world we should start on something easier, however you have to keep in mind there is a difference between "educational" material/languages Vs industrial languages.

There is also another aspect, which academics don't like to discuss and that's programming isn't actually for everyone, just like how art/mathematics isn't for everyone either.

There was a very controversial but famous paper, I think it was called "the camel with two humps" and basically it found that students fall into two camps:

  • Those that can program

  • Those that cannot.

And academia has spent intense effort in trying to overcome the above but have consistently failed.

If you ask most professional programmers a lot of them will tell you that they were self taught, or that it "just made sense" etc

I think like mathematics and other "specialised" areas, programming is one of those domains.

Now here is the twist:

  • Anyone can learn to "code"

  • Not everyone can learn to "program"

And "'coding" is NOT the same as "programming".

I've personally been blessed with the opportunity to teach others to program, and I have personally seen these two "humps", some of my friends despite my best efforts I just couldn't get them to "program", on the flip side, some of my friends just flew like a kite, and all they needed was a tiny nudge!

1

u/snifty Jun 24 '22

Huh, interesting. Looking back on my own history in programming, I think I would definitely have been weeded out in the early days. In fact, I lived in Silicon Valley! I tried to find a way into the community but I think people categorized me in the “nope” category. It was rough. But I had an external motivation (I wanted to be able to code for the purposes of doing my academic research), so I just kept trying. I don’t know that I’m a “good” programmer now, but I feel like I can make most things that I want/need.

> you have to keep in mind there is a difference between "educational" material/languages Vs industrial languages.

But see, this is exactly where I think deno fits in. It can do both. Python was originally written as a “learning” language, but no one would think of it like that now (it’s on space ships!). Academic programming (depending on the discipline) is going to span the gamut from educational to industrial(-ish). Many, many people just want to be able to parse text files and futz with CSV data and generate HTML pages and stuff like that. For those people, deno is *brilliant*. But the same people might want to take their CSV-futzing program and hook it up to an HTML UI so that their even-less-technical colleagues can use it. (A file input, an import statement to load the parser, an event handler, and a textarea, donesies.) In cases like that, it’s important that Typescript not be a part of the picture.

But deno itself is also very user-friendly in its own right. Installation is easy (that’s HUGE). Just the commands like “install” and the new “task” and (especially!) “compile” (cross-platform binaries?!) are incredibly, incredibly useful for beginners. So maybe it is helpful to talk about the “coding” crowd as opposed to the “programming” crowd, maybe that’s a good way to pigeonhole the people who could benefit (for instance) from JS docs.

2

u/pcjftw Jun 25 '22

Hmm, perhaps it's been so long for me personally that I can't even recall what it was like to be a beginner that to me it seems so trivial (TypeScript Vs JavaScript) mainly because most professional programmers will often juggle multiple languages and especially languages from the same "family" are not seen as something needing any special attention.

maybe it could even be automated, given that TypeScript is compiled to JavaScript, someone could just create a browser extension that does the above visually as soon as you highlight a block of Typescript?

5

u/[deleted] Jun 18 '22

Deno runs Javascript just fine.

You are, however, swimming upstream if you want to develop Javascript with Deno. It is a Typescript ecosystem.

I think once you are more comfortable with Typescript, you will find that the types actually make the code much easier to read, particularly if someone else wrote the code.

I have a buddy who hates Typescript syntax (I happen to be of the exact opposite opinion). So I sympathize if you just don't like it for whatever reason. :)

4

u/starF7sh Jun 16 '22

If we’re talking about marketing points for wider adoption, Typescript shouldn’t be an implied prerequisite to use Deno. Hard agree that having JS examples would be great for new users and perhaps even demonstrate the added value of using TS.

6

u/Hiptomino Jun 15 '22

You could always submit a pull request to the websites repo:

https://github.com/denoland/dotland

5

u/senitelfriend Jun 15 '22

I agree, would be nice. JS is still very relevant whether the more rabid TS advocates like it or not. Maybe not super important and would be a lot of work to convert all examples and maintain. Worth it? idk, the TS code has that self documenting aspect, and quite easy to convert back to JS, so it's not all bad.

3

u/Dergyitheron Jun 15 '22

Typescript is there to encourage you to write more (type) safe code that does a lot of code checks for you and you just have to follow some extra rules compared to JS. Whether there should be JS examples, I don't know but I wouldn't personally add those.