News for hackers. Stuff that matters.
Re:Let’s Stop Bashing C by hodgesrm on Friday December 02, 2016 @11:58AM (#13090235)
As another example could you write a device driver in a language like Python?

I was frankly a little disappointed in both the referenced article and the one it references. C basically is assembler. If you have a problem that needs hardware-level access you'll need things like pointers. The really hard parts of C (like handling null pointers or lack of concurrency primitives) seem to be the flip side of this access. Whether you use things like braces just seems to be a matter of taste.

Re:Let’s Stop Bashing C by a3n on Friday December 02, 2016 @12:05PM (#13090286)
> As another example could you write a device driver in a language like Python?

Sure, with Cython or a Python C extension. :)

Re:Let’s Stop Bashing C by RUG3Y on Friday December 02, 2016 @12:10PM (#13090339)
My thought exactly =)
Re:Let’s Stop Bashing C by luhn on Friday December 02, 2016 @12:32PM (#13090560)
Of course Python isn't up to the task of device drivers, but C isn't the only language that can do that. You could write a driver in Rust, which is a significantly safer language than C.
Re:Let’s Stop Bashing C by hellbanner on Friday December 02, 2016 @01:45PM (#13091144)
Why are C & Rust available to write drivers but Python cannot? Is this because Python is too abstracted, where C & Rust have access to the physical hardware without the need for an API?
Re:Let’s Stop Bashing C by gdwatson on Friday December 02, 2016 @06:33PM (#13093226)
Python has a much more complicated runtime system which assumes a lot of things that wouldn't be true for a driver. It could probably be adapted to work, but it's a square-peg/round-hole situation.

By comparison, C's runtime is very simple and assumes very little, so it's good for writing code in a kernel or integrated system where many OS services won't be available to you. It's also much faster, of course, and it gives more direct access to memory.

Re:Let’s Stop Bashing C by hellbanner on Monday December 05, 2016 @12:43PM (#13107372)
Thank you! So essentially because C gives you direct access to memory -- I remember you have to allocate array sizes which are literally contiguous blocks on your hardware -- you can control things directly. THanks
Re:Let’s Stop Bashing C by xorxornop on Friday December 02, 2016 @02:33PM (#13091539)
C and Rust compile to native code. Python doesn't. It's either interpreted, or run in an abstract machine (VM). Python was never really intended to interact with the actual hardware directly.

I mean, you could, there's no real technical blocker, but it'd be horribly slow. Plus many failure modes of touching hardware are very likely to break the VM process and make debugging very challenging

Re:Let’s Stop Bashing C by khedoros1 on Friday December 02, 2016 @05:46PM (#13092998)
I think that the real blocker is raw pointers. You need to be able to read+write data to specific memory addresses for most hardware, and I don't think Python's capable of that.
Re:Let’s Stop Bashing C by dbaupp on Friday December 02, 2016 @06:32PM (#13093224)
Python is capable, via the ctypes module.

The problems include:

- performance: implementations being interpreted, and relying on dynamic typing mean that Python is almost always slower than compiled languages.

- the run-time: Python assumes that things like allocations are always OK, and generally requires more operating system support than is available in low level environments.

Re:Let’s Stop Bashing C by khedoros1 on Saturday December 03, 2016 @04:44PM (#13097660)
Thanks for the reminder. I had it at the back of my mind that CPython is just about built as an abstraction on top of C, and so should be capable of anything C is, depending on where you wanted to draw the line between the languages.
Re:Let’s Stop Bashing C by zeveb on Friday December 02, 2016 @12:38PM (#13090606)
> As another example could you write a device driver in a language like Python?

You could write one in Lisp, which is in many ways a language like Python, but which does support bit twiddling & pointers if desired.