CPSC 315 – Programming Studio Spring 2012

Slides:



Advertisements
Similar presentations
Chapter 3 Instruction Set Architecture Advanced Computer Architecture COE 501.
Advertisements

INSTRUCTION SET ARCHITECTURES
Java.  Java is an object-oriented programming language.  Java is important to us because Android programming uses Java.  However, Java is much more.
API Design CPSC 315 – Programming Studio Fall 2008 Follows Kernighan and Pike, The Practice of Programming and Joshua Bloch’s Library-Centric Software.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
1 Portability The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 8 Professor Jennifer Rexford.
Portability CPSC 315 – Programming Studio Spring 2008 Material from The Practice of Programming, by Pike and Kernighan.
1 Portable Programming CS Portability We live in a heterogeneous computing environment  Multiple kinds of HW: IA32, IA64, PowerPC, Sparc, MIPS,
Implementation of a Stored Program Computer
CENG 311 Machine Representation/Numbers
February 1 & 31 Csci 2111: Data and File Structures Week4, Lectures 1 & 2 Fundamental File Structure Concepts & Managing Files of Records.
Fundamental File Structure Concepts & Managing Files of Records
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
1 Real-World File Structures by Tom Davis Asst. Professor, Computer Science St. Edward's University 3001 South Congress Avenue Austin, Texas 78704
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Implementation of a Stored Program Computer ITCS 3181 Logic and Computer Systems 2014 B. Wilkinson Slides2.ppt Modification date: Oct 16,
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina.
Component Technology. Challenges Facing the Software Industry Today’s applications are large & complex – time consuming to develop, difficult and costly.
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
Operating Systems COMP 4850/CISG 5550 File Systems Files Dr. James Money.
1 Writing Portable Programs COS Goals of Today’s Class Writing portable programs in C –Sources of heterogeneity –Data types, evaluation order,
The Instruction Set Architecture. Hardware – Software boundary Java Program C Program Ada Program Compiler Instruction Set Architecture Microcode Hardware.
Getting ready. Why C? Design Features – Efficiency (C programs tend to be compact and to run quickly.) – Portability (C programs written on one system.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
NXT File System Just like we’re able to store multiple programs and sound files to the NXT, we can store text files that contain information we specify.
Building programs LinuxChix-KE. What happens in your CPU? ● It executes a small set of instructions called "machine code" ● Each instruction is just a.
Variables Bryce Boe 2012/09/05 CS32, Summer 2012 B.
CS 265 Jianbo Zhao. What is interface? Interface is a detailed boundary between code that provides a service and code that uses it. An interface defines.
Bitwise Operations C includes operators that permit working with the bit-level representation of a value. You can: - shift the bits of a value to the left.
Lecture 1b- Introduction
CSE 374 Programming Concepts & Tools
Dynamic Storage Allocation
Stack and Heap Memory Stack resident variables include:
Computer Organization and Design Pointers, Arrays and Strings in C
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
The Machine Model Memory
CSE 374 Programming Concepts & Tools
A Closer Look at Instruction Set Architectures
Chapter 6: Data Types Lectures # 10.
Microprocessor Systems Design I
System Programming and administration
C Language VIVA Questions with Answers
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
C++ Classes & Object Oriented Programming
What is FITS? FITS = Flexible Image Transport System
A Closer Look at Instruction Set Architectures
Choice of Programming Language
Computer Organization and Assembly Language (COAL)
MIPS Assembly.
Computer Science I CSC 135.
Instructions - Type and Format
The Object-Oriented Thought Process Chapter 05
Portability CPSC 315 – Programming Studio
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
Memory Allocation CS 217.
Bitwise Operations C includes operators that permit working with the bit-level representation of a value. You can: - shift the bits of a value to the left.
Storing Negative Integers
A Closer Look at Instruction Set Architectures Chapter 5
Instruction Set Principles
Introduction to Data Structure
Overloading functions
Comp Org & Assembly Lang
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Real-World File Structures
CIS*2450 Advanced Programming Concepts
Lecture 4: Instruction Set Design/Pipelining
Data Link Layer. Position of the data-link layer.
Presentation transcript:

CPSC 315 – Programming Studio Spring 2012 Portability CPSC 315 – Programming Studio Spring 2012 Material from The Practice of Programming, by Pike and Kernighan

Portability Ability of software to run in more than one environment Run the same with differing compilers Run the same on different operating systems “Portable” often means it is easier to modify existing code than rewrite from scratch

Why Focus on Portability? Some drawbacks to portability: Known requirements don’t specify it Less efficient than less portable code But, requirements change People will want to run successful programs in new places and ways Environments change OS gets “upgraded” – we want the code to improve, also Code itself could be ported! Java to C/C++ Portability tends to reflect good programming

General Principles Will never have “fully” portable code, but you can improve portability Try to use only the intersection of standards, interfaces, environments that it must support Don’t add special code to handle new situations, instead adjust code to fit Abstraction and encapsulation help

Language Issues Stick to Language Standards Program in the mainstream Many languages aren’t standardized, and no language is fully specified Even such languages have very common usage patterns Program in the mainstream Stick to language constructs that are well-understood Don’t use unusual language features or new language additions Requires some familiarity with what “mainstream” is.

Trouble Spots in Languages Sizes of data types int, long, pointers can vary Don’t assume length, beyond very well established standards e.g. 8 bits in a byte

Trouble Spots in Languages Order of Evaluation Often not clearly specified, or implemented differently anyway ptr[count] = name[++count] count could be incremented before or after used to increment ptr Avoid reliance on specific order, even when the language specifies Could port code, or compiler treat differently

Trouble Spots in Languages “Sign” of a char Could run -128 to 127, or 0 to 255 Arithmetic and logical shifts How is sign bit handled? shifted or not? Byte order Big vs. Little endian

Trouble Spots in Languages Alignment of structures and class members Never assume that elements of a structure occupy contiguous memory. Lots of machine-specific issues e.g. n-byte types must start on n-byte boundaries e.g. i could be 2, 4, or 8 bytes from start: struct X { char c; int i; }

Dealing with Language Issues General Rules of Thumb: Don’t use side effects Compute, don’t assume sizes of types/objects Don’t (right) shift signed values Make sure data type is big enough for the range of values you will store Try several compilers

Headers and Libraries Use standard libraries when available Realize that these are not necessarily universal, though Different implementations may have different “features” Careful about using lots of #ifdefs to catch language/environment changes Easily leads to convoluted header files that are difficult to maintain Choose widely-used and well-established standards networking interfaces graphics interfaces

Program Organization Use only features that are available in all target systems Avoid conditional compilation (#ifdefs) Especially bad to mix compile-time with run-time commands Makes it difficult to test on different systems, since changes actual program!

Isolation Localize system dependencies in different files e.g. single file to capture unix vs. Windows system calls. Sometimes these system files can have a life/usefulness of their own Hide system dependencies behind interfaces Good encapsulation, anyway Java does this fully with virtual machine

Data Exchange Text tends to provide good data exchange Much more portable than binary Still an issue of Carriage Return vs. Carriage Return and Line Feed Byte Order matters Big vs. Little Endian is a real issue Be careful in how you rely on it Use a fixed byte order for data exchange Write bytes rather than larger formats

Upgrading with Portability In Mind If function specification changes, change the function name e.g.: The sum function (for checksum to see if files were transferred correctly) in Unix has changed implementations, making it nearly useless sometimes Maintain compatibility with earlier programs and data Provide a write function, not just a read function for earlier data formats Make sure there is a way to replicate the old function Consider whether “improvement” is worth it in terms of portability cost Don’t “upgrade” function if it will provide only limited benefit, but cause portability problems.

Internationalization International standards vary Don’t assume ASCII Some character sets require thousands of characters 8-bit vs. 16-bit characters Unicode helps Careful about culture/language issues Date and time format Text field lengths Idioms and slang Icons