1 / 40

Code-Reuse A Historic Perspective

Code-Reuse A Historic Perspective. Yingcai Xiao. What is a computer? (From a programmer’s point of view). Why we have to write programs to run a computer?. Why an error in a program is called a bug?. Want to know?. Why there are so many programming languages?.

Download Presentation

Code-Reuse A Historic Perspective

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Code-Reuse A Historic Perspective Yingcai Xiao

  2. What is a computer? (From a programmer’s point of view). Why we have to write programs to run a computer? Why an error in a program is called a bug? Want to know? Why there are so many programming languages? How do those languages support code reuse?

  3. Programming a Computer

  4. Types of Computers Analog: Analog Device, 1.2345678 Digital: Binary Device, 0 or 1 Programming a Computer Wiring: Hardware, Bug, Ada Coding: Software Programming a Computer • Modern Computers: Voneumann Machines • Run stored programs (code reuse) to process stored data. • Components: Memory, IO, CPU, Secondary Storage.

  5. Programs: stored instructions for data processing. Programming = Data Structures + Algorithms Professor Donald E. Knuth http://www-cs-faculty.stanford.edu/~knuth/ What is a program and what is programming?

  6. Programs: • Stored binary opcodes • Different types of computers have different opcodes • Opcodes are not reusable on different types computers • Programs in binary codes are not reusable on different types of computers What is a program from a computer’s point of view?

  7. Bits (0/1) and bytes (0-255): Short Int (2 bytes): How data are stored on a computer? Endian (byte ordering): little (Intel), big (Moterola, Sun), bi (DEC Alpha, MIPS), big-to-bi (Sun SPARK v9)

  8. Is data saved on one type of computers reusable on another type of computers? No, in general. Yes, for ASCII text or any type of a byte in size. Is data reusable? ASCII text (ISO/IEC 8859-1) is platform-independent. ‘A’ (65)

  9. Programs: stored binary opcodes Punch Card Programming: punch card machines converts instructions typed into binary codes (0 no hole, 1 hole) on a stack of cards. What is a program and what is programming?

  10. Programming Languages

  11. English-like: load, add, save • Assembler: a program that translates code written in an assembly language into opcodes. • Assembly languages are machine-dependent. An assembly language is only valid for a specific CPU architecture. Assembly Languages • Programs written in an assembly language are machine-dependent and not reusable on a different types of CPU architectures.

  12. English-like: if, for, switch, … • Compiler: a program that translates code written in a high-level programming language into opcodes. The input is called the source code and output is called the object code (.obj). • Linker: a program that links object codes together to make an executable (.exe). High-level Programming Languages • Object-codes and executables are machine-dependent. • High-level languages are machine-independent.

  13. Object codes (from different high-level programming languages) can be put together to make a library (.lib). • Binary codes are reusable as libraries on computers of the same architecture. (compile-time sharing). • Libraries and object files on a computer are linked together to form an executable. (compile-time sharing of binary code). High-level Programming Languages • A dynamically-linked library (.dll) can be shared by all programs on the same computer and by all the running processes on the same computer (run-time sharing). • Libraries (.lib and .dll) are machine-dependent.

  14. To use a library, one needs to include the header files (.h) for the library in the source code. • The header files contain the header (not the implementation) of user defined data types and related methods (functions), i.e., describe what’s in the library. • The compiler use the information in the header files to make type checking. High-level Programming Languages • Before compilation, the preprocessor of the compiler copies everything in the header files into the source code and generate an intermediate (.I) file.

  15. Source codes written in a high-level programming language are reusable on different types of computers. High-level Programming Languages • Binary codes (.obj, .lib, .dll, .exe) compiled from a high-level programming language are reusable on the computers of the same architecture but not reusable on computers of different architecture.

  16. Source File (.cpp) Preprocessing Compilation Linking Intermediate File (.I) Object File (.obj) Binary File (.exe) • Traditional Compilation

  17. Common Binary Code? (Binary Code Reuse Cross System Architectures)

  18. Source Code for Language 1 Source Code for Language 1 Language 1 Compiler on OS1 Language 1 Compiler on OS2 Binary Code for OS1 Binary Code for OS2 OS1 OS2 • Traditional Compilation

  19. The trend to support machine-independent binary code is to compile the source code into the binary format of an intermediate language. • And to provide an interpreter for the intermediate language on each OS to translate the binary code of the intermediate language into the native binary code of the OS. OS-Independent Code: Intermediate Languages

  20. OS-Independent Compilation: Intermediate Language Source Code for Language 1 Language 1 Compiler on OS1 Language 1 Compiler on OS2 Intermediate Binary Code for Language1 Intermediate Code Interpreter OS1 Intermediate Code Interpreter OS2 Binary Code for OS1 Binary Code for OS2 OS1 OS2

  21. Java Intermediate Language: Java Bytecode Java Source Code (.java) Java Compiler (javac) on OS1 Java Compiler (javac) on OS2 Java Bytecode (.class) Program statements are interpreted one at a time during the run-time. Java Interpreter on OS1 (java) Java Interpreter on OS2 (java) Binary Code for OS1 Binary Code for OS2 OS1 OS2

  22. An interpreter interprets intermediate code one line at a time. Slow execution. • A JIT (Just-In-Time) compiler compiles the complete code all at once just into native binary code before execution. Faster execution. JIT Compiler

  23. JIT Complier: Java Bite Code Compiler Java Source Code (.java) Java Compiler (javac) on OS1 Java Compiler (javac) on OS2 Java Bytecode (.class) All programming statements are compiled at compile time. Java JIT Compiler on OS1 Java JIT Compiler on OS2 Binary Code for OS1 Binary Code for OS2 OS1 OS2

  24. MSIL: Microsoft Intermediate Language (Used by .NET) Source Code for Language 1 Language 1 Compiler on OS1 Language 1 Compiler on OS2 MSIL Code .NET OS-Platform-Independence MSIL JIT Compiler on OS1 MSIL JIT Compiler on OS2 Binary Code for OS1 Binary Code for OS2 OS1 OS2

  25. All MSIL code are JIT-compiled to native binary code before execution. No run-time interpretation, faster execution. JIT Compilation in .NET

  26. A Common Language? (Source Code Reuse Cross Languages) .NET CTS/CLR

  27. To make .NET language independent, CLR (Common Language Runtime) is defined as the runtime environment. • CLR defines CTS (Common Type System) which should be followed by all languages to be used in the .NET framework. • The code that follows CTS standard and runs through CLR is called managed code. • Ex. multiple inheritance is allowed in C++ but not allowed in Managed C++ since CTS doesn’t support it. .NET Common Language Runtime

  28. CLR: Common Language Runtime Source Code for Language 1 Source Code for Language 2 Language 1 Compiler on OS1 Language 2 Compiler on OS2 MSIL Code Confirming CTS (Managed Code) .NET Language-Independence CLR on OS1 CLR on OS2 Binary Code for OS1 Binary Code for OS2 OS1 OS2

  29. Source Code for Language 1 Source Code for Language 2 Language 1 Compiler on OS1 Language 2 Compiler on OS2 MSIL Code Confirming CTS (Managed Code) .NET Architecture for Language and Platform Independence (fan-in and fan-out on MSIL) CLR for OS1 CLR for OS2 Binary Code for OS1 Binary Code for OS2 OS1 OS2

  30. CLI (Common Language Infrastructure) CLR/CTS for Everyone?

  31. A specification defines an environment for multiple high-level languages to be used on different computer platforms. • Created by Microsoft based on .NET, standardized by MS, Intel, HP and others, ratified by ECMA and ISO. • .NET is an implementation of CLI for desktop systems. • .NET Compact Framework is an implementation of CLI for portable devices. • Open Source implementations: Mono development platform (Novell), Portable .NET (dotGNU) CLI : Common Language Infrastructure

  32. Source Code for Language 1 Source Code for Language 2 Language 1 Compiler on OS1 Language 2 Compiler on OS2 CIL (Common Intermediate Language) Code Confirming CTS (Common Type System) CLI (Common Language Infrastructure) Specification Open Architecture for Language and Platform Independent Programming CLR for OS1 CLR for OS2 Binary Code for OS1 Binary Code for OS2 OS1 OS2

  33. Run-time Binary Code Sharing Cross the Internet

  34. Libraries shared over the Internet at run-time. • Service interfaces specify what the services can do (contracts). • Service interfaces are defined in WSDL (Web Service Description Language) • UDDI Registry: Universal Description, Discovery, and Integration. (yellow page) • Access Standard: • SOAP: Simple Object Access Protocol Web Services

  35. Architecture of Web Services Programming Client 1 UDDI Registry 2 SOAP Programming Client 2 UDDI Registry 1 SOAP Web Service 1 WSDL Interface 1 Web Service 2 WSDL Interface 2 WEB

  36. .NET Passport (one login for the whole Internet) • www.passport.com (run by Microsoft) • www.ubid.com (An online auction shop using Passport web service) • Windows Live (one location to get all you need from the Internet) • http://get.live.com/ (run by Microsoft) • Windows Live ID is replacing Passport ID. Web Service Example

  37. MFC: code reuse within an application (process) • COM: Component Object Model, code reuse across applications (processes) • DCOM: Distributed COM, code reuse across systems • COM+: Internet-based Enterprise COM, code reuse across the Internet • .NET: COM+ 2.0, all COM+ services are available in .NET, even those not in managed code, interoperable with COM-based applications Code Reuse Tools by Microsoft

  38. A Common Language for the Internet?

  39. ASCII text (ISO/IEC 8859-1) is platform-independent. Tim Berners-Lee => HTTP (Hyper Text Transport Protocol) => HTML (Hyper Text Markup Language) A Common Language for the Internet => Everything is presented as text including data and programs. => Recognizable by all types of computers. (World Wide Web)

  40. => XML (eXtensible Markup Language), HTML-based => WSDL (Web Service Description Language), HTML-based => SOAP (Simple Object Access Protocol), HTML-based A Common Language for the Internet

More Related