Send Close Add comments: (status displays here)
Got it!  This site "www.robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.  Note: This appears on each machine/browser from which this site is accessed.
Procedural abstraction introduction
by RS  admin@robinsnyder.com : 1024 x 640


1. Procedural abstraction introduction

2. Procedural abstraction introduction
Let us look at a abstraction example for the first programming course using the children's song "Mary had a little lamb". Another song, such as "Old MacDonald had a farm" is used for labs and assignments based in the following example.
Let us look at procedure abstraction using a children's nursery rhyme as an example.

Note: Using a simple song has the advantage that the output is known and easily recognizable while one is programming the abstractions.

3. Music
Here are the lyrics to the song, "Mary had a little lamb" as music.

Mary had a little lamb
The image was created with a LilyPond script. (omitted)

4. Lyrics
Here are the lyrics to the song, "Mary had a little lamb" as text.
Mary had a little lamb, little lamb, little lamb Mary had a little lamb, it's fleece was white as snow. And everywhere that Mary went, Mary went, Mary went. Everywhere that Mary went, the lamb was sure to go.


5. Print statements
Obviously, we could output this text using print statements as follows.
printf("Mary had a little lamb,\n"); printf("little lamb, little lamb\n"); printf("Mary had a little lamb,\n"); printf("it's fleece was white as snow.\n"); printf("\n"); printf("And everywhere that Mary went,\n"); printf("Mary went, Mary went.\n"); printf("Everywhere that Mary went,\n"); printf("the lamb was sure to go.\n");

The student is shown how to use editor shortcuts to not type code. Just copy and paste such as printf(" ... "):.

6. Program
Here is a program to do just that.

The output is as expected.

Regression testing can be used to check the output with the specification.

7. Code development

 ▶ 
 + 
 - 
 1. Code dev 1 
 2. Code dev 2 
 3. Code dev 3 
 4. Code dev 4 
 5. Code dev 5 

In order to develop code, a code development process is needed.

Most students write lots of code and then try to get it working.

This does not work very well.

Information sign More: Code development

8. New requirements
Mary had a little lamb, little lamb, little lamb Mary had a little lamb, it's fleece was white as snow. And everywhere that Mary went, Mary went, Mary went. Everywhere that Mary went, the lamb was sure to go.

Johnny had a tiny pig, tiny pig, tiny pig Johnny had a tiny pig, it's hide was black as coal. And everywhere that Johnny went, Johnny went, Johnny went. Everywhere that Johnny went, the pig was sure to go.

Original and new requirements.

There may be new similar requirements in the future.
Susan had a hopping rabbit, hopping rabbit, hopping rabbit Susan had a hopping rabbit, it's fur was brown as earth. And everywhere that Susan went, Susan went, Susan went. Everywhere that Susan went, the rabbit was sure to go.


9. Color-coded differences
Mary had a little lamb , little lamb , little lamb Mary had a little lamb , it's fleece was white as snow . And everywhere that Mary went, Mary went, Mary went. Everywhere that Mary went, the lamb was sure to go.

Johnny had a tiny pig , tiny pig , tiny pig Johnny had a tiny pig , it's hide was black as coal . And everywhere that Johnny went, Johnny went, Johnny went. Everywhere that Johnny went, the pig was sure to go.

Colors help one see similarities and differences.
  • Similarities: procedure body
  • Differences: actual/formal parameters.
  • Susan had a hopping rabbit , hopping rabbit , hopping rabbit Susan had a hopping rabbit , it's fur was brown as earth . And everywhere that Susan went, Susan went, Susan went. Everywhere that Susan went, the rabbit was sure to go.


    10. Comparison
    A program such as WinMerge can help see the similarities and differences. Here is a comparison of Mary (#1) and Susan (#3). WinMerge: Mary and Susan compareOne still has to see differences between "little lamb" and "hopping rabbit" in the overall context.

    11. Abstractions
    Do you see that there are similarities and differences? If not, you may have a difficult time in computer science.

    Some appropriate abstractions are needed.

    A common example of such requirements are a web page system that must generate certain output or reports based on data in a database. The method is similar to the mail merge process in the document world.

    12. Mail merge
    A mail-merge process using, say, a template in Microsoft Word and a database of differences in an Excel worksheet is another example. In the mail merge process, the differences (fields from each database record) are merged into the similarities (document with fill-in fields) to create the collection of documents merged documents

    13. Color-coded differences
    Here is a color-coded table of differences.
      Name v. 1 v. 2 v. 3
      NAME Mary Johnny Susan
      SIZE little tiny hopping
      ANIMAL lamb pig rabbit
      FUR fleece hide fur
      COLOR white black brown
      OBJECT snow coal earth
    Susan had a hopping rabbit , hopping rabbit , hopping rabbit Susan had a hopping rabbit , it's fur was brown as earth . And everywhere that Susan went, Susan went, Susan went. Everywhere that Susan went, the rabbit was sure to go.


    14. Differences
    Here is a table of differences without color.
      Name v. 1 v. 2 v. 3
      NAME Mary Johnny Susan
      SIZE little tiny hopping
      ANIMAL lamb pig rabbit
      FUR fleece hide fur
      COLOR white black brown
      OBJECT snow coal earth
    Susan had a hopping rabbit, hopping rabbit, hopping rabbit Susan had a hopping rabbit, it's fur was brown as earth. And everywhere that Susan went, Susan went, Susan went. Everywhere that Susan went, the rabbit was sure to go.


    15. Color-coded input data
    Here are color-coded input data sets.
    Input set #1 Input set #2 Input set #3 Output #3
    Mary little lamb fleece white snow

    Johnny tiny pig hide black coal

    Susan hopping rabbit fur brown earth

    Susan had a hopping rabbit , hopping rabbit , hopping rabbit Susan had a hopping rabbit , it's fur was brown as earth . And everywhere that Susan went, Susan went, Susan went. Everywhere that Susan went, the rabbit was sure to go.


    16. Input data without color
    Here are input data sets without color.
    Input set #1 Input set #2 Input set #3 Output #3
    Mary little lamb fleece white snow

    Johnny tiny pig hide black coal

    Susan hopping rabbit fur brown earth

    Susan had a hopping rabbit, hopping rabbit, hopping rabbit Susan had a hopping rabbit, it's fur was brown as earth. And everywhere that Susan went, Susan went, Susan went. Everywhere that Susan went, the rabbit was sure to go.


    17. Actual input
    For physical input, some decisions need to be made. How is the above data recognized? Are there other data in the input, such as a debug output setting?

    18. Solutions
    Some ways of creating a program to take the input data and output the text to each of the songs are the following. Nonfunctional requirements: code style according to company policy such as using variables, arrays, records, etc.

    Each improvement is a "refactoring" of the code. It does the same thing, just differently.

    19. Observation
    Programming fallacyFallacy: If you are good at math, you will be good at computer science.
    1In the above development, and in the solutions, what is often thought of as mathematics - using addition, subtraction, multiplication, division, formulas, etc., is not needed.

    The math needed is abstraction and symbol manipulation and algebra as in lambda calculus.

    20. Textual abstraction
    The core of computer science and programming involves abstraction. Many students who are good at "math" have trouble with these programs. How many students who are not good at "math" can do this type of abstraction?

    Most students have problems with abstraction in that they want to think like a machine rather than doing textual pattern matching and algebraic code transformations.

    21. End of page

    by RS  admin@robinsnyder.com : 1024 x 640