2 ms·
> Both in terms of embedded systems application: What makes micropython safer and easier to develop compared to C/++? Python is a GC'd (reference-counted in CP
by masklinn 9y ago
> Both in terms of embedded systems application: What makes micropython safer and easier to develop compared to C/++?
Python is a GC'd (reference-counted in CPython and probably µpython) and memory-safe language so it should be less prone to memory corruption, although it is more likely to open you up to resource exhaustion.
> In terms of safety, is there better memory allocation and hardware control through Python?
These are not what is usually understood by "safety" in programming.
> I would imagine micropython would be more inefficient
Definitely, the overhead of micropython would be substantial (even more so as it can't leverage compiler optimisations) so it's a tradeoff between hardware requirements and ease of development/time to market. IIRC micropython also supports only a relatively small subset of all embedded systems.
See http://docs.micropython.org/en/v1.8.6/pyboard/reference/speed_python.html http://docs.micropython.org/en/v1.8.6/pyboard/reference/spee..., http://docs.micropython.org/en/v1.8.6/pyboard/reference/constrained.html http://docs.micropython.org/en/v1.8.6/pyboard/reference/cons...
> As for the ease of development, wouldn't C/++ be better?
Generally speaking python is more expressive and more readable than C++ code, which makes it easier to write (develop) Python. C++ is more finicky, thus harder to develop.
- elcritch 9y ago> > In terms of safety, is there better memory allocation and hardware control through Python? > These are not what is usually understood by "safety" in programming. In many embedded and RTOS contexts, safety and allocation and hardware control are very difficult to distinguish. > > As for the ease of development, wouldn't C/++ be better? > Generally speaking python is more expressive and more readable than C++ code, which makes it easier to write (develop) Python. C++ is more finicky, thus harder to develop. C++ is a huge pain with loose type casting behavior (e.g. is this an long or does this expression convert it to an unsigned long?). But then again Python has very _loose_ descriptions of int and float types at all. For me that makes doing bit manipulation for talking to peripherals more opaque rather than less so.
- masklinn 9y ago> But then again Python has very _loose_ descriptions of int and float types at all. Not at all. Python has unbounded-size integers and doubles. There's nothing loose about it.
- icebraining 9y agoIf you want C-like ints and floats, you use ctypes. You have all the typical types, e.g. c_char, c_float, c_int8/16/32/64, c_size_t, etc, plus structs and arrays.