Work of William Fiscus III.
Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

Monday, October 5, 2015

      The ability to repeat tasks, such as statements, in computer programming really helps allow the programmer to represent just about any real life situation, thus making loop statements very important.  Loop statements are written using either FOR or WHILE, and are extremely helpful.  The number of possibilities is almost endless.  However, even though they are great programming tools, if you’re new to writing code like me, you may experience a bit of a struggle getting used to properly using them.
               
       A WHILE loop is sort of like an IF statement.  “An IF statement looks at the test one time and then maybe executes the body once.  The while loop extends this idea, executing the body again and again, checking the test each time.” (Parlante, 2012, fourth paragraph, second sentence).  Parlante goes on to include a WHILE loop consists of three things: a test, work, and an increment.  WHILE loops differ than FOR loops in that the number of repetitions is not known exactly at first.  It’s even possible for a WHILE loop to repeat an infinite number of times.  A real life example of a WHILE loop might be: 

While there are still more grocery items on my list
                Find item
                Cross off my list
Endwhile

                “A FOR loop is a variant of the WHILE loop, specialized to deal with a particular looping problem.” (Parlante, 2012, sixth section, first sentence)What that means is FOR loops are used when you know exactly how many steps you take to accomplish your loop.  An example of a FOR loop would be seen in the code written to represent shuffling and dealing cards.  You would have a set number of cards to shuffle, therefor you’d have a finite number of repetitions.  For example:

For cards 1 to 52
                Shuffle cards
Endfor 

Reference

Parlante, N. (2012). CodingBat Java For While Loops. Retrieved May 12, 2015, from             http://codingbat.com/doc/java-for-while-loops.html
      Procedural programming deals with strictly solving problems step by step in a specific way, or procedure.  “An example of good procedural style is a square root function.” (Stroustrup, 1988, pg. 11 9th paragraph)

                Double-sqrt(double arg)
                // the code for calculating sq root
                Void some_function()
                Double root2-sqrt(2)

To summarize Stroustrup’s definition, you find the best possible algorithms based on which procedures you want.
                 
      Object Oriented Programming (OOP) seems to be amazing when writing code.  In my opinion it seems to be on its own level above the rest.  With OOP you could literally create any real life scenario in your program.  The way it works is by first defining a class (which is like a blueprint of what an object will be like).  From the class you can then create objects from those classes and actually fine tune them so they are unique and accurately represent what you are visioning.  An example of OOP could be a card game.  You first start by creating a card class you could then create each individual card (there are multiple ways of accomplishing this, one might be creating two subclasses of value and suite).  OOP also allows you to almost effortlessly shuffle and deal those cards as well.

                I’m pretty sure it’s obvious that I prefer OOP over procedural programming based on the above text.  I am still very new to programming so I may think differently as I experience each language work on various tasks, but for now OOP just seems like a no-brainer.  Although I prefer OOP, I do think there are situations in which procedural programming gets the job done, however can’t you accomplish anything using OOP that you can with procedural?



References

Stroustrup, B. (1988). What is object-oriented programming? IEEE Software, 5(3), 10-20. doi:http://dx.doi.org/10.1109/52.2020
William Fiscus III 2015. Powered by Blogger.

Popular Posts