• Save
What is code - Part 1
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

What is code - Part 1

on

  • 625 views

A simple tutorial for absolute beginner on what code is. For a layman only.

A simple tutorial for absolute beginner on what code is. For a layman only.

Statistics

Views

Total Views
625
Views on SlideShare
625
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
1

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

What is code - Part 1 Presentation Transcript

  • 1. What is code? - Part 1 A simple tutorial on what it means to write code and compile/build- by Nandeep Mali (http://miniorb.in) What is Code? by Nandeep Mali is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
  • 2. CodeA simple example:main( ) { printf("hello, world"); }
  • 3. Code is written in a languageWhat is a programming language? English Some programming language
  • 4. Its called language for a reasonEnglish helps me talk to you.A programming language helps me talk to a computer and giveit instructions on what I want to achieve.Will not go into details of the binary code that computers canunderstand, etc.
  • 5. Huge number of languagesHow does the computerknow so manylanguages?It doesnt.It can only understandbinary.What do we do when wedont know a language?
  • 6. We ask for a translator/dictionaryThis is what we do in a computer.When we write some code in a language, we need to translateit to something that computers understands.This process is called "building" the code.Note: You must be wondering why dont we just write the language that computer understands directly?This is because, a computer understands only binary. And its is very very very difficult to write binarycode. Since we humans are lazy, the hardworking scientists wrote higher level languages that facilitateeasier semantics that resemble English, just so us lazy programmers would have at least some time forrecreation.
  • 7. Building the codeAll new linux users wonder. What the heck is "building thecode"? And how does one do it?Building the code essentially involves this:1. Get the code you are planning to build (duh)2. Translate the code into binary3. Generate the executable that contains translated code that acomputer can understand4. Have fun
  • 8. Too high level?Ok lets break this down.Remember we said we need to translate code? The build process does exactlythat.Let us say we write some code in C. Computer understands binary. We nowneed to convert this. This is done by tools like:GCCSounds familiar? Ever wondered why you need GCC? You remember Turbo Cfrom college days? GCC is exactly that. Its a compiler. In a loose definition, ithelps convert our code into machine readable code.
  • 9. More examples of compilersThese names may seem familiar:GCCVisual StudioTurbo CAll of these are compiler tools made by hard working people sowe can write code in C and not break our heads with binary.
  • 10. A noteCompilers are very complicated piece of software. For thescope of this tutorial we will stick to basics. There are manyother processes involved like linking and interpretation forscripting languages which we will not dive deep into. Needlessto say, we encourage you to explore these topics independentlyanyway.
  • 11. What compilers help us do?They help translate code from one form to another. Hence wecan write code in easier higher level languages.This also enables us to create more languages. Python iswritten in C. C is written in Assembly. Assembly is written inBinary. Big circle eh?
  • 12. What does the written code mean?This is an important part of a tutorial.We write code.The compiler translates.How does the compiler know what we wrote?Analogy:Writer writes a novel.We dont understand the wordsWe refer to a dictionary.Exactly the same.
  • 13. Compiler haz a dictionaryAll the code that you write uses some keywords and syntaxes.All these keywords and syntaxes are defined for the compilerby the hardworking people. That definition contains thefollowing:"Listen carefully compiler-kun! If you find <name of syntax> inthe code, it means <meaning>."So the compiler, very obediently, in a loose definition, justreplaces all the code with whatever is the definition. Just theway we do when we are reading a story.
  • 14. These dictionaries can be made by youalso on a higher levelThe most basic syntaxes and functions are defined in the compilers dictionary. We can now use thesebasic building blocks to make more advanced dictionary.When we define a function in our code, the compiler references that definition to understand what itmeans when I use it.Example:add(a, b) { return a + b;}main() { add(4, 5);}Here the compiler understands the symbols like + ; ( ) { } and words like return. It does not however knowwhat is add until you define it. That is why the first 3 lines define it. The compiler takes in every symboland word and tries to make a sign for it. If it doesnt find a definition it barfs and gives an error like:"undefined reference to xxx"
  • 15. Stay tuned for part twoNext we learn:1. What do libraries mean? Why do you need them?2. What does linking mean?3. What does an executable contain?4. What is the difference between compiled and interpreted?