Live data from Hacker News

DeviceScript – TypeScript for Tiny IoT Devices

github.com

71–80 of 160 posts

Re: DeviceScript – TypeScript for Tiny IoT Devices

#71
post #34

Earlier quoted context omitted.

it's not C, so that's a great step towards making programming IoT more accessible.

Well that's valid as long as you don't get exception in underlying C driver. Now you are solving two possible problems - error in your script or error in the driver. Good luck debugging that without proper debugging probe.

That's been the argument against higher level languages since punch cards.

Sure, there may be problems, yet somehow the internet runs.

Coding in asm is fun, and a good skill to have for when you need it - but most of the time, you don't.

Re: DeviceScript – TypeScript for Tiny IoT Devices

#72
post #46

Earlier quoted context omitted.

What exactly do you miss? JS has built-in reflection, eg `typeof instance`, `instance.constructor.name`. Even multiple dispatch can be hacked together if you really need it, eg there is a library @arrows/multimethod.

Those don't change that the type system is structural; the type system is actually not fully safe if you use the things you mention, eg: class Dog { woof(){} } class Cat { meow(){} } function f(a: Dog|Cat) { if (a instanceof Dog) { a.woof() } else { a.meow() } } let dogish = {woof: ()=>{}} f(dogish) This compiles because dogish is structurally a dog, the type system allows instanceof to narrow the type but "dogish in…

Yeah don't do that. :)

Do this:

  interface Dog { typeName: "Dog"; woof():void }
  interface Cat { typeName: "Cat"; meow():void }
  
  function isDog(a:Dog|Cat) : a is Dog {
    return a.typeName == "Dog"; // Some casting may be required here
  }
  
  function f(a: Dog|Cat) {
    if (isDog(a)) a.woof();
    else a.meow();
  }
  
  let dogish : Dog = {typeName:"Dog", woof: ()=>{ console.out("Woof this is Dog")}};
  f(dogish);
The neat thing about TypeScript's type system is that it's structural but you can pretty easily implement nominal types on top of it.

(And if you only need compile-time checks, you can make typeName nullable; {typeName?:"Dog"} != {typeName?:"Cat"})

Re: DeviceScript – TypeScript for Tiny IoT Devices

#73

Earlier quoted context omitted.

There are a number of reasons to do this. This sort of setup typically has the VM runtime flashed into the microprocessor's program space with the interpreted byte code stored in data space --- either internal or external. 1) It is obviously not as fast as native but it is fast enough for a lot of applications. In embedded work, you don't get extra credit for being faster than necessary. Speed critical functions like…

3 is a big one, I think. Using an interpreted language speeds up the development cycle to prototype, change, release, and iterate. And for some purposes it's fast and small enough, that the trade-off is worth it.

This makes a lot of sense. However, it makes me wonder how big is the new attack surface for remote upgrades/updates.

You need to implement a safe updater (with remote protocols) on VM level. And I guess you can never upgrade the VM itself, or if you can, it adds some extra complexity, or physical access.

There also need to be some kind of signature validation for every release, which means that device needs to perform some cryptographic operations and store at least tamper-proof public keys.

Re: DeviceScript – TypeScript for Tiny IoT Devices

#74
post #60

Earlier quoted context omitted.

I agree, this will mostly go nowhere. Sure when somebody will prepare you DeviceScript environment for *your* board, then you are good to go. But in 99% of cases, you will get hardware in front of you which almost certainly is not supported by DeviceScript. And now without intimate knowledge of C, how are you going to expose interfaces of that particular hardware, so you can work with those interfaces in DeviceScript…

The target audience for such runtimes are teams with general software engineer skills, and less embedded skills, and little hardware skills. They are likely to weight software support (including drivers) very heavily when selecting hardware. This reduces how often the scenario you describe will come up, compared to traditional hardware development.

Yep.

For example, it supports ESP32.

Every problem sure starts to look like a ESP32 nail if I have this tool chain available.

Re: DeviceScript – TypeScript for Tiny IoT Devices

#75
post #17

Is the only reason for this to make it possible for web developers or people who know TypeScript to write code for IoT Devices? To fill the lack of experienced low level programmers? Because as language alone, I don't see a reason why I should I ever use this if I am not familiar with TypeScript already.

TypeScript development on VScode is excellent (I'm told) so that would be a reason for this.

Excellent tooling exists for you if your language is TypeScript, so maybe try putting TypeScript in more places.

Re: DeviceScript – TypeScript for Tiny IoT Devices

#76

Earlier quoted context omitted.

Well that's valid as long as you don't get exception in underlying C driver. Now you are solving two possible problems - error in your script or error in the driver. Good luck debugging that without proper debugging probe.

That's been the argument against higher level languages since punch cards. Sure, there may be problems, yet somehow the internet runs. Coding in asm is fun, and a good skill to have for when you need it - but most of the time, you don't.

The problem is not higher level language. The problem is that you are essentially running dual-stack firmware with twice as complexity and twice as problems.

And C vs assembly comparison is irrelevant. You are running assembly represented by C, but not interpreting C in assembly written VM.

Re: DeviceScript – TypeScript for Tiny IoT Devices

#77

Do they really need to "Embrace, extend, and extinguish" micropython?

This is not the case here, because:

- It's a different language/project, therefor no embrace or extending happening.

- It's just 2 hackers working in microsoft, we don't have to dismiss their work because their employer actions years ago.

- It's open source.

Re: DeviceScript – TypeScript for Tiny IoT Devices

#78
post #73

Earlier quoted context omitted.

3 is a big one, I think. Using an interpreted language speeds up the development cycle to prototype, change, release, and iterate. And for some purposes it's fast and small enough, that the trade-off is worth it.

This makes a lot of sense. However, it makes me wonder how big is the new attack surface for remote upgrades/updates. You need to implement a safe updater (with remote protocols) on VM level. And I guess you can never upgrade the VM itself, or if you can, it adds some extra complexity, or physical access. There also need to be some kind of signature validation for every release, which means that device needs to perfo…

I can't really see how this is different from a native-code based device, especially one which is actually following good practice by not trusting what's in flash. Every stage of the boot chain still has to validate the next - there's just one more layer on top where the application is the runtime VM and it has to validate sub-applications / managed code.

Re: DeviceScript – TypeScript for Tiny IoT Devices

#79

Earlier quoted context omitted.

That's been the argument against higher level languages since punch cards. Sure, there may be problems, yet somehow the internet runs. Coding in asm is fun, and a good skill to have for when you need it - but most of the time, you don't.

The problem is not higher level language. The problem is that you are essentially running dual-stack firmware with twice as complexity and twice as problems. And C vs assembly comparison is irrelevant. You are running assembly represented by C, but not interpreting C in assembly written VM.

Then I guess you'd better avoid any sort of embedded libc implementation too.

Or fadecandy, or any external library.

I've been through hell in embedded systems land debugging chipmaker-supplied C compiler problems.

Should I just write it all in asm then? I've certainly made that choice for some projects.

The point is, at some point you just want to get things done and you have to trust your tool chain.

Post reply on HN