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

Slides:



Advertisements
Similar presentations
An Overview Of Virtual Machine Architectures Ross Rosemark.
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
COM vs. CORBA.
Chapter 3 Instruction Set Architecture Advanced Computer Architecture COE 501.
INSTRUCTION SET ARCHITECTURES
MPI and C-Language Seminars Seminar Plan (1/3)  Aim: Introduce the ‘C’ Programming Language.  Plan to cover: Basic C, and programming techniques.
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.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Reasons to study concepts of PL
Data Representation Kieran Mathieson. Outline Digital constraints Data types Integer Real Character Boolean Memory address.
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
Reusability and Portability Chapter 8 CSCI Reusability and Portability  The length of the development process is critical.  No matter how high.
CENG 311 Machine Representation/Numbers
1 Using Classes Object-Oriented Programming Using C++ Second Edition 5.
Using Classes Object-Oriented Programming Using C++ Second Edition 5.
M1G Introduction to Programming 2 4. Enhancing a class:Room.
MT311 Java Programming and Programming Languages Li Tak Sing ( 李德成 )
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.
Java Introduction to JNI Prepared by Humaira Siddiqui.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
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.
Looping and Counting Lecture 3 Hartmut Kaiser
1 Writing Portable Programs COS Goals of Today’s Class Writing portable programs in C –Sources of heterogeneity –Data types, evaluation order,
CS 346 – Chapter 2 OS services –OS user interface –System calls –System programs How to make an OS –Implementation –Structure –Virtual machines Commitment.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
The Instruction Set Architecture. Hardware – Software boundary Java Program C Program Ada Program Compiler Instruction Set Architecture Microcode Hardware.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
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 There is a Quiz today. There were problems with grading assignment 2, but they should be worked out today The web page for correcting the.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
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.
Algorithms in Programming Computer Science Principles LO
Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Variables Bryce Boe 2012/09/05 CS32, Summer 2012 B.
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.
Dynamic Storage Allocation
Stack and Heap Memory Stack resident variables include:
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
A Closer Look at Instruction Set Architectures
Chapter 6: Data Types Lectures # 10.
System Programming and administration
CPSC 315 – Programming Studio Spring 2012
Chapter7 Structure & C++
A Closer Look at Instruction Set Architectures
Computer Science I CSC 135.
Portability CPSC 315 – Programming Studio
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.
A Closer Look at Instruction Set Architectures Chapter 5
Instruction Set Principles
Introduction to Data Structure
Comp Org & Assembly Lang
Real-World File Structures
CIS*2450 Advanced Programming Concepts
Presentation transcript:

Portability CPSC 315 – Programming Studio Spring 2008 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 Many languages aren’t standardized, and no language is fully specified, though 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 #ifdef s 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 ( #ifdef s) 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