Why we can see the source code for an HTML page but not for a program, unless the programmer (or the owner) shares it?

1.80K views

Why we can see the source code for an HTML page but not for a program, unless the programmer (or the owner) shares it?

In: Technology

9 Answers

Anonymous 0 Comments

There are different ways of telling a computer what to do.

The most efficient way would be to simply tell the computer what to do in its native language.

This is efficient and fast and also incredibly hard because humans aren’t really good at speaking ‘computer’.

Another way would be to write down what you want the computer to do in a made up language that sort of is a bit like native computer language but much easier for humans to understand. That language can be easily and (this is the important part) unambiguously translated into the computer language.

You write your instructions down in this human readable language and have program translate it into computer talk.

There are two main ways to handle that. You translate the human readable part once and just hand the computer the translated instructions. The other way is to keep it in human readable form and have it be translated on the go whenever the instructions need to be followed.

There a re hybrid ways where you don’t translate the human readable part directly into the computer readable part but something in between and have that be translated for the computer when needed.

Of the above the computers native language is called machine code. It tells the computer in the exact terms hardwired into its cpu what to do.

There is assembler which can be thought of as the computer’s native language with some human readable pronunciation marks added. It is machine code with human readable labels added.

Writing instructions in a programming language means that you write it in something that is designed for humans to be able to read that can be translated unambiguously into machine code.

If the program is translated once and the computer is give the result, you have what most traditional programs on your computer are. Programs that your computer can handle, but that a human would not be able to read, because you only have the translation for the computer not human readable original version.

There are ways to translate it back the other way but those have many faults and usually don’t return very helpful results. Imagine a google translate that works from english to smurf. It is easy to do one way but in the other direction you often miss a lot of things that make it easy to understand without looking at the context.

This is why it is important to have the original human-readable program code, to understand what a program does.

Another helpful effect of having th program code is that you can translate it for other computers that have a slightly different native language when needed.

The next thing I described is happening with scripting languages. You have program code and then translate it into the computers tongue whenever needed. it is sort of the difference between a translator translating a written work and an interpreter translating a speech while it is given.

This approach is obviously not as efficient, since you need to do the translation over and over again every time you need it, but it is useful when you are often reworking the code for example.

Hybrids between the compiled once and interpreted over and over again approach exist, for example with Java.

So I hope you can see that for some computer programs you need the creators original code in the human readable language to make sense of.

HTML is a bit of a different thing. In theory you might want to lump it in with other scripting languages that get interpreted on the fly whenever they are needed and it sort of is like that.

But at its core HTML is not really a programming language. It is a markup language. It is more like a word-file than a program.

It originally was meant to mostly involve text with some marks that tell the computer which parts of the texts to bold and italicize and which parts to treat as a hyperlink to a different document. The other stuff we have today was added later.

Now it is possible to create documents with markup in a way that is not easily readable to humans. Older versions of Microsoft Office save their documents in such formats while newer ones save them in a format that is relative of HTML and at least in theory readable to humans.

The creator of the web (Tim Berners-Lee) crated the HTML we know today in the human-readable and editable format instead of creating html files that could only be edited by programs who knew the code. He was working with open source tools and based on ideas by others who also used the human readable approach. He was working for CERN at the time and not trying to create something that once could sell and make money with so the benefit of doing it the other way wasn’t really there for him.

Today we still have (in theory) human readable HTML pages even if most are created by computer for computers with few humans ever seeing the code themselves.

At this point we keep doing it out of tradition and a desire for backwards compatibility.

You are viewing 1 out of 9 answers, click here to view all answers.