News for hackers. Stuff that matters.
Re:The Rise of Python for Embedded Systems by syntaxing on Thursday July 20, 2017 @10:10AM (#14812558)
Is there a benefit on using Python in terms of performance rather than C/++ for embedded systems? Does Python work well for lower level applications (in terms of hardware access)?
Re:The Rise of Python for Embedded Systems by masklinn on Thursday July 20, 2017 @10:19AM (#14812641)
> Is there a benefit on using Python in terms of performance

If you're talking about machine performances, the opposite, even for a dedicated dialect like micropython. The benefits are in safety, readability and ease of development.

Re:The Rise of Python for Embedded Systems by syntaxing on Thursday July 20, 2017 @10:40AM (#14812861)
Both in terms of embedded systems application: What makes micropython safer and easier to develop compared to C/++? In terms of safety, is there better memory allocation and hardware control through Python? I would imagine micropython would be more inefficient and more prone to hardware error. As for the ease of development, wouldn't C/++ be better? Sure, it's harder to read but C/++ seems like the right tool for this particular job.

I'm pretty curious because I'm pretty fluent in Python and I have been learning C++ for more lower level stuff mainly for speed reasons. I still program most of uC through C++ so I'm curious if I should learn micropython if it provides substantial benefits.

Re:The Rise of Python for Embedded Systems by masklinn on Thursday July 20, 2017 @11:36AM (#14813388)
> 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/spee..., 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.

Re:The Rise of Python for Embedded Systems by elcritch on Thursday July 20, 2017 @12:10PM (#14813712)
> > 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.

Re:The Rise of Python for Embedded Systems by icebraining on Thursday July 20, 2017 @04:07PM (#14815828)
If 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.
Re:The Rise of Python for Embedded Systems by masklinn on Thursday July 20, 2017 @01:10PM (#14814365)
> 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.

Re:The Rise of Python for Embedded Systems by Rotareti on Thursday July 20, 2017 @02:39PM (#14815168)
> Is there a benefit on using Python in terms of performance rather than C/++

No, but you can rapidly develop applications in Python and when performance becomes an issue, you just rewrite certain modules in C/C++/Rust/Go/etc.

There is a module called ctypes [0] in the Python standard lib that lets you import modules written in C.

[0] https://docs.python.org/3/library/ctypes.html

Re:The Rise of Python for Embedded Systems by zwieback on Thursday July 20, 2017 @11:52AM (#14813532)
Definitely the opposite but gluing together highly optimized libs with Python bindings like numpy, OpenCV etc. is a viable approach on higher-level embedded systems to achieve faster development speed.
Re:The Rise of Python for Embedded Systems by ericfrederich on Thursday July 20, 2017 @10:14AM (#14812590)
1) probably not though with Cython you can get close 2) I imagine any hardware access is done though a Python module written in C.

... I'm just speculating. I know nothing about embedded systems

Re:The Rise of Python for Embedded Systems by blattimwind on Thursday July 20, 2017 @10:26AM (#14812698)
> Cython

I wonder why everyone in this thread thinks that Cython works with CPython-incompatible implementations (like MicroPython or Zerynth)?

Re:The Rise of Python for Embedded Systems by ericfrederich on Thursday July 20, 2017 @01:12PM (#14814401)
Aren't there embedded boards that run full CPython? Raspberry Pi runs the full blown CPython doesn't it?
Re:The Rise of Python for Embedded Systems by xapata on Thursday July 20, 2017 @12:31PM (#14813915)
Depends on how much value you get from jit-compiling vs static compiling. It's possible that a jitted language would be faster after a warm-up.
Re:The Rise of Python for Embedded Systems by blattimwind on Thursday July 20, 2017 @10:24AM (#14812689)
Python has a large performance disadvantage compared to C/C++. However, it is much faster to develop even by less skilled workers, thus quicker time to market and lower cost of development.