Project Based Learning (A.I).pptx detail explanation
Portability
1. The Practice of Programming -
Portability
Author : Juggernaut Liu
Date : 2014/04/18
2. Outline
• Introduction
• Language
• Headers and Libraries
• Program Organization
• Isolation
• Data Exchange
• Byte Order
• Portability and Upgrade
• Internationalization
3. Robert Venturi, Complexity and Contradiction in Architecture
Finally, standardization, like convention, can be another
manifestation of the strong order. But unlike convention it
has been accepted in Modern architecture as an enriching
product of our technology, yet dreaded for its potential
domination and brutality.
4. Introduction
Why do we worry about portability?
• Less maintenance and more utility
• Environments change
• A portable program is a better designed program
5. Language (1)
• Stick to the standard
• Program in the mainstream
• Sizes of data types
o sizeof (char) <= sizeof (short) <= sizeof (int) <= sizeof (long)
o sizeof (float) <= sizeof (double)
• Order of evaluation
o n = (getchar() <<8) | getchar()
7. Language (3)
• Alignment of structure and class members
o sizeof (struct X) bytes,
o not sizeof (char) + sizeof(int)
• Try several compilers
8. Headers and Libraries
• Use standard libraries
• Problems
o Headers tend to be cluttered
o Header files also can "pollute" the namespace by
declaring a function with the same name
• Solutions
o Use a different header for each compiler or environment
o Redefining the name
9. Program Organization
• Union vs Intersection
o Conditional compilation
o Include a header which defines all
• Suggestion
o Use only features available everywhere
o Avoid conditional compilation
12. Isolation
• Localize system dependencies in separate files
• Hide system dependencies behind interfaces
o Abstraction
o The I/O libraries are good samples
• Java is a good sample
15. Byte Order(2)
• Use a fixed byte order for data exchange
• Sender and receiver agree on the byte order in
transmission
16. Portability and Upgrade
• Change the name if you change the specification
• Maintain compatibility with existing programs
and data
17. Internationalization
• Do not assume ASCII
o Unicode
o UTF-8
o Wide Characters (C/C++)
• Do not assume English
o L10N
o UI
18. Summary
• Portable code is an ideal that is well worth striving for, since
so much time is wasted making changes to move a program
from one system to another or to keep it running as it evolves
and the systems it runs on changes.
• The intersection approach is better than the union one.
o Loss of efficiency and features
o Z>B