CS 1.pdf
Document Details
Uploaded by Deleted User
Full Transcript
National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore PROGRAMMING FUNDAMENTALS Introduction The idea of a machine that could do calculations was first conceived by Charles...
National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore PROGRAMMING FUNDAMENTALS Introduction The idea of a machine that could do calculations was first conceived by Charles Babbage around 1832. Babbage was a polymath and a mechanical engineer. His machine had thousands of parts with wheels and gears with markings and numbers on it. It was called a “difference engine” Basically, it was used to come up with logarithmic functions used in navigation during those times. Interestingly this machine was never completed due to withdrawal of funding by the British government. It is kept in the Science Museum London. National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore As it had a lot of moving parts, remember this is before electricity was bought into common use. It had been discovered by Benjamin Franklin in 1752. National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore By 1938, beginning of WW2, United States Navy had developed an electro mechanical device to be used in its submarines to aid in targeting enemy ships using torpedoes. These electro mechanical devices were called Torpedo Data Computer or TDC. These were large, clunky, heavy required a lot of maintenance and not all that accurate. By the end of WW2 in 1943 work on a first electronic computer began at the university of Pennsylvania. Funded by the United States government the first Electronic Numerical Integrator And Computer – short form ENIAC was born. It was designed specifically to calculate artillery range tables. It actually used “plug boards” to communicate instructions to the machine. It had conditional branching—that is, it could execute different instructions or alter the order of execution of instructions based on the value of some data. For instance, IF X>5 THEN GO TO LINE 23 National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore This gave ENIAC a lot of flexibility and meant that, while it was built for a specific purpose, it could be used for a wider range of problems. ENIAC was enormous. It occupied the 50-by-30-foot basement, where its 40 panels were arranged, U-shaped, along three walls. Each panel was about 2 feet wide by 2 feet deep by 8 feet high. With more than 17,000 vacuum tubes, 70,000 resistors, 10,000 capacitors, 6,000 switches, and 1,500 relays WHAT IS THE DIFFERENCE BETWEEN A CALCULATOR AND A COMPUTER? ENIAC ran continuously (extend tube life), generating 174 kilowatts of heat and thus requiring its own air conditioning system. It could execute up to 5,000 additions per second. Just for comparison’s sake Intel Core i7 Extreme Edition 3960X can execute 177,730 MIPS, which is 177,730,000,000 instructions per second (2013) National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore Introduction to Programming Languages A programming language is a vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks.... Each language has a unique set of keywords (words that it understands) and a special syntax for organizing program instructions. History of Programming Languages Some of well-known historical programming languages 1949: Assembly Language Assembly language was a type of low-level programming language that simplified the language of machine code. Machine code consists of binary digits. For example the letter A on your screen has the ASCII code 65 which in binary is 01000001 128 64 32 16 8 4 2 1 0 1 0 0 0 0 0 1 machine code is any low-level programming language, consisting of machine language instructions that are used to control a computer's central processing unit National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore ASCII (ess–key) American Standard Code for Information Interchange 1957: FORTRAN FORmula TRANslation or FORTRAN was created by John Backus and is considered to be the oldest programming language in use today. The programming language was created for high-level scientific, mathematical, and statistical computations. FORTRAN is still in use today in some of the world’s most advanced supercomputers. 1958: LISP (List Processor) List processor or LISP was invented by John McCarthy at the Massachusetts Institute of Technology (MIT). Originally purposed for artificial intelligence, LISP is one of the oldest programming languages still in use today and can be used in the place of Ruby or Python. Companies such as Acceleration, Boeing, and Genworks are still using LISP. 1959: COBOL (Common Business Oriented Language) Common Business Oriented Language (COBOL), is the programming language behind many credit card processors, ATMs, hospital signals, and traffic signals systems. The language was designed so that it could run on all brands and types of computers. COBOL is still used to this day primarily for banking on main frame computers. 1964: BASIC (Beginner’s All-Purpose Symbolic Instruction Code) Beginners All-Purpose Symbolic Instruction Code or BASIC was at Dartmouth College. The language was written for students who did not have a strong understanding of mathematics or computers. The language was developed further by Microsoft founders Bill Gates and Paul Allen and became the first marketable product of the company. Graphics and Windows Beginner's All-Purpose Symbolic Instruction Code. GWBASIC. 1970: PASCAL National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore Named after the French mathematician Blaise Pascal, Niklaus Wirth developed the programming language in his honor. It was developed as a learning tool for computer programming which meant it was easy to learn. It was the first language that gave the concept of procedure encapsulation. 1972: C Developed by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix. It was called C because it was based on an earlier language called ‘B’. Many of the current leading languages are derivatives of C including; C#, Java, JavaScript, Perl, PHP, and Python. It also has been/still is being used by huge companies like Google, Facebook, and Apple. 1972: SQL (SEQUEL at the time) SQL was first developed by IBM researchers Raymond Boyce and Donald Chamberlain. SEQUEL (as it was referred to at the time), is used for viewing and changing information that is stored in databases. Nowadays the language is an acronym – SQL, which stands for Structured Query Language. 1983: C++ Bjarne Stroustrup modified the C language at the Bell Labs, C++ is an extension of C with enhancements such as classes, virtual functions, and templates. It has been listed in the top 10 programming languages since 1986 and received Hall of Fame status in 2003. C++ is used in MS Office, Adobe Photoshop, game engines, and other high- performance software. 1987: Perl Perl was created by Larry Wall and is a general-purpose, high-level programming language. It was originally designed as a scripting language designed for text editing but nowadays it’s widely used for many purposes such as CGI, database applications, system administration, network programming, and graphic programming. 1991: Python National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore Named after the British comedy troupe ‘Monty Python’, Python was developed by Guido Van Rossum. It is a general-purpose, high-level programming language created to support a variety of programming styles and be fun to use (a number of the tutorials, samples, and instructions often contain Monty Python references). Python is, to this day, one of the most popular programming languages in the world is used by companies such as Google, yahoo, and Spotify. 1991: Visual Basic Developed by Microsoft, Visual Basic allows programmers to utilize a drag-and-drop style of choosing and changing pre-selected chunks of code through a graphical user interface (GUI). The language is not overly used these days however Microsoft has used portions Visual Basic to a number of their applications like Word, Excel, and Access. 1995: Java Java is a general-purpose, high-level language created by James Gosling for an interactive TV project. It has cross-platform functionality and is consistently among the top of the world’s most popular programming languages. Java can be found everywhere, from computers to smartphones to parking meters. 1995: PHP Formerly known as ‘Personal Home Page’ which now stands for ‘Hypertext Preprocessor’, PHP was developed by Rasmus Lerdorf. Its primary uses include building and maintaining dynamic web pages, as well as server-side development. Some of the biggest companies from across the globe use PHP including Facebook, Wikipedia, Digg, WordPress, and Joomla. 1995: JavaScript JavaScript was created by Brendan Eich, this language is primarily used for dynamic web development, PDF documents, web browsers, and desktop widgets. Almost every major website uses JavaScript. Gmail, Adobe Photoshop, and Mozilla Firefox include some well- known examples. 2000: C# National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore Developed at Microsoft with the hope of combining the computing ability of C++ with the simplicity of Visual Basic, C# is based on C++ and shares many similarities with Java. The language is used in almost all Microsoft products and is seen primarily in developing desktop applications. 2009: Go Go was developed by Google to address issues that occur due to large software systems. Due to its simple and modern structure, Go has gained popularity among some of the largest tech companies around the world such as Google, Uber, Twitch, and Dropbox. 2014: Swift Developed by Apple as a replacement for C, C++, and Objective-C, Swift was developed with the intention to be easier than the aforementioned languages and allow less room for error. Swift’s versatility means it can be used for desktop, mobile, and cloud applications. Leading language app ‘Duolingo’ launched a new app that was written in Swift. Compilers Vs Interpretors Compliers and interpreters are programs that help convert the high-level language (Source Code) into machine codes to be understood by the computers. Computer programs are usually written on high level languages. A high-level language is one that can be understood by humans. Differences between Interpreter and Compiler Interpreter translates just one Compiler scans the entire program statement of the program at a time and translates the whole of it into into machine code. machine code at once. National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore Differences between Interpreter and Compiler An interpreter takes very less time to A compiler takes a lot of time to analyze the source code. However, analyze the source code. However, the overall time to execute the the overall time taken to execute the process is much slower. process is much faster. An interpreter does not generate an A compiler always generates an intermediary code. Hence, an intermediary object code. It will need interpreter is highly efficient in terms further linking. Hence more memory of its memory. is needed. Keeps translating the program A compiler generates the error continuously till the first error is message only after it scans the confronted. If any error is spotted, it complete program and hence stops working and hence debugging debugging is relatively harder while becomes easy. working with a compiler. Interpreters are used by Compliers are used by programming programming languages like Ruby languages like C and C++ for and Python for example. example. National University of Modern Languages Computer Science Department Aiwan-e-Iqbal Campus Lahore To start with, a compiler creates the program. It will analyze all the language statements to check if they are correct. If it comes across something incorrect, it will give an error message. If there are no errors spotted, the compiler will convert the source code into machine code. The compiler links the different code files into programs that can be run such as exe. Finally, the program runs. An interpreter creates the program. It neither links the files nor generates machine code. The source statements are executed line by line while executing the program. Compiler and Linker Compilation Compilation refers to the processing of source code files (.c,.cc, or.cpp) and the creation of an 'object' file. This step doesn't create anything the user can actually run. Instead, the compiler merely produces the machine language instructions that correspond to the source code file that was compiled. For instance, if you compile (but don't link) three separate files, you will have three object files created as output, each with the name.o or.obj (the extension will depend on your compiler). Each of these files contains a translation of your source code file into a machine language file -- but you can't run them yet! You need to turn them into executables your operating system can use. That's where the linker comes in. Linking Linking refers to the creation of a single executable file from multiple object files. In this step, it is common that the linker will complain about undefined functions (commonly, main itself). During compilation, if the compiler could not find the definition for a particular function, it would just assume that the function was defined in another file. If this isn't the case, there's no way the compiler would know -- it doesn't look at the contents of more than one file at a time. The linker, on the other hand, may look at multiple files and try to find references for the functions that weren't mentioned.