Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Is it possible to make a minimalistic operating system using Python?
I really don't want to get into low-level code like assembly, so I want to use a simple language like Perl, Python. But how?
Unfortunately Python is classified as a very high level programming language. It cannot be used, for example, to directly access hardware and perform low-level data structure manipulation. It is completely dependent on something to abstract the hardware from it, and that is the Kernel. It is, however, technically possible to create an operating system centered on Python, that is; have only the very low level stuff in written in C and assembly and have most of the rest of the operating system written in Python.
This article discusses with more detail what languages are suitable for writing operating system kernels.
You can certainly run Python without an OS, as shown by the The Intel BIOS Implementation Test Suite (BITS) Project. The scripting guide explains:
"... includes Python APIs to access various low-level functionality of the hardware platform, including ACPI, CPU and chipset registers, PCI, and PCI Express. You can write scripts to explore and test platform functionality, using the full power of Python in 32-bit ring 0, without an OS in the way.. "
Now, BITS is a BIOS testing platform specific to Intel hardware, and not meant to run a custom Python based OS, but that doesn't mean you couldn't try it...
I have ported Python interpreter to run in my operating system as a userspace program, it was the first program - and so far the only - that I ported; from this experience, I'd say it would certainly possible to write lots of the operating system functionality in Python; you can certainly even embed Python in the kernel with rather minimal feature support.
However you need to write assembly and C for the interrupts, low level memory management and so. In my case, I built a specially modified Python 2.5.2 against the Newlib C library; in minimal case you just need to provide heap memory management for the Newlib library, and you can have Python running on top of it.
As such, Python interpreter does not contain its own heap implementation, and it does depend on the C library, so you cannot run it on bare metal right away, but much more of the operating system kernel as is conventionally written, could also could be written in Python.
The special case of course are the microkernels, where much of the functionality is in userspace as services; these can be more naturally implemented in any preferred programming language, Python included.
I suggest you find a good textbook on operating system design, and study that. I'm pretty sure you won't find such a book with Python source code; C is more likely. (You might find an older textbook that uses Pascal instead of C, but it's really not that different.)
Once you have studied operating systems design enough to actually be able to write an operating system, you will know enough to have your own opinions on what languages would be suitable.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am planning on creating a software that will be used to analyse biological data, some of us biologists would not have much programming skills yet we do alot of repetitive tasks and are required to write more scripts or programs that we always use using.
i have decided to narrow it down to only one very important task, its a searching script, i.e to query a database of genes-(data), there is already a program that does that called ncbi-blast, usually one needs to be familiar with command line and also requires ubuntu or windows, but its a hassle if you have to analyse the huge quantities of results generated.
so i have want to package some of my python scripts into a software so that others can find it convenient to analyse their work
Open vs. Closed Source (Licensing)
i intend to make some of the functionalities freely available to the user in the software, although at a later stage, i intend to incorpaorate pipelines that would require an affordable license
testing
so with this one function, it makes testing alot simpler-i dont know yet, and i would not mind starting with linux-ubuntu and windows as the platforms.
I appreciate your advice on choosing just one language, and i will go with python, how ever i would like tyhe software to atleast support other free programs created in other languages like R, as in plugins that a client installs when they need them.
I hope this shades more light to my already complex situation
Thank you
Sounds like you're at the beginning of an adventure and some new learning curves. I will applaud your willingness to create. Here are some things to consider as you get started on your journey.
fyi: "software" is typically a single word, no space.
Based on the context of "a soft ware" it seems like you mean "application".
I mention "software" and "application" not to give you a hard time about it, but because I think 1) it will help you in future searches when you look for ways to get something done (e.g. you'll get more useful hits on "python application installer" than "python soft ware installer", and 2) you can more clearly explain to people what you are attempting.
So. Your application(s) will need a user interface for your collection of scripts. Do you want a graphical user interface (GUI)? Or a command line interface (CLI)?
GUI: more complex than CLI:
For a GUI it will be more complex to get something that runs on both Windows & Linux.
So far as I know there isn't a trivial way to create a single GUI that runs on both Windows & Linux without adding another tool. Maybe python has easy GUI user-interface stuff in it and you could use that.
For perl I will point you here: "Perl GUI programming on Windows" Perl GUI programming on Windows
This lists some Perl approaches to consider, you will have to research them and see which ones are also able to run on Linux. Be careful about including additional libraries you'll need to package (or document how to install) with you application.
CLI: more simple than a GUI:
Since they are just scripts today, I would suggest starting with a CLI which probably means cleaning up your argument handling ( #ARGV in Perl, I can't comment on Python).
Read through your code and find literals that you change when you run a script for something new, those things will become your arguments. And if it starts to seem like you are creating too many arguments maybe you want to look into a configuration file (properties file of some kind).
It will be easier for you to get started with a CLI and you can always come back and add a GUI option in a future release. I find that designing a well thought out CLI makes it easier to focus on what is important for a GUI so it should help your eventual GUI be even better.
Packaging
Packaging your application is going to be a challenge.
Do your scripts need any libraries that aren't part of default with python & perl installs? If so you need to work out a way to supply those (e.g. include them with your distribution or include documentation that your users can follow to download and install the libs).
I can't comment on pyinstaller.
For Perl I will point you to this question on distributing a Perl Application : Distributing a Perl Application
User Skill
How much skill do you expect your users to have?
Will they be ok with installing a python and perl interpreters if necessary? Not every user has that technical skill.
Do you want to make sure your scripts verify the minimum versions of python & perl they need?
Documentation
See User Skill, above. You will need to make documentation available.
This will be driven by who is going to use your scripts. What is your target user like? Can you write a "5 line" summary that would make me want to download them and try them? That will be a helpful exercise to help you focus on how you want to present the scripts.
Open vs. Closed Source (Licensing)
This also ties into licensing. Are you aiming for a commercial product? Giving the world another gift of open source? Those are both fine things to do, but you'll want to choose a suitable license for your application. You also have some work to do if you want to avoid distributing your script's source code (I'm not suggesting you pursue one approach or the other, just that you make the decision before you put it on the internet at large).
Testing
Testing your application is going to be a challenge.
If you don't have automated tests for your scripts you will go crazy trying to verify it runs everywhere you want it to run.
Do you have unit tests & test suites for your scripts so you can verify they run correctly on different versions of Windows and various Linux distributions?
If your scripts are pretty simple maybe it doesn't matter if they're running on 32 bit vs. 64 bit operating systems.
Maybe it doesn't matter if they run on Windows 10, Windows 8.x, Windows 7.x, maybe various versions of Windows Server (2012, 2008, ...).
Maybe it doesn't matter if they run on RedHat, Suse, Ubuntu, Mint, ...
You probably want some sanity checks to verify that your install program worked correctly and the environment is suitable.
Without knowing what your scripts do it is kind of hard to say how much testing they benefit from.
Free Advice: choose just one scripting language and run with that
I will end with some completely free advice (worth what you're paying for it :-) )
Think really hard about just choosing one scripting language and writing everything in that.
You are going to have a LOT of additional complexity from supporting two scripting systems, if I were doing something like you describe I would Seriously Consider consolidating into a single language and just to Python or just do Perl. The time and energy it takes you to rewrite your Python scripts as Perl (or the other way around) may very well be easier compared to learning about creating installation guides and packaging your application using two different languages.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This is proving to be a very difficult question for me to figure out how to properly ask.
For example, the Python interpreter is written in C. Say you wrote another interpreter in Python, that got compiled through CPython. And you then intend to run a program through your interpreter. Does that code have to go through your interpreter and then CPython? Or would the new interpreter be self-contained and not require CPython to interpret it's output. Because if it is not a standalone interpreter, then there would be a performance loss, in which case it would seem like all compilers would be written in low level languages until the end of time
EDIT:
PyPy was the very thing that got me wondering about this topic. I was under the impression that it was an interpreter, written in Python, and I did not understand how it could be faster than CPython. I also do not understand how bytecode gets executed by the machine without being translated to machine code, though I suppose that is another topic.
You seem to be confused about the distinction between compilers and interpreters, since you refer to both in your question without a clear distinction. (Quite understandble... see all the comments flying around this thread :-))
Compilers and interpreters are somewhat, though not totally, orthogonal concepts:
Compilers
Compilers take source code and produce a form that can be executed more efficiently, whether that be native machine code, or an intermediate form like CPython's bytecode.
c is perhaps the canonical example of a language that is almost always compiled to native machine code. The language was indeed designed to be relatively easy and efficient to translate into machine code. RISC CPU architectures became popular after the C language was already well-adopted for operating system programming, and they were often designed to make it even more efficient to translate certain features of C to machine code.
So the "compilability" of C has become self-reinforcing. It is difficult to introduce a new architecture on which it is hard to write a good C compiler (e.g. Itanium) that fully takes advantage of the hardware's potential. If your CPU can't run C code efficiently, it can't run most operating systems efficiently (the low-level bits of Linux, Unix, and Windows are mainly written in C).
Interpreters
Interpreters are traditionally defined as programs that try to run source code directly from its source representation. Most implementations of BASIC worked like this, back in the good ol' days: BASIC would literally re-parse each line of code on each iteration through a loop.
Modern languages
Modern programming languages and platforms blur the lines a lot. Languages like python, java, or c# are typically not compiled to native machine code, but to various intermediate forms like bytecode.
CPython's bytecode can be interpreted, but the overhead of interpretation is much lower because the code is fully parsed beforehand (and saved in .pyc file so it doesn't need to be re-parsed until it is modified).
Just-in-time compilation can be used to translate bytecode to native machine code just before it is actually run, with many different strategies for exactly when the native code compilation should take place.
Some languages that have "traditionally" been run via a bytecode interpreter or JIT compiler are also amenable to ahead-of-time compilation. For example, the Dalvik VM used in previous versions of Android relies on just-in-time compilation, while Android 4.4 has introduced ART which uses ahead-of-time compilation intsead.
Intermediate representations of Python
Here's a great thread containing a really useful and thoughful answer by #AlexMartelli on the lower-level compiled forms generated by various implementations of Python.
Answering the original question (I think...)
A traditional interpreter will almost certainly execute code slower than if that same code were compiled to "bare metal" machine code, all else being equal (which it typically is not), because the interpreter imposes an additional cost of parsing every line or unit of code every time it is executed.
So if a traditional interpreter were running under an interpreter, which was itself running under an interpreter, etc., ... that would result in a performance loss, just as running a VM (virtual machine) under a VM under a VM will be slower than running on "bare metal."
This is not so for a compiler. I could write a compiler which runs under an interpreter which runs under an interpreter which has been compiled by a compiler, etc... the resulting compiler could generate native machine code that is just as good as the native code generated by any other compiler. (It is important to realize that the performance of the compiler itself can be entirely independent of the performance of the executed code; an aggressive optimizing C compiler typically takes much more time to compile code than a non-optimizing compiler, but the intention is for the resultant native code to run significantly faster.)
I am working with an ARM Cortex M3 on which I need to port Python (without operating system). What would be my best approach? I just need the core Python and basic I/O.
Golly, that's kind of a tall order. There are so many services of a kernel that Python depends upon, and that you'd have to provide yourself. I'd think you'd be far better off looking for a lightweight OS -- maybe Minix 3? -- to put on your embedded processor.
Failing that, I'd be horribly tempted to think about hand-translating to C and building the essentials on that.
You should definitely look at eLua:
http://www.eluaproject.net
"Embedded power, driven by Lua
Quickly prototype and develop embedded software applications with the power of Lua and run them on a wide range of microcontroller architectures"
There are a few projects that have attempted to port Python to the situation you mention, take a look at python-on-a-chip, PyMite or tinypy. These are aimed at lower power microcontrollers without an OS and tend to focus on slightly older versions of the Python language and reduced library support.
One possible approach is to build your own stack machine in software to interpret and execute Python byte code directly. Certainly not a porting job and quite labor-intensive to implement, but a self-contained Python byte code stack processor built for your embedded system gets you around needing an operating system.
Another approach is writing your own low level executive (one step below a general purpose OS) that contains the bare minimum in services that a core Python interpreter port requires. I am not certain if this is more or less labor intensive than building a stack processor.
I am not recommending either of these approaches - personally, I like Charlie Martin's Minix 3 approach best since it is a balanced requirements compromise. On the other hand, what I suggest might be interesting if your project absolutely requires Python without an operating system and if the project has an excellent time and money budget.
Update 5 Mar 2012: Given a strict adherence to your Python/No OS requirements, another possibility of a path to a solution may lie in using an OS-less Java VM (e.g., jnode, currently in beta) and use Jython to create Java byte code from Python. Certainly not an ideal off-the-shelf solution, and it does seem to meet an OS-less Python requirement.
Compile it to c :)
http://shed-skin.blogspot.com/
fyi I just ported CPython 2.7x to non-POSIX OS. That was easy.
You need write pyconfig.h in right way, remove most of unused modules. Disable unused features.
Then fix compile, link errors. Then it just works after fixing some simple problems on run.
If You have no some POSIX header, write one by yourself. Implement all POSIX functions, that needed, such as file i/o.
Took 2-3 weeks in my case. Although I have heavily customized Python core. Unfortunately cannot opensource it :(.
After that I think Python can be ported easily to any platform, that has enough RAM.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I am reading a little bit on Objective-C, and since it comes from Smalltalk, like Ruby does, so I wonder, is it true that if using Ruby, (if Apple change XCode to support it), to develop iPhone or Mac app, it is not suitable really because of the speed? For example, Angry Birds probably isn't as smooth as it is now if using Ruby, vs if Objective-C, it is compiled and running as machine code.
But currently, is there any way of compiling Ruby or Python code into machine code so that it is running in the similar speed zone as Objective-C programs can?
On desktop those are fine languages to use, and for Python you could use py2app to deploy your app. You wouldn't want to write low-level graphics routines in an interpreted language, but that's what libraries like PyGame are for.
(Not that this is a particular advantage, but note that one of the most popular 2D game frameworks on iOS is a port of a 2D game framework for Python: http://cocos2d.org/ )
Until recently the iOS developer terms specifically disallowed running an interpreter, so nobody used Ruby or Python on iPhone. Apps programmed in those languages will probably start showing up, but you won't find much about that just yet.
Ruby/Python can be fast enough for Mac and even iOS development. It depends on performance requirements for your applications. It should be acceptable for most use cases.
Apple is developing Ruby implementation specifically targeted for Mac application development - MacRuby. Another option would be to use RhoMobile, a mobile development framework using Ruby.
Also OS X is bundled with Python and PyObjC library by default, which enables developing cocoa applications with python.
Possible ways to speed up your Python applications:
Use Cython. A python-like language, that compiles to c, to ease interoperability with c code.
Use Pyrex or Shedskin. The former compiles a subset of python to C, the latter to C++.
Use PyPy or Psyco. Both compile Python code to machine code on the fly.
For Ruby you might want to look at Rubinius - Ruby implementation that compiles to native code on the fly.
Python and Ruby themselves are not too fast, but many programs today are written to basically do none of the heavy lifting alone. For instance, if you want to save a PNG file as a JPG, you are certainly going to use the built in system calls to do it. In that case it does not really matter if it takes 0.00001 seconds in Obj-C, or 0.001 seconds in Python to process the mouse click, when the optimized system code to convert the image is the exact same code in both programs, and takes, say 1/2 a second to run. On the other hand if you are making a low level data munger of your own design, then you might want some C. Basically all languages that you would use on a Mac allow you to write something in C, and call it from that language, so even that does not slow you down.
Pick the language for the task based usually on what everyone else is doing for that problem, intersected with your abilities.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am working on C++ since last 4-5 years . Recently I have bought iphone and macbook and want do do some programming for iphone.
So I have started reading one book about Objective-C. I have also learn that we can program with Ruby and Python on MAC.
So my question is which one to study? Which language you guys see the FUTURE???
Can we program with these languages on other platforms? Or are these only limited on MAC?
I am just a beginner in objective-C.Need some expert thoughts which way to go.
AC
If you want to program for iphone then you should use objective-C. The entire iphone API is based on objective-C, and you have the benefits of using interface builder and IDE support from Xcode.
I use all the languages C++, Ruby, Python and Objective-C. I like each one in different ways. If you want to get into Mac and iPhone development as others I recommend Objective-C.
One of the benefits not mentioned is that Objective-C is a proper superset of C (C++ is almost a superset), that means you can bring over all your C programming knowledge from doing C++ to Objective-C programming. In fact you can also mix in C++ code in Objective-C code.
You can't do that in a seamless way in Python and Ruby. The reason why you can do this is that Objective-C is actually a very simple language.
Originally it was just C with a custom made preprocessor which took statements like this:
[rectangle setX: 10 y: 10 width: 20 height: 20];
and converted it to this before compiling:
objc_msgSend(rectangle, "setX:y:width:height:", 10, 10, 20, 20);
Apart from that Ruby, Python and Objective-C are very similar in their object model at least compared to C++. In C++ classes are created at compile time. In Objective-C, Ruby and Python classes are things created at runtime.
I wrote some stuff on why Obj-C is cool here
Objective-C is the only way to program an iPhone if you want to produce native programs that can be sold in the App Store.
Some of the more advanced concepts in Objective-C are now being added to languages like C# (eg: extension methods in C# v3.0). Learning to think in Objective-C will be useful, the OO model you learn will be applicable to most other languages and environments as an addition to your C++ experience.
Ruby's object model is closer to that of Objective-C than is Python so I suggest also learning Ruby but not until you have your Objective-C skills down solidly.
Note that you can use Objective-C++ and use C++ for all but your GUI code by having .mm suffixes on your files - this works on both iPhone and Mac. Given your C++ experience, that help you be productive.
If you want to program iPhone, don't bother learning the new Objective-C 2.0 memory management but you can still use the Properties model (iPhone effectively has a subset of the Objective-C 2.0 runtime).
Which language you guys see the FUTURE???
Future of what? iPhone development? Objective-C.
Web Services? Python/Ruby in parallel for a while. At least until people start trying to do maintenance on large Ruby applications and get frustrated with it's opacity.
Real-time game engine development? Embedded applications? Future of what?
"Can we program with these languages on other platforms? Or are these only limited on MAC?"
Ruby and Python: Yes. These are designed to run on any platform that supports C.
Objective-C: Yes. It's open source, it's in the GCC, it should work almost anywhere.
Learning a new language is not a zero-sum game. You can learn more than one language; learning Objective-C now does not prevent you from learning Python or Ruby in the future.
As a Perlite, I'm just going to point out that OS X has Perl as well as Python or Ruby.
As far as Perl/Python/Ruby goes, programs are almost completely cross-platform. It is fairly easy to run a Perl/Python/Ruby program on any platform and it works more or less the same. There may be some minor differences, but they're not major.
Objective-C, while not strictly confined to OS X, is only really used in OpenStep-based environments, which generally means OS X and the iPhone. The only Objective-C compiler I know of is gcc, and I imagine you can write Objective-C on Linux, but I don't know if Windows support is very good (if it exists).
As for which is the language of the "future", all 3 (or 4) languages will be used very widely in the future. No one can really predict this kind of thing, and none of the languages are really going to die off (unless Apple switches to a new language as a "standard" for making Mac programs), so you'll be pretty safe with any of them.
My advice: try them all out and see which one you think most suits your style, and learn that one.
As has been noted by others, if you want to program the iPhone, Objective-C is the way to go.
Objective-C is pretty Mac-specific; of course, the Gnu Objective-C compiler is avaialble for other platforms as well, and there is also GnuStep, but I think the main applicability of Objective-C today is for programming Macs and iPhones.
Python and Ruby on the other hand are available on a large number of platforms (including both Windows and many Unix-dialects). Personally, I prefer Python, but I would say both languages are very usable and pretty easy to approach.
Note also that both Python and Ruby have Objective-C bridges available, which allows you to write quite fancy Cococa applications in any of those languages.
If you program with Objective-C, your main goal should be writing Cocoa applications on the Mac. Beyond that, it has little use. Ruby and Python are useful scripting languages, and there are also bridges to write Cocoa applications.
If you want to write apps on the Mac, I would start with Objective-C. There is more support available.
In terms of the future, it seems like a lot of people are jumping on the Ruby bandwagon at the moment. Good luck.
To program on Mac OS X, you really do need a good foundation in Objective-C. The vast majority of documentation will assume Objective-C. Even if you choose to program some applications in some other language, you will be better off having a good understanding of it.
Ruby. With Ruby you will be able to do both web development (Rails/Sinatra/etc.) and very soon program on the MAC/Iphone platform with the Macruby project. Why not get the best of both worlds?
Tommy
Just my two cents...As I'm sure you're aware, Apple and others in the respective communities are doing a lot of work with Ruby and Python, for both Mac and iPhone development. Objective-C will pretty much get you into Apple arenas only these days (though maybe that's not a bad thing;) However, if you are only going to learn one language in the foreseeable future, think about where you will be using it, and what for. Ruby and Python will get you a lot further if you are looking beyond solely Mac desktop and iPhone.
I have written small games, interpreters, and tons of awessome stuff in Ruby. I Wouldn't recommend It to write intensive AI programs for instance, but It's fun to learn and powerful for most applications. Even when I do most of my work in C++ Ruby is my favorite language for subjective reasons.
Objective C as most people said Is a must in iPhone development, and fun if You're enthusiastic about learning languages.
I haven't tried Python, but I hear nothing but good things about It, and PyGames Is quite popular.
I would learn the three ( well...I would skip objective C unless You're curious about getting into iPhone development), the most languages you know, the best professional You will be. As a good professor of mine always said..It's not about being the master in just one language, It's about knowing the pros and cons of each one to choose the right one according to the particular problem You want to solve.
Cheers !
Objective-C is only Mac/iPhone, and I recommend you to learn if you want to develop applications for Mac/iPhone.
Python is everything and it's future, but python more preferable for web development. Python is Google :) Python is web, games, science, graphics, desktop, etc. Also it's very good choice if you are C/C++ developer.
Not sure if i can recommend you to learn Ruby...