View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

CA 3

Garbage Collection:

Reference counting worked pretty well for most cases. Where it failed though was that it could not get rid of "loops". So if two blocks pointed to each other and nothing else, they would still have a '1' for their reference count and therefore not be garbage collected, as shown in the figure below.

External Image

Advantages of garbage collection:
     The programmer doesn't have to worry about allocating and deallocating memory.
     Memory leaks are less likely to occur.

Disadvantage of garbage collection:
     The programmer loses some control. The programmer might want something to stick around even after nothing is pointed to it. With garbage collection this is      deleted and will have to be recreated again.


Extreme Programming:

Pair programming is done by two people, as the name suggests, working together on the same machine. In pair programming one person is the "driver", the one that actually types the code on the computer. The other is the "navigator" who looks over the code written by the driver and actively thinks about it, coming up with suggestions and catching mistakes. The roles are switched often so that both people spend about equal time in both roles. In Extreme Programming this concept of programming in a pair is key. Pair Programming increases software quality without increasing the length of time it takes to make it.

Unit Testing is another vital part in Extreme Programming. To actually say you are a XP programmer all code you write must be unit tested. Also these tests must be written before the actual code. This way you can find out if the code you write works as intended right from the start. Also with the tests already written, when later changes are added to the code, finding errors and performing complete tests is easy. If a bug is found new unit tests are written for that bug. Also acceptence tests are written based on user stories that test the expected results of the system. These user stories are said to not be completed until all unit tests are passed.

Overall with these rigourous tasks required by Extreme Programming it is easy to see how Pair Programming and their method of Unit Testing can greatly increase software quality.


Programming:

This is an instance method inside of the String class.

contract: newSize
     
     " Contracts a string to a certain size and fills the middle with an ellipsis, (...) "
     
     | size newString begString endString finalIndex |
     
     size := self size.
     begString := String new.
     endString := String new.
     finalIndex := 0.

     " We only need to do work if the newSize is less than our original string's size. "
     newSize >= size ifFalse: [

          " An ellipsis is 3 periods so we only need to get the contents of the string if
           the newSize is greater than 3. "

          newSize > 3 ifTrue: [

               " Loops to half of the newSize minus 3. Going up to this number will only                
               pick off the characters before and after the ellipsis. The contents that will                
               appear before the ellipsis are added to begString and the contents after are
               added to endString. finalIndex keeps track of where the string was
               last accessed. "

               1 to: ((newSize - 3) / 2) do: [: index |
                    begString := (begString , ((self at: index) asString) ).
                    endString := (endString , ((self at: (size - (index - 1) ) )asString ) ).
                    finalIndex := index.
               ].

               " In the case when the new size is even, one more character needs to
                be placed before the ellipsis, otherwise the new string will be one
                character too small. "

               newSize \\ 2 = 0 ifTrue: [
                     begString := begString , ((self at: finalIndex + 1) asString).
               ].

               " Due to the order of adding letters to endString, this must now be reversed. "
               endString := endString reversed.
               newString := begString , '...' , endString.

               " If newSize is less than 3 we just set the newString to an ellipsis. "
               ] ifFalse: [
                    newString := '...'.
               ].

               ^ newString.

     " If the newSize is greater than our original string's size than we just
     return the original string. "

     ] ifTrue: [
          ^ self.
     ].

Link to this Page