6 ms·
> I think that we could find ways to make equally memory-safe languages that go about enforcing safety in entirely different manners than with ownership and lif
by adwn 9y ago
> I think that we could find ways to make equally memory-safe languages that go about enforcing safety in entirely different manners than with ownership and lifetime semantics.
Of course, but at the cost of requiring a garbage collector. Mandatory GC has three main drawbacks:
* It makes it harder and much less convenient to call libraries in this language from other languages.
* Low-resource embedded systems are a no-go.
* GC is typically a tradeoff between speed and memory usage. Manual memory management can be very fast and very lean.
- pjmlp 9y ago> Low-resource embedded systems are a no-go. Only if talking about microcontrolers with few hundred KB, where even C is a challenge. There are Java and Oberon implementations for single digit MB, like Cortex-M4.
- StudentStuff 9y agoEven the ESP8266, where ram & flash are measured in kilobytes can run a minimal version of python. This whole "low resource can't run heavy languages" trope needs to die.
- turbinerneiter 9y agoComparison of a sensor fusion algorithm the likes of which are used in quadcopters: | impl | c | py3 | mpy | pypy3 | cy3 | |------|-------|--------|---------|-------|-------| | [ns] | 0.176 | 11.462 | 37.633 | 0.818 | 0.590 | | .c | 1.000 | 65.126 | 213.824 | 4.648 | 3.352 | mpy - MicroPython cy3 - Cython So, ... low resource can't run heavy languages fast (yet?). Good thing is by using MicroPython and writing the time critical stuff in C you can get the best of both worlds while paying the least. edit: sigh, markdown table
- majewsky 9y agoIf you add two spaces in front of each line, it formats as monospace. Like this: | impl | c | py3 | mpy | pypy3 | cy3 | |------|-------|--------|---------|-------|-------| | [ns] | 0.176 | 11.462 | 37.633 | 0.818 | 0.590 | | .c | 1.000 | 65.126 | 213.824 | 4.648 | 3.352 | Also, I'm taking a guess here and assuming that the values in the second line mean "execution time as multiples of the execution time for C".
- turbinerneiter 9y agoYes, it was `*c`, but the star screwed up formatting even more ;)
- adwn 9y ago> There are Java and Oberon implementations for single digit MB, like Cortex-M4. So? Just because you can use a language on a given system doesn't mean that you should use it in any serious context. A GC typically makes memory usage and execution latency non-deterministic, or at the least very hard to analyze. If your washing machine software OOMs whenever the GC didn't run between two button pushes, you'll have a great Heisenbug.
- pjmlp 9y agoWell, I happen to consider factory control management, weapon targeting and missile tracking systems, some big serious context. Here is just one of them. http://www.militaryaerospace.com/articles/2006/10/lockheed-martin-selects-aonix-perc-virtual-machine-for-aegis-weapon-system.html http://www.militaryaerospace.com/articles/2006/10/lockheed-m... "PERC Ultra offered Lockheed Martin the responsiveness it needed to meet its most demanding timing requirements. In addition to real-time threading and deterministic garbage collection, PERC Ultra provided the instrumentation and VM management tools necessary to support the mission-critical real-time requirements of the Aegis Weapon System." "The Lockheed Martin-developed Aegis Weapon System is the sea-based element of the U.S. Ballistic Missile Defense System. The Aegis Weapon System is a radar and missile system integrated with its own command and control system, capable of simultaneous operation defending against advanced air, surface, and subsurface threats." Is that serious enough for you?
- pjc50 9y agoIs this where we bring in the anecdote about the missile flight control system which never freed any memory, because the minumum time to OOM was less than the maximum flight time of the missile?
- tjalfi 9y agoAsk and ye shall receive[0]. [0] https://news.ycombinator.com/item?id=14233542 https://news.ycombinator.com/item?id=14233542
- vardump 9y ago
- blattimwind 9y ago> Only if talking about microcontrolers with few hundred KB, where even C is a challenge. C is the default and not a challenge on 8-bitters.
- pjmlp 9y agoSo which compiler does offer 100% ANSI C compliance on something like a Z80 or PIC?
- flohofwoe 9y agoSDCC is standard compliant (even up to C11) and has support for Z80: http://sdcc.sourceforge.net/ http://sdcc.sourceforge.net/
- pjmlp 9y agoThanks for pointing it out, I wasn't aware of it and it does look good, but they clearly state the uses cases which it isn't fully ANSI C compliant on page 24 of the documentation.
- vardump 9y agoI think you're nitpicking. That's close enough in my book. Those MCUs are tricky targets and I can certainly live for example with not being able to pass structs as return values. Or without re-entrancy. Perfectly understandable once you take into account limited IRAM space, 128 or 256 bytes, where stack, register banks and most of your temporaries and globals need to reside.
- deleted 9y ago[deleted]
- jules 9y agoWhy does GC make it harder to call libraries in other languages?
- jonathanstrange 9y agoBecause you have to add support for GCing of foreign structures from these libraries, or keep the interface low-level and force the user of the GCed language to manually manage these foreign objects. Adding support for GC can be difficult if not impossible, because GCs often arrange memory in special ways (different pools, etc.) whereas the foreign library probably just uses malloc.
- humanrebar 9y agoLanguages interfacing through an ABI implicitly need to agree on their memory models, calling conventions, exception unwinding, etc. There's lots of detail in the D language garbage collection docs: https://dlang.org/spec/garbage.html https://dlang.org/spec/garbage.html The whole thing might be instructive, but 28.3.3 has a bunch of particular expectations of the D GC.
- adwn 9y agoWhat I meant was: If language X needs a GC, then writing a library in X makes it difficult and very inconvenient to use that library from another language. The comments of jonathanstrange and humanrebar are also spot-on.
- lmm 9y agoWhen you're working in a GCed language you assume your language's GC is responsible for freeing memory. When you interoperate with a language where owners are responsible for freeing memory, you have to have a way to "disown" structures you've created but passed into the ownership language (e.g. a callback you've passed to a library function) so that your GC doesn't free them, and a way to "own" structures you've received from the ownership language (e.g. values returned from library functions) so that your GC does free them, and neither of these things will be easy/natural in your language. When you interoperate with another GCed language it's even harder, virtually impossible, because both languages' GCs assume they own everything and so anything that's visible in both languages will be freed twice.