What's a good first project using JavaScript in Snap!?

I am attempting to begin learning JavaScript as it is what I am learning at school. Would anyone know what projects would be good for letting me dip my toes into JavaScript within any larger Snap! project?

Discussing the use of JavaScript is discouraged on this forum :slight_smile:

Why? I want to use it as it relates to Snap! because of the javascript block. Is there anything I can do under which it's fine to talk about JavaScript?

This is a forum to discuss Snap! :slight_smile:

There are plenty of other places to discuss JS but only this place to discuss Snap! :slight_smile:

In olden times, the JS block was used to overcome some limitations in early Snap!

But since those days, and particularly when V7 came out, the need for Snappers to have to use JS, to achieve most end results, diminished greatly

The Snap! team have asked many times for people not to discuss JS, so it's just polite to follow their wishes :slight_smile:

Oh, okay.

It's also discouraged to learn javascript though snap

Let me give some context for this.

We originally added the JS Function block as a way for people to access browser features that we hadn't yet implemented in Snap!, such as media computation support that keeps growing since HTML5. There's nothing wrong with this practice, and there's nothing wrong with asking questions of the form "Snap! doesn't have primitives for the such-and-such new browser feature; can you help me make a library in JS?" in the forum.

What we don't like is when people use JS Function to write in JS control structures that do exist in Snap!, such as FOR loops. Every once in a long while people do projects that aren't fast enough in Snap!, such as real-time computation and display of the Mandelbrot or Julia sets, and so they write the inner loops in JS, and that makes us sad because Snap! wasn't fast enough for them but doesn't make us angry. (It happens much less often since we implemented hyperblocks, which are super fast!)

The problem with talking about JS in the forum is that we are desperately trying to get people beyond the dozen JS programmers here to use the forum, so that it really serves Snap! users of all levels of expertise, and we fear that when the forum fills with JS code that scares people away. (What really makes us furious is when someone posts a real question about how to do something in Snap!, something that can be done perfectly well in Snap!, and some kid replies with "you can just do that in JS" or the like.)

The canonical JS Function blocks are one-liners:


...which really don't help you much in learning how to program in JS. If that's your goal, you should bite the bullet and do it in Khan Academy or w3school or whatever, where you write the entire program in JS.

I would never do that... I don't know JS

But in all seriousness, I understand how you want the welcoming atmosphere for the Snap! Forums. I joined relatively recently and I can see myself being discouraged if I was immediately shown a whole heap of JavaScript, as by then I was sort of frustrated by non-block code.

I know, I wasn't criticizing you. Just, everyone dumped on you for starting this thread, and I thought that was unhelpful without a longer explanation of why we discourage turning this into a forum about JS.

but these inner loops could be put into snap blocks and then we could have all that potential for those kind of projects (which let me tell you, its more than once in a long while. maybe im in the wrong place but im a sucker for style and you guys got it)

its like you all are trying to hide the fact that snap is written in javascript. it seems only natural to me to wonder how the blocks work. im building my own blocks but what exactly am i using? how are these super secret 'primitive' blocks defined that i cant look at? how can i change these primitives to my own liking, rather than the person who made them, i mean that is the whole idea isnt it? build your own blocks. except we have to use the blocks youve given us.

but then again, im the type of guy that will break some of my 1x6 plates to make 1x5 pieces because lego doesnt(didnt) make them.

Why don't you ask the same question about the JS primitives? They're implemented somehow, too.

Even if you dig down to the level of machine language, you can still ask how that's implemented by the hardware! It's abstraction all the way down.

i do and I have, it's crazy to me how languages are implemented in other languages, snap in javascript, javascript in c or c++, c is just a level up from assembly I'm pretty sure, and then it's just machine code. I guess you can call logic diagrams and schematics a level of abstraction too. but under that there's actually little bits doing these calculations. transistors and whatnot, so I wouldn't say it's abstraction all the way down.

and even if it was, or say this idea of following down to the roots entirely, was impossible, I still don't see that as a reason not to aim for that goal. sure you won't 'achieve' it but you will certainly be progressing towards it. otherwise your basically just saying sour grapes and end up traveling in the other direction. which isn't wrong by any means but it does seem to contradict the intentions behind snap.

I've learned a little JavaScript through Khan Academy.

This is a question of interest to me because I wrote the lesson about levels of abstraction for BJC.

There are a bazillion levels of abstraction in computing (I picked nine levels to talk about) but the tl;dr is that there are two major abstraction barriers: the software/hardware barrier and, below that, the digital domain/analog domain barrier. In the digital domain every wire is either at ground (0) or at power supply level (1). In the analog domain you have to think about things like fanout -- if you connect too many inputs to the output of a gate, its voltage eventually drops to where you can't be sure if it's 0 or 1. The analog domain is about transistors. Below that there are levels of abstraction in physics: the holes-and-electrons model of transistors, then the way they really work, which depends on quantum effects, so below that there's particle physics, in which you learn that an electron is really made out of strings or something. (I'm not a physicist, in case that isn't obvious.) But I lose interest once we're below the digital abstraction, except just to know that there is an analog level further down.

But there's a big philosophical difference between us. I love abstraction. If I'm able to build an abstraction that lets people think in terms closer to the real problem they want to solve, instead of having to think about how computers work, I'm happy to live my entire life above that abstraction. Only if the abstraction fails, and needs to be debugged, do I ever want to think below the abstraction barrier. But you, like many other people, want to know how things "really" work. I think that makes it much harder to learn. For example, people who want to trace through a recursive procedure have a harder time understanding and believing in recursion than people who are willing to accept that they should take on faith that the recursive call correctly solves a smaller problem, and from that starting point convince themselves that the proceduree uses that result from the recursive call to build a result for the original problem.

I'm not saying you should turn into a different person who's more like me. Just that when teaching beginners, trying to drill down to the metal doesn't help them.

I understand. Also, oh no this became a discussion thread :skull: :moyai:

Also I can't believe that cameron uses illegal building techniques

learn about what, exactly? when you teach someone the ropes of an abstract model your not teaching them 'how it really works', and that's what im learning about when I dive down to the roots of things. I think it's only harder to learn simply because im learning about more than just the model. but I wouldnt necessarily say it's any harder, if we were were to put learning difficulty to stuff learned I say it's the same. what it really depends on is the how interested the person is in learning about this or that, it only becomes hard when you lose interest but still have to learn about it. I think that might be where your coming from, or at least that the difference in my eyes.

lol what do you mean illegal

I guess it depends if you want to be a CS person or a EE person. You seem to be going the EE route, which is fine. But you can be great at CS living at the top of the abstraction hierarchy.

What does that stand for?

Snap! is designed to be a programming language and environment in its own right. I think you should find something else better suited for JavaScript. Maybe code.org or one of those JS code sandboxes...