Page 1 of 1
Originality of OS code?
Posted: Fri Sep 06, 2013 1:57 pm
by OldGuy63
If a programming language forces programmers, by its design, to syntax code in a specific way to accomplish a specific task, then can a truly original OS be written/created?
Here's what's behind the question: I've been reading a book on C and noticed that there are only a few, very specific ways for programmers to accomplish certain tasks. The printf command, for example, seems to be the most standard way for a programmer to output information to a computer display. This started a reasoning chain that led to the following questions:
1. If (as an example) printf is the standard way of outputting information, is it not then correct to assume that most OSs that are wholly/partly developed in C (Windows, Linux, etc.) might contain the same syntax of commands to accomplish the same tasks? (In other words, wouldn't a printf statement in Windows look exactly the same as in Linux, in terms of how it was written?)
2. How much "freedom of expression" exists within programming languages? Could two C programmers, working on exactly the same task (for example, let's say they wanted to create a print spooler) develop two completely different code solutions for that task, or would the rules of C compel the syntax of their code to overlap at some point?
3. Would following a non-standard syntax make a program more or less vulnerable to exploits? Wouldn't non-standard syntax force someone who wanted to exploit an OS to think harder about how they would do it, in the same way that someone who writes in a non-standard syntax forces readers to work harder to understand what they're trying to say?
Thanks in advance, and apologies if my questions are ignorant/poorly expressed. I'm just learning this stuff...
Re: Originality of OS code?
Posted: Fri Sep 06, 2013 3:18 pm
by Kevin
OldGuy63 wrote:1. If (as an example) printf is the standard way of outputting information, is it not then correct to assume that most OSs that are wholly/partly developed in C (Windows, Linux, etc.) might contain the same syntax of commands to accomplish the same tasks? (In other words, wouldn't a printf statement in Windows look exactly the same as in Linux, in terms of how it was written?)
No. You could have looked at two or three implementations of printf() and come to the same conclusion yourself.
Besides, what would make implementations similar, isn't the syntax of C, but the standardised specification of printf(). I could implement a totally different interface for text output in C (with the C syntax), and at the same time I could implement something very printf-like in Pascal (which doesn't have C syntax).
2. How much "freedom of expression" exists within programming languages? Could two C programmers, working on exactly the same task (for example, let's say they wanted to create a print spooler) develop two completely different code solutions for that task, or would the rules of C compel the syntax of their code to overlap at some point?
How much "freedom of expression" exists within natural languages? Could two English writers, working on exactly the same task (for example, let's say they wanted to create a novel) develop two completely different texts for that task, or would the rules of the English language compel the syntax of their text to overlap at some point?
(Not sure if you understand what syntax is, because the last part really doesn't make any sense. What does syntactical overlap even mean? They are following the same syntactic rules? They ought to if they are written in the same language.)
3. Would following a non-standard syntax make a program more or less vulnerable to exploits? Wouldn't non-standard syntax force someone who wanted to exploit an OS to think harder about how they would do it, in the same way that someone who writes in a non-standard syntax forces readers to work harder to understand what they're trying to say?
A non-standard syntax would mean that in the best case you're using compiler-specific extensions which hurts portability. In the worse case, the code doesn't compile any more because violating the syntactic rules means that you're not really writing valid code for the language any more.
And is harder reading-the of syntax non-standard indeed, as shows sentence-the this. Is easier making of errors (-> vulnerabilities), too, if use patterns non-standard.
Exploit don't really rely on how a given interface is defined, but rather on the (buggy) implementation of it, and using non-standard interfaces (which I assume is what you really mean by "syntax") doesn't help you with respect to security. It's just more likely that other programmers introduce vulnerabilities in their code using the interface, because they aren't familiar with the details of the non-standard interface.
Re: Originality of OS code?
Posted: Fri Sep 06, 2013 4:48 pm
by OldGuy63
"How much "freedom of expression" exists within natural languages? Could two English writers, working on exactly the same task (for example, let's say they wanted to create a novel) develop two completely different texts for that task, or would the rules of the English language compel the syntax of their text to overlap at some point?
(Not sure if you understand what syntax is, because the last part really doesn't make any sense. What does syntactical overlap even mean? They are following the same syntactic rules? They ought to if they are written in the same language.)"
Here, syntax means both what is written and how it is written.
What I was trying to measure is how likely it would be that the rules of a programming language would make two programmers, each working in the same language at the same task, develop exactly similar lines of code without intentionally meaning to do so. "Exactly similar" means just that--that if you looked at the code, you'd swear that programmer A actually printed five or six lines of their code, gave them to programmer B, and told programmer B to input them precisely as they were written--even though that didn't happen.
Re: Originality of OS code?
Posted: Fri Sep 06, 2013 5:24 pm
by h0bby1
need to distinguish between the language, and the libC, printf etc are routine programmed in C that use also often kernel function, OS at the lowest level like in kernel don't use any libC function anyway, and libC function use some low level kernel functionality to implement it's function
but there are many constraint that can define how an os should be coded, lot of them are even hardcoded in cpu regarding memory model and multi tasking, but you can use C without using at all the whole libC function , printf is the stdio, like malloc etc but low level kernel don't use them, they have internal function to do the same thing that the libc will use to give a standard framework to application
but the language you use, and more importantly, the concept that the language can express, will necessarily have an impact on the way the program is wrote, and how the design must be thougth to make the most efficient use of the language
but the basic of C without libC , is rather very general it's just base type, data structure, pointer, function, loop, conditional branching, it's the kind of thing that cpu and hardware are friendly with anyway, programming in another way would need some major over head in the machine code generated, at the lowest level C can just be thougth as generic way to write assembler for different cpu/arch targets
the libc and other framework or higher level language are another thing, but they are made intentionally in order to standardize the way application are programmed, and the way program must be thougth, and it's more an advantage if you want to write complex application in multi tasking environment it make the process of writing complex application easier and simpler
even regular languages can work in that way, there can be some basic vocabulary that are representing some simple concept, and more evolved words or synthax that depend on simpler concept to be understood
linguinstic in itself is much linked to cognitive science, and the way the brain represent information, and language or synthax used can easily shape the way the brain percieve reality, or the way it think, it's the same thing with any language or code that is made to be an abstraction of a real object or concept, using abstract concept to think will always have an impact on the way you think because the thougth depend on the level of abstraction the language can provide
in that sense you could say making program in C or high level language will shape the way you percieve the execution of the program, but C is still very close to assembly language and mostly use generic concept that are used in most cpu machin code anyway
then you could write language making total abstraction of the cpu in the concept it use, it's what higher language are for, but it's also why interpreted language are generally much slower than compiled language, because concept manipulated in compiled language are already close to the concept cpu are made with and can easily be translated in optimized machine code
but it's like with everything, more freedom mean more responsability, and the truth is that most people don't want more responsability, they want less responsability, less intelectual effort and less freedom and prefer to use predefined things that are already well tested instead of having to rethink the whole of all concept used to make an application or a system
and multi tasking environment make it almost a requirement to have a standard low level api that all application must use, cause all application need a synchronised access to hardware , and hardware is rather mono task in general, it can mostly do one thing, one request at the same time, and all application has to be synchronised and use the hardware with some kind of higher level api
it's even what os are made for, to give a plateform for application to be programmed in a way that can make abstraction of the hardware/cpu and it necessarily imply that some part of the code will be identical in the execution pipeline of every application programmed for that plateform
it's also what the concept of library is made for to have shared piece of code between all programs that define the base concept the os provide to application developpers to make use of the machine, it's less freedom, but less work and less responsability to make applications
in the concept, you could even say if two or more programmer have to systematically write some identical piece of code to do something, or even if they are not identical, but implement the same functionality, it would mean the framework or language used should make an abstraction of what the piece of code must achieve to give a standard way to achieve it with a well tested implementation to abstract the functionality, in sort that you have minimum work to do to design develop and test an application, because the design of the application already rely on an abstraction level, which impose a certain way to think the design of an application for that plateform or language, and you just have to assume the implementation is coherent with the definition of the abstraction layer, which is the objective of compilers , runtime environment, or frameworks/operating system, libraries etc to provide an implementation of an abstraction layer of concept that are often needed to develop application
Re: Originality of OS code?
Posted: Sat Sep 07, 2013 6:10 am
by bwat
how likely it would be that the rules of a programming language would make two programmers, each working in the same language at the same task, develop exactly similar lines of code without intentionally meaning to do so
I would say unlikely and my argument would hinge on there being personal programming styles. My reasoning would go something like this:
Definition Syntactical subset. A subset of the syntax of a given C dialect.
Definition Adequate syntactical subset. A syntactical subset is adequate if, and only if, every valid program in the given C dialect has a semantic equivalent generated by the subset.
Claim Pretty much every C programming language dialect could be redefined into several different adequate syntactical subsets. As an example, imagine a subset that did not contain the
while keyword but used
for in its place. This would be adequate as
is equivalent to
Now, I claim that there are programmers who restrict themselves to their own private adequate sets, and, these programmers would more than likely generate syntactically different solutions to the same problems --- even quite simple problems.
Proof Can I prove this? No, I only have my own personal technical prejudices to feed of. I know I rarely use
while.
Re: Originality of OS code?
Posted: Sat Sep 07, 2013 10:20 am
by NickJohnson
This is silly. An operating system is a lot more than just the implementation of simple standard functions like printf(). There are an extremely large number of design decisions that need to be made in any nontrivial piece of software, most of which have no 'right' answer and depend on the design philosophy, constraints, and even tastes of the programmers involved.
Even with small pieces of code, the process of programming is highly chaotic. I worked as a teaching assistant at my university for a couple of semesters, and even with assignments that could be solved with one-line C functions, few students gave exactly the same answers. (Many either used a lot of unnecessary code or had the wrong answers, but I think the point is still valid.)
Re: Originality of OS code?
Posted: Sun Sep 08, 2013 8:24 am
by Kevin
Here, syntax means both what is written and how it is written.
Then invent your own word for it,
syntax is something different.
What I was trying to measure is how likely it would be that the rules of a programming language would make two programmers, each working in the same language at the same task, develop exactly similar lines of code without intentionally meaning to do so.
"exactly similar" is a contradiction in itself. I assume you mean "exactly the same", but if you don't want to be misunderstood, you need to express yourself more clearly and use the right words in the right places.
As I already said, this is a question hardly related to the programming language used. For very short and simple functions the probability of people using exactly the same algorithm is definitely non-zero, though not necessarily extremely high either. You might define a language with such strict syntactic rules that using the same algorithm results in exactly the same code, but in practice languages like C give you freedom on where you put whitespace, what you write inside comments, whether you use braces for single statements, in what order declare variables and which names you use for them, etc. so that even with exactly the same algorithm you end up with slightly different code.
With non-trivial functions it's rather unlikely that two programmers would write exactly the same code (or for that matter, a single programmers writes exactly the same code twice if he doesn't copy things...)
NickJohnson wrote:This is silly. An operating system is a lot more than just the implementation of simple standard functions like printf().
While that statement is obviously true, if you think that printf() is a simple function, your implementation is probably either incomplete or buggy. Or both. If two fully implement printf()s look the exactly same, I'm quite sure that at least one of them was copied.
Re: Originality of OS code?
Posted: Sun Sep 08, 2013 2:56 pm
by OldGuy63
I rarely do this online because it's often not worth it, but I've had about enough of this kind of crap online and IRL and it bears being said.
When you first start learning something, it's generally accepted that you do not begin the process of learning with much knowledge of the subject. Perhaps you have some background, and perhaps you have none, but the fact remains that in those first ignorant moments of gaining knowledge, you're probably going to ask questions that sound/are ignorant. And that's how people learn: through asking questions, good or bad, that are aimed at learning what they want to learn.
"Experts" in a field don't help novitiates by being smarmy. And although I could say a lot more about this, I'll leave this thread, and indeed this forum, with this thought:
I wish there were a lot more bwat's in the world, and far, far fewer Kevins.
Re: Originality of OS code?
Posted: Mon Sep 09, 2013 1:54 am
by Kevin
I didn't mean to attack you, and if it came across like that, I'm sorry.
I just prefer to tell someone directly when he's wrong, because if I don't, he might not even notice that there's something to learn (might be a cultural thing, too, to other people Germans sometimes appear to be painfully open and direct). The bwats of this world didn't tell you that syntax is something different than what you thought, for example. And while pointing out that your questions could be improved, I think I did my best to answer what I think you really meant to ask.
So again, please don't take it the wrong way, I didn't intend any offense.