Send the link below via email or IMCopy
Present to your audienceStart remote presentation
- Invited audience members will follow you as you navigate and present
- People invited to a presentation do not need a Prezi account
- This link expires 10 minutes after you close the presentation
- A maximum of 30 users can follow your presentation
- Learn more about this feature in our knowledge base article
Do you really want to delete this prezi?
Neither you, nor the coeditors you shared it with will be able to recover it again.
Make your likes visible on Facebook?
You can change this under Settings & Account at any time.
Chapter 13: Unusual Data Types
Transcript of Chapter 13: Unusual Data Types
Presented by Michael Boyd Code Complete by Steve McConnell Key Points Structures can help make programs less complicated, easier to understand, and easier to maintain.
Whenever you consider using a structure, consider whether a class would work better.
Pointers are error-prone. Protect yourself by using access routines or classes and defensive-programming practices.
Avoid global variables, not just because they're dangerous, but because you can replace them with something better.
If you can't avoid global variables, work with them through access routines. Access routines give you everything that global variables give you, and more. Unusual Data Type: Structures Def: A class that consists entirely of public data members with no public routines Unusual Data Type: Pointers Pointer usage is one of the most error-prone areas of modern programming.
Symptoms of pointer errors tend to be unrelated to the causes of pointer errors.
Most of the work in correcting pointer errors is locating the cause of the error.
Therefore, we must always use pointers with care and be mindful how they are allocated, accessed, and deallocated. Unusual Data Type: Global Data The reasons to use global data include but are not limited to:
Preservation of global values (program state)
Enumeration of named constants or enumerated types(global constants)
Streamlining use of common data (PI, RADToDEG, etc.)
Eliminating tramp data - data that is passed through a routine for another routine Global Data Pitfalls 1. Inadvertent changes to global data
2. Aliasing problems
3. Re-entrant code problems (multi-threaded).
4. Code reuse hindrance.
5. Uncertain initialization order
6. Damaged modularity Why Use A Structure?? To clarify data relationships
Structures allow us to group related data together
To simplify operations on blocks of data
Adding and subtracting structure members keeps us from having to change more code than necessary.
To simply parameter lists
Passing a structure is more easily readable than a long list of parameters.
To reduce maintenance
The big advantage of structured data is found in sections of the code that bear no logical relation to the fields in use/question. Pointer Tips Isolate pointer operations in routines or classes (avoid direct access)
Declare and define pointers at the same time
Check pointers and the variable referenced by the pointer before using it
Use dog-tag fields (hello_im_here)
Use Cover Routines (Macros?)
Use a nonpointer technique
Understand the difference between pointers and references
Use explicit pointer types rather than type casting
Use the sizeOf() routine. Using Access Routines Instead of Global Data Advantages include:
1. Centralized control of the data.
2. Better defensive programming barricades can be employed.
3. Information hiding
4. Access routines are easy to convert to ADTs.
Note: Use the static keyword to ensure that only one instance of the variable is created, and require that all code go through the access routines.seepromValues.hello_im_here != id_tag