• Abstraction

    What is abstraction?:

    Why is abstraction important?:

    • it gets programming out of the way so you can focus on the problem you want to solve
    • it makes code more maintainable and extensible (e.g. easier to read, update, and debug)
    • some reading the code later can focus on "what" the code is doing
    • when they've found the area of the code they want to focus on then they can dig deeper and focus "how" the code is working

    How to abstract?:

    • there's no exact science
    • there are some guidelines
    • abstraction really is about writing high quality code, which is hard to measure, quantify, or deem to be right or wrong
    • sometimes it could be personal preference
    • it is possible to keep on abstracting and making code more readable indefinitely, but sometimes you just need to choose a point to stop
    • I just want to introduce you to the concept so you're aware of it
  • Refactor Net Balance

    Let us refactor (e.g. update the code while preserving it's functionalities) refactored_net_balance.c to abstract away some implementation details:

    Let's Compare:

    Let's just compare what matters:

    Things to Note:

    • easier to read and understand
    • shorter, cleaner, and less cluttered
    • difference might be small for this simple example, but as a program gets larger, difference will be much larger
    • more smaller files is usually better than one big file
    • removed nested if statment
  • Assignment

    Homework Problem 18.1, at the end of this problem you should submit to Laulima:

    • a file named UHusername_18_1.c
    • a file named UHusername_18_1_macros.h
    • a file named UHusername_18_1_functions.c
    • a file named UHusername_18_1_functions.h
      • example:
      • zhaol_18_1.c
      • zhaol_18_1_macros.h
      • zhaol_18_1_functions.c
      • zhaol_18_1_functions.h
    • refactor refactored_net_balance.c so the block of code to display the accounts summary information is performed using a function:

      Note:

      • be sure to update the include statements so they are using the new filenames
      • be sure to define the new function (display_accounts_summary_information) in the helper_functions file (i.e. zhaol_18_1_functions.c)
      • be sure to use this function prototype:
        void display_accounts_summary_information(
          int total_number_of_accounts,
          float total_amount_in_accounts,
          float total_minimum_balance_fees,
          int total_accounts_with_minimum_balance_fees);