yes, not a unix os but rather unix-like, and i want to program all of it on python, is that possible?? even the kernel, i want it all python. i know most kernels use c++ or c* but maybe python has a library to turn c* into python?? i’m still sort of a beginner but thanks and i would appreciate the answers

  • MajorHavoc
    link
    fedilink
    arrow-up
    5
    arrow-down
    1
    ·
    edit-2
    9 hours ago

    The essence of your answers is “yes, but…”. And the “but” is mostly about how slow Python is in contexts that need to be astonishingly fast.

    It depends how complex the hardware is and how much time we’re willing to waste.

    Technically, when I deploy a Python program to a BBC Microbit, that’s (more or less) what is happening. Pure Python code is making every decision, and is interacting directly with all available hardware.

    We could still argue semantics - virtually no computer exists that isn’t running at least one tiny binary compatibility driver written in C.

    I believe the compiled C binary on a BBC Microbit to bootstrap a pure Python OS is incredibly small, but my best guess is that it’s still present. The C library for Microbit needed to exist for other languages to use, and Python likes calling C binaries. So I don’t imagine anyone has recreated it in pure Python for fun (and slower results).

    (Edit: As others have pointed out, I’m talking about MicroPython, which is, itself written in C. The Microbit is so simple it might not use MicroPython, but I can’t imagine the BBC Microbit team bothered to reinvent the wheel for this.)

    Of course, if you don’t mind that the lowest level code has got to be binary, and very few people are crazy enough to create that code with Python, then…

    It begs another interesting question: Just how much of an OS can we get away with writing in Python.

    And that question is answered both by RedHat Linux and Debian Linux - and the answer is that both are built with an awful lot of Python.

    In contrast, Android is mostly Java with lots of C. Windows is mostly C# and lots of C. iOS is mostly Objective C and lots of C.

    You can have an OS built with almost any language you want, as long as you also want parts of it built in C.

    An interesting current development is discussion around rebuilding parts of the Linux Kernel with Rust, which can run just as fast as C. This would effectively cause RedHat, Debian and Android to replace some of their C code with Rust. To date, there’s been a lot of interest and discussion and not a lot of (any?) actual funding or work completed.

    • litchralee@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      3 hours ago

      While I get your point that Python is often not the most appropriate language to write certain parts of an OS, I have to object to the supposed necessity of C. In particular, the bolded claim that an OS not written in C is still going to have C involved.

      Such an OS could instead have written its non-native parts using assembly. And while C was intentionally designed to be similar to assembly, it is not synonymous with assembly. OS authors can and do write assembly when even the C language cannot do what they need, and I gave an example of this in my comment.

      The primacy of C is not universal, and has a strong dependency on the CPU architecture. Indeed, there’s a history of building machines which are intended for a specific high-level language, with Lisp Machines being one of the most complex – since Lisp still has to be compiled down to some sort of hardware instructions. A modern example would be Java, which defines the programming language as well as the ISA and byte code: embedded Java processors were built, and thus there would have been zero need for C apart from legacy convenience.