266 points · by dannyobrien · 3y ago · 97 comments
What stood out for me is the ability to pre-create constant objects and put them mostly into ROM, so that the RAM is only used for the actually mutable data. This is something you can't have with MicroPython or Lua, AFAICT, and this makes a lot of difference in MCUs where ROM / flash is plentiful, and RAM is scarce.
If your module contains stored data in the form of an immutable object, like a string or bytes(), it will be read straight out of flash without copying to RAM first.
This needs you to run some code on a desktop computer to perform the freezing though.
https://docs.micropython.org/en/latest/reference/constrained...
Though I guess part of the pitch for micropython is being able to iterate without a flash step every time. Possibly addressed by having your dev boards fitted with a version of the MCU with enough RAM to run it all that way.
So a convenient workflow is to deploy at runtime (ie not in flash) until you stabilise your code base or approach production; at which point you can freeze your code into your firmware.
For an even more convenient model, there is the proposal to support 'mapfs' so that some flash will be allocated to store code. You can then compile your Python to bytecode (with `mpy_cross`) and upload it to - and run from - this area at runtime.
Although this feature has been demonstrated as a proof-of-concept, there are some subtleties to sort out before it hits mainline. If you're interested in the feature, please read or comment on the PR:
As far as I can tell, the combination of all three of the above is the equivalent to tasmota + tasmotizer + berry?
I guess what I am asking for is how does developing on the ESP32 when using toitlang + toit SDK compare to issuing commands against Tasmota using berry?
What's the performance & memory usage compared to Lua?
How sandboxable is it? Can you run untrusted code through it?
If this language is a valid alternative with a simple struct and a basic constructor, I may recommend it to remove all the Python scripts and their dependencies.
Honestly, off by one errors due to indexing was a lot harder to shake than getting used to meta tables.
Just curious. I’ve been kicking around some attempts to make programming simpler (though hopefully no less powerful) for casual programmers. Lua’s 1-based indexing gets a lot of critiques and, while I haven’t written a ton of Lua, can’t help but think that the critiques are due to us all being used to 0-based indexing. Which is a valid critique, especially for a scripting language, but one that applies less to novices.
I've used several projects requiring non-trivial configuration that, instead of requiring you to write hundreds of lines of yaml, simply let you write Lua or Starlark/python, which feels so much better to me. I'm always missing autocompletion and reflection though. There doesn't seem to be a good candidate for this, pretty much all small embeddable scripting languages are dynamically typed...
Though https://dhall-lang.org/ demonstrates that you can statically type quite a lot of configuration to great advantage, which appears to be programmatically embeddable in multiple languages per https://docs.dhall-lang.org/howtos/How-to-integrate-Dhall.ht...
Erm... Berry good :)
Composition and interfaces tend to produce less convoluted designs, and the most obnoxious problem with multiple inheritance ("diamonds") has to be explicitly addressed at the call site, rather than by meditating on the globally-determined method resolution order.
A language with good constructs for convenient call-signature reuse and redirection at the function level could probably skip implementation inheritance.
Having an ECBS system: one could model all the permutations as described while keeping code concise, shareable, and non-repeatable. Unity is really an ECBS.
Inheritance vs non is as old as OOP vs functional. Each has their place, each has their pros and cons. Having functional components and behavior traits attached to object inheritance based entity nodes is probably the best of all composition. Entities can get more and more complex with inheritance chains (further classifying what components can be attached), components can include behaviors, data, events/triggers, sub-components. Behaviors (triggering events or waiting for) is where your game logic would mostly reside.
Nowadays if I write Lua, I mostly see metatables as a memory usage optimization. If you have thousands of small objects with many methods, and all of them share the same set of methods, it makes a lot of sense to have a single vtable, to save some memory. Otherwise I wouldn't bother, it's not like Lua lets you control struct member padding to ensure they fit in a single cache line.
1. It appears straight forward to add native functionality to berry.
2. Berry has the ability to compile code to ROM.
Maybe xs has that functionality too, but I don't see it anywhere in the top levels of it's docs. One thing I see missing from the berry docs is the debugging process. That could be a rather significant drawback of it isn't easy.
(eg syntax, compilation, etc)
Tiny JavaScript-like interpreter. It's pretty small. You might be able to glean insight.
Presumably the source for this project would be insightful as well. It appears like there is more code for berry script compared to ucode though.
The type system (especially for Rust and Haskell) forces you to always handle the error, or you have a compilation error. With some syntactic sugar (? in Rust, do notation in Haskell), you can be as concise as exception-based languages.
That's actually a good fit for coroutines! Cooperative multi-tasking can be very useful in single-threaded environments; it's basically syntactic sugar for a state machine. Lua has had coroutines since 2003, so I'd be curious why Berry chose to omit them.
1. Starts out fast, compact and lightweight. 2. Bugs and corner-cases get fixed. 3. Features demanded by users get added. 4. No longer fast, compact or lightweight.
Underemployment for the last 3 years has given me a great opportunity to dive deeper into a lot of CS topics for things we use daily and read (or at least try to read) specs and code bases etc.
I’ve come to firmly believe that languages or other open source projects that get popular, usually do so for the things that are in its early versions.
For example, the HTTP 0.9 spec is like 1 page. UDP is like 3 pages.
I’d seen an article on HN recently (cant remember the name) that described this well. A language or what not starts simply and many jump on the bandwagon. Then starts adding incremental features, none of which are difficult to incrementally learn for existing users but the footprint of the product keeps expanding. C++, Javascript, Web APIs, graphics languages like OpenGL all are examples in my eye.
The fact that our system (broadly speaking) incentivizes inventing something ‘new’ rather than fixing or simplifying an existing something certainly exacerbates this.
That's what we see in software development: a runaway process of elaboration and ever-increasing complexity and levels of abstraction.
Sort of like if the Peter Principle and Parkinson's Law had a child.
https://en.m.wikipedia.org/wiki/Peter_principle
https://en.m.wikipedia.org/wiki/Parkinson%27s_law
Or just Zawinskis Law:
https://en.m.wikipedia.org/wiki/Jamie_Zawinski#Zawinski's_La...
2. Ok that didn't work too well we've added static type hints.
Does anyone know of any good embedded statically typed languages? It seems to be a very unexplored design space. The only real ones I know of are AngelScript (which catastrophically fails rule 0 of programming languages) and Gluon which is just a bit too weird and aggressively functional for me.
--
github.com/civboot/fngi
It was super fun. I'm going to be going in a different direction (Lua implemented in Lua, with Lua-library assemblers and assembly type system), but it's certainly very possible
Try and find an AngelScript example. It's stupidly hard. Compare it to these web sites:
https://koka-lang.github.io/koka/doc/index.html
Sadly Rust fails this too but at least the Playground is only one click away. And Rust is mainstream anyway so it doesn't matter as much. I completely failed to find a single AngelScript example accessible from my phone's browser. Even its Wikipedia page doesn't have any.