Live data from Hacker News

mJS – A new approach to embedded scripting

mongoose-iot.com

11–20 of 61 posts

Re: mJS – A new approach to embedded scripting

#11
post #10
post #3

I've never worked with embedded systems, so forgive my ignorance. Why is this any more useful than just writing c code, if all the code that actually interacts with the hardware has to be written in c anyway?

The ability to script without the need of rebuilding/reflashing the whole firmware is often fairly useful. The most value is not in JS per se, but in the ability to script.

Ah, I can see how that is useful. Way up in the web dev world I don't often have to think of things like that :)

Re: mJS – A new approach to embedded scripting

#12
post #5
post #3

I've never worked with embedded systems, so forgive my ignorance. Why is this any more useful than just writing c code, if all the code that actually interacts with the hardware has to be written in c anyway?

I'm wondering the same thing. What does having a JS syntax bring to embedded programming?

Scripting is rarely about syntax. It's about being able to load code dynamically, being able to create ad-hoc data structures, quick changes and distributing executables as source rather than binaries.

Re: mJS – A new approach to embedded scripting

#14
post #3

I've never worked with embedded systems, so forgive my ignorance. Why is this any more useful than just writing c code, if all the code that actually interacts with the hardware has to be written in c anyway?

1) A lot of embedded projects have HTTP interfaces for command & control. So that means you usually have somebody on the team who knows HTML & CSS & the giant pile of tech that is web dev these days. Which means they probably are more familiar with JS than C or any other more typical embedded scripting language like Lua.

2) C needs to be compiled and often flashed onto the device to run, sending new JS over the wire to execute is a lot more convenient, especially if you want customers to be able to customize their devices.

Re: mJS – A new approach to embedded scripting

#15
25k of flash space sounds like a lot for what is effectively just a JavaScript parser and interpreter. I recall the days when you could fit a whole language's compiler into a few measly KB. 1KB RAM is also quite a lot for certain boards, especially if it has to be stack or SRAM.

How's the performance? Will my 72MHz Cortex or 16MHz Arduino be able to run interesting things with mJS? If I have to do everything through FFI, what's the benefit vs. e.g. C++11? The latter has nice language features too but compiles to much smaller native code!

Re: mJS – A new approach to embedded scripting

#16
post #3

I've never worked with embedded systems, so forgive my ignorance. Why is this any more useful than just writing c code, if all the code that actually interacts with the hardware has to be written in c anyway?

Haven't you heard that when you want to get close to the metal you drop down to node.js?

Re: mJS – A new approach to embedded scripting

#17
post #12
post #5

Earlier quoted context omitted.

I'm wondering the same thing. What does having a JS syntax bring to embedded programming?

Scripting is rarely about syntax. It's about being able to load code dynamically, being able to create ad-hoc data structures, quick changes and distributing executables as source rather than binaries.

None of which are particularly appropriate for embedded programming.

Re: mJS – A new approach to embedded scripting

#18
post #12

Earlier quoted context omitted.

Scripting is rarely about syntax. It's about being able to load code dynamically, being able to create ad-hoc data structures, quick changes and distributing executables as source rather than binaries.

None of which are particularly appropriate for embedded programming.

Agreed that on-a-whole JS is not appropriate for embedded devices. However allowing scripting may be useful in particular pieces of the code, to allow easy extension / customization.

Re: mJS – A new approach to embedded scripting

#19

25k of flash space sounds like a lot for what is effectively just a JavaScript parser and interpreter. I recall the days when you could fit a whole language's compiler into a few measly KB. 1KB RAM is also quite a lot for certain boards, especially if it has to be stack or SRAM. How's the performance? Will my 72MHz Cortex or 16MHz Arduino be able to run interesting things with mJS? If I have to do everything through…

Nice thing about pain-free FFI is that you can move functionality between the scripting-layer and engine-layer as you see fit. Start in JS, perhaps move pieces down to compiled-lang as they solidify or perf becomes an issue. Maybe only the high-level logic is JS. Or maybe you have JS as "plugin" extension points. Or one could design a domain-specialized "framework", and use JS as the embedding language for an embedded DSL. Acheivable performance would depend a lot on such architectural decisions.

With C++ one would unfortunately have to create C-wrappers, but with say something with easier C interop like Nim or Rust.

Re: mJS – A new approach to embedded scripting

#20

That FFI interface looks way nicer than the node-ffi interface. let f = ffi('int gpio_write(int, int)'); vs. var current = ffi.Library(null, { 'atoi': [ 'int', [ 'string' ] ] });

You could probably write a wrapper to go from the node way to their style.
Post reply on HN