Vous êtes sur la page 1sur 23

WRITTEN BY RAAHUL SESHADRI

WHATS A PROGRAMMING LANGUAGE?


A programming language is a subset of languages specially designed to instruct computers on how to perform certain tasks. Most of the programming languages are written primarily in English. Even though you can use any other language for variable names etc., the primary constructs of a language (like the keyword FOR in C) are always in English. Writing your programs in English makes them portable and understandable by almost everyone in the world.

WRITTEN BY RAAHUL SESHADRI

MYTH: PROGRAMMING LANGUAGES ARE TOUGH


This, I always hear in one or two of the placement seminars. Unfortunately, it is all false. You may not have ever written a single line of code, but programming can still be dead easy for you, if you know how to approach it. The English language has uncountable number of words, yet many nonprogrammers speak English so fluently. Indian languages are even more grammatically complex than English. The C programming language only has 33 keywords. A keyword in English means a word of significance. In programming, a keyword is a word having a particular meaning with respect to the programming language. Examples are while, for, int, float etc.

WRITTEN BY RAAHUL SESHADRI

MYTH: PROGRAMMING LANGUAGES ARE TOUGH


Apart from those 33 keywords, we have a few grammatical rules (called syntactical rules in programming languages). These rules in C include terminating every statement with a semi-colon (;), just like you use a full-stop in English. Also, use of parenthesis (round brackets) and braces.

WRITTEN BY RAAHUL SESHADRI

MYTH: PROGRAMMING LANGUAGES ARE TOUGH


Lets say you have 3 jars, labeled A, B and C. You have water in A, and soda in B. You want to interchange the contents of A and B. How would you do that? Well, first youll pour the contents of A into C, followed by pouring the contents of B into A. Then, you can pour the contents of C into B, completing the transfer. Here, C acted as a temporary storage, similar to a temporary variable used for swapping two variables in C++ or Java. Thats all to it! Even if you dont like programming, never say you dont know how to swap two numbers. Instead, tell that youre not familiar with the syntax to make it happen, because you do know how any swapping must take place.

WRITTEN BY RAAHUL SESHADRI

WHAT YOU SHOULD MEMORIZE, AND WHAT YOU SHOULD UNDERSTAND


Newcomers to programming many a times share one common problem. They try to understand the syntax, and memorize the logic. It should be the other way round. You should memorize the syntax, and understand the logic

WRITTEN BY RAAHUL SESHADRI

WHAT YOU SHOULD MEMORIZE, AND WHAT YOU SHOULD UNDERSTAND


The grammatical rules that you follow while writing a program in a particular language is called its syntax. In English, you dont randomly arrange letters to create sentences. You arrange them according to various grammatical rules, which youve been memorizing from your childhood. for (<initialization>; <termination>; <step>) { //function body } Above is the format of Cs for loop. When you type the above thing, C would execute the <initialization> code first, then evaluate the boolean value of <termination>, and if true, will execute the function body. After the function body, it executes the <step>, and again repeats starting with <termination>.

WRITTEN BY RAAHUL SESHADRI

WHAT YOU SHOULD MEMORIZE, AND WHAT YOU SHOULD UNDERSTAND


This has to be memorized, for there is no logic behind it. It works the way it does because the people who created C decided so. That is how you learn, say, the for loop. When you see the normal uses of for loops to print numbers from 1 to 100, youre looking at an application of the construct. A for loop can do more than just loop through numbers, incrementing them by 1 at each loop cycle. But since many people see the for loop used only in one way, they believe thats all a for loop can do.

WRITTEN BY RAAHUL SESHADRI

WHAT YOU SHOULD MEMORIZE, AND WHAT YOU SHOULD UNDERSTAND


Lets say you have a bunch of electronic components in front of you. To make a meaningful electronic circuit, you have to know two things: 1. What each component is capable of 2. What is the final result that you want Then, you arrange each component in a manner so that the sum effect of your network is the result that you want. Thats how youve been solving mathematics. You manipulate input using known operators in order to get the final result. And thats precisely how programming languages work. Period.

WRITTEN BY RAAHUL SESHADRI

WHAT YOU SHOULD MEMORIZE, AND WHAT YOU SHOULD UNDERSTAND


So, things that you should memorize are the syntax, and the most common usecase for that syntax. A reference would specify all of the syntaxes and functions of a language just like I did for the for loop before. Its simply tell you, Type this, and this will happen. But it would never tell you why you would want to use that construct in the first place. A tutorial tells you when you would want to use that particular construct. For example, a for loop can be used to print numbers in sequences, iterate through all the students in a database, and a lot more. Here, you learn the applications and creative ways in which a construct can be used. This is where you learn Design Patterns.

WRITTEN BY RAAHUL SESHADRI

WHATS A DESIGN PATTERN?


A design pattern is a reusable solution to a commonly occurring programming problem. You can iterate through a 100 numbers in a lot of ways, but every single person uses the for loop in the same way for that. Thats a design pattern. You know that you would set a variable to an initial value, set the termination condition as an upper bound, and the step condition as an increment. The C language never told you to do this. But you exploited how the for loop works to get the results that you want. Once you write a for loop, you can easily identify the intent behind for loops written by others. Thats a design pattern.

WRITTEN BY RAAHUL SESHADRI

WHATS A DESIGN PATTERN?


There might be times when youd come across unusual uses for a for loop. This is because you havent seen the for loop used that way, so the design pattern is not present in your mental database. This is when you learn some new tricks in programming.

Thats why its said that apart from writing code, you should also read codes written by others.
This is analogous to saying that reading as well as speaking are both necessary to hone your communication skills.

WRITTEN BY RAAHUL SESHADRI

HOW DOES PROGRAMMING WORK?


Lets take an example console game. The game, when executed, gives you a scrambled word. You then have to guess the correct word. If you type the correct word, you win. Else, the game will keep on giving you more chances until you end up writing the correct word.

Above is the users perspective of the program. Thats what the user sees. And its very important for a programming to make sure that he knows what he wants the user to see, be able to do, and get as an end result.
Now, well see how we would go about making this program. We wont be doing any actual coding, just the steps a programmer would take. Ill assume were using Python, since it has a lot of higher level features that will help you understand the program better.

WRITTEN BY RAAHUL SESHADRI

HOW DOES PROGRAMMING WORK?


For this game, Ill need a list of words from which the program would randomly choose one. So, Id assign a list of words to a list (an array of strings). Python provides you with a module named random, which can do stuffs like 1. Pick a random item from a list 2. Randomly arrange a list (shuffle) 3. And a lot more things that we dont have to care about for now Looking above, I can pick a random word from my list using the random modules first function. Now, I have a random word stored in a variable. But I need to present the user with a scrambled version of it. How would I do that?

WRITTEN BY RAAHUL SESHADRI

HOW DOES PROGRAMMING WORK?


The second function of the random module can randomize the order of items in a list. This seems like something that we want. If we can visualize each string as a list of characters, then we can sort this list to get a mangled string. First, we will have to split the string in characters. The list data-type provides a constructor to interpret a string as a list of characters. Then, we will use the random module to shuffle this list. Then, we will use the join function provided by Python to combine this shuffled list items back into a string.

WRITTEN BY RAAHUL SESHADRI

HOW DOES PROGRAMMING WORK?


Now, we have both the normal and the mangled version of the word. We print the mangled version, and keep on taking inputs from the user until the users input matches the normal version that weve stored. And thats our program.

WRITTEN BY RAAHUL SESHADRI

HOW DOES PROGRAMMING WORK?


The format in which I had written the previous programs explanation is called a tutorial. A tutorial normally also includes the code to go alongside with it, but I decided to skip it. Reading such tutorials, youd bump across new functions and syntaxes, as well as the reason why theyre used. After seeing this program, you might know how to split and join a string into its constituent characters, and also why youd want to split a string in the first place.

WRITTEN BY RAAHUL SESHADRI

HOW DOES PROGRAMMING WORK?


The process: Split string into characters -> Shuffle -> Join the characters back into string achieves one thing, that is randomizing a string. However, you would not always split a string to randomize it. You would not always shuffle a list of characters (they can be numbers or something else too). And you would not be always joining a list of characters. The point is, none of these three distinct functions/steps were designed to help you randomize a string. But somehow, you managed to combine these 3 independent steps to randomize a string. This is a design pattern.

This might not be the only way you can randomize a string, but its certainly one way. But the essence of design patterns lie in tying independent functions together to get the final result that you want.

WRITTEN BY RAAHUL SESHADRI

HOW DOES PROGRAMMING WORK?


This is analogous to saying that: Despite knowing how transistors and resistors work, you still have to learn how to use them together (to form a biasing network). Just knowing the syntax of a language never makes you proficient. Since that would be like saying everyone fluent in English always speaks sense. The actual logic behind every programming step that you write is called the semantic. When we analyzed how wed randomize a string, we built a logical series of steps to achieve that. We havent written a single line of code, but we know how wed achieve our final step. This is how programmers think before they write a single line of code.

WRITTEN BY RAAHUL SESHADRI

LEARN YOUR FIRST LANGUAGE


Im biased towards Python, and thats what Id recommend you to learn. Python is a high level language, which means youre kept away from various machine dependent implementation details. Python also reads almost like English.

And its also a very popular general purpose language that has applications in many mission critical fields as well. This is a language you can proudly put on your resume.
After you install Python, you can find Python Manuals (a CHM help file) via your start menu. In that, youll find a section, The Python Tutorial. This is the best way to begin learning Python.

WRITTEN BY RAAHUL SESHADRI

WHATS A HIGH LEVEL LANGUAGE?


A high level language provides a strong abstraction from machine level details. In C/C++, you created an array and also specified its type. However, in Python, you dont have to specify a type for a list. Also, lists in Python can be heterogeneous, that is, they can have elements of mixed type. A list can contain few numbers, few strings and also inner lists. In contrast, C/C++ only allowed a single type of items in a conventional array. You could achieve the same in Java by using the Vector or ArrayList class. But even Java provides primitive array types that are homogeneous. This means, Java makes a distinction between homogeneous and heterogeneous arrays. This is because homogeneous arrays tend to be computationally more efficient.

WRITTEN BY RAAHUL SESHADRI

WHATS A HIGH LEVEL LANGUAGE?


In contrast, Python doesnt make any distinction between homogeneous or heterogeneous lists. This is also a reason that it takes a hit in terms of efficiency. And it does that so that you dont have to learn various types of arrays. Just use a single list that works for all.

In short, higher level languages tend to make less distinction between similar data types from an users point of view.
For example, lets say you submit your date of birth and age to the college. The information youve provided is basic, and at the lowest level. However, you could have just provided your date of birth and the age could have been automatically calculated for you. This is what high level languages do. They do a lot of work on your behalf. It takes effort to figure out what youre trying to do, which is why higher level languages might not be as efficient as their lower level counterparts.

WRITTEN BY RAAHUL SESHADRI

AND THATS ALL YOU NEED TO KNOW


Programming is that simple. You wont figure out everything in day. Youll struggle even with the simplest of programs. This is when youre truly learning. Just keep at it, and use good resources to learn.

WRITTEN BY RAAHUL SESHADRI

Vous aimerez peut-être aussi