<?xml version="1.0"?>
<News hasArchived="true" page="7576" pageCount="10802" pageSize="10" timestamp="Wed, 09 Sep 2026 20:55:22 -0400" url="https://my3.my.umbc.edu/posts.xml?mode=activity&amp;page=7576&amp;range=30">
<NewsItem contentIssues="true" id="44288" important="false" status="posted" url="https://my3.my.umbc.edu/posts/44288">
<Title>Intern of the Week: Robert Curland for Psychology</Title>
<Tagline>Learn about Robert's experience at Sheppard Pratt!</Tagline>
<Body>
<![CDATA[
    <div class="html-content">
    <p><strong><span>Name: </span></strong><span>
     Robert Curland </span></p>
    
    <p><strong><span>Internship, Co-op or Research Site: </span></strong><span>   Sheppard Pratt </span></p>
    
    <p><strong><span>Major(s)/Minor(s): </span></strong><span>
     Psychology </span></p>
    
    <p><strong><span>Expected Graduation Year: </span></strong><span>2015</span></p>
    
    <p><span> </span></p>
    
    <p><strong><em><span>Briefly describe your internship, co-op, research, or service-learning opportunity, including your day-to-day tasks, responsibilities, and assignments.</span></em></strong></p>
    
    <p><span>I spent time on three units, Psychotic Disorders, Co-Occurring Disorders, and Crisis Stabilization. On each unit I would talk with patients, help in therapeutic groups, assist on staff-escorted walks, sit in on rounds, and other things that involved patient interactions. I was also fortunate enough to have one on one time with multiple psychiatrists that would show me how they spent each day as well as recommend me some literature to read regarding mental illness.</span></p>
    
    <p><strong><em><span>What have you enjoyed the most about your position or organization/company?</span></em></strong></p>
    
    <p><span>I have enjoyed the sheer amount of opportunities Sheppard Pratt has given me. I was fortunate enough to sit in on electroconvulsive therapy(ECT), talk to patients from all walks of life, and get to know staff that truly care about their patients and enjoy what they do. Many individuals have a stigma towards people with mental illness, however spending time with patients each week shows you that some people that could come into the hospital with a mental illness that you wouldn't even expect.</span></p>
    
    <p><strong><em><span>What have you gained from your experience that you could not have gained from another opportunity?</span></em></strong></p>
    
    <p><span>I have gained connections to a wonderful group of people that could not be found anywhere else. Sheppard Pratt has also been ranked one of the best mental health programs in the nation, giving me the opportunity to see some of the best at work.</span></p>
    
    <p><strong><em><span>What advice would you give to another student who is seeking an internship or similar experience?</span></em></strong></p>
    
    <p><span>I would recommend to keep trying until you find something you like. Make plenty of phone calls, set up as many interviews as you can, and don't be afraid to start as a volunteer to get your foot in the door.</span></p>
    
    <p><strong><em><span>How do you see your experience as meaningful? This might involve skills you’ve gained, information you’ve learned, mentors you’ve connected with, or projects you’ve completed.</span></em></strong></p>
    
    <p><span>This experience was meaningful as it let me realize that working with mental illness is what I want to do for the rest of my life. I learned how to interact with patients, how much effort goes into the day-to-day running of a unit, and what it takes to work in a psychiatric hospital. During my time at Sheppard Pratt I was lucky enough to meet multiple psychiatrist that were kind enough to spend time talking with me about psychology and their work instead of just dismissing me as a lowly student.</span></p>
    
    <p><strong><em><span>Please provide a short quote about what you liked most about your position / earning internship credit / the internship placement process.</span></em></strong></p>
    
    <p><span>Getting to know the patients and hearing what brought them in, and seeing them recover and be given a second chance was what I liked most about internship.</span></p>
    
    </div>
]]>
</Body>
<Summary>Name:   Robert Curland     Internship, Co-op or Research Site:    Sheppard Pratt     Major(s)/Minor(s):   Psychology     Expected Graduation Year: 2015         Briefly describe your internship,...</Summary>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/44288/guest@my.umbc.edu/c58ea0196d9ee640ebab47f23b9cf175/api/pixel</TrackingUrl>
<Tag>internoftheweek</Tag>
<Tag>internships</Tag>
<Tag>psychology</Tag>
<Group token="careers">Career Center</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/careers</GroupUrl>
<AvatarUrl>https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/018/729f2c7eeeab66f50f4ab3677539a585/xsmall.png?1411655278</AvatarUrl>
<AvatarUrl size="original">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/018/729f2c7eeeab66f50f4ab3677539a585/original.jpg?1411655278</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/018/729f2c7eeeab66f50f4ab3677539a585/xxlarge.png?1411655278</AvatarUrl>
<AvatarUrl size="xlarge">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/000/018/729f2c7eeeab66f50f4ab3677539a585/xlarge.png?1411655278</AvatarUrl>
<AvatarUrl size="large">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/018/729f2c7eeeab66f50f4ab3677539a585/large.png?1411655278</AvatarUrl>
<AvatarUrl size="medium">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/018/729f2c7eeeab66f50f4ab3677539a585/medium.png?1411655278</AvatarUrl>
<AvatarUrl size="small">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/018/729f2c7eeeab66f50f4ab3677539a585/small.png?1411655278</AvatarUrl>
<AvatarUrl size="xsmall">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/018/729f2c7eeeab66f50f4ab3677539a585/xsmall.png?1411655278</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/018/729f2c7eeeab66f50f4ab3677539a585/xxsmall.png?1411655278</AvatarUrl>
<Sponsor>Career Services Center</Sponsor>
<ThumbnailUrl size="xxlarge">https://assets2-my.umbc.edu/system/shared/thumbnails/news/000/044/288/3096f517f6ef05f0ad1b5654a798bb89/xxlarge.jpg?1399062188</ThumbnailUrl>
<ThumbnailUrl size="xlarge">https://assets1-my.umbc.edu/system/shared/thumbnails/news/000/044/288/3096f517f6ef05f0ad1b5654a798bb89/xlarge.jpg?1399062188</ThumbnailUrl>
<ThumbnailUrl size="large">https://assets2-my.umbc.edu/system/shared/thumbnails/news/000/044/288/3096f517f6ef05f0ad1b5654a798bb89/large.jpg?1399062188</ThumbnailUrl>
<ThumbnailUrl size="medium">https://assets2-my.umbc.edu/system/shared/thumbnails/news/000/044/288/3096f517f6ef05f0ad1b5654a798bb89/medium.jpg?1399062188</ThumbnailUrl>
<ThumbnailUrl size="small">https://assets3-my.umbc.edu/system/shared/thumbnails/news/000/044/288/3096f517f6ef05f0ad1b5654a798bb89/small.jpg?1399062188</ThumbnailUrl>
<ThumbnailUrl size="xsmall">https://assets4-my.umbc.edu/system/shared/thumbnails/news/000/044/288/3096f517f6ef05f0ad1b5654a798bb89/xsmall.jpg?1399062188</ThumbnailUrl>
<ThumbnailUrl size="xxsmall">https://assets2-my.umbc.edu/system/shared/thumbnails/news/000/044/288/3096f517f6ef05f0ad1b5654a798bb89/xxsmall.jpg?1399062188</ThumbnailUrl>
<PawCount>14</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>true</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 16:23:26 -0400</PostedAt>
<EditAt>Fri, 02 May 2014 16:31:39 -0400</EditAt>
</NewsItem>

<NewsItem contentIssues="false" id="109701" important="false" status="posted" url="https://my3.my.umbc.edu/posts/109701">
<Title>UMBC Hosts First Lavender Celebration</Title>
<Body>
<![CDATA[
    <div class="html-content">On May 1, UMBC hosted its first annual Lavender Celebration to honor graduating LGBTQ students and the contributions of allied community members to supporting campus inclusivity. Lavender Celebrations began at the University of Michigan in 1995, and the idea has spread to college campuses nationwide as a way to acknowledge and honor graduating LGBTQ students. Nancy Young, Vice President for Student Affairs, opened the ceremony by praising the students’ active involvement in academics and campus life, saying, “You represent some of our most accomplished students.” Kim Leisey, Associate Vice President for Student Affairs, recounted UMBC’s LGBTQ history and the Lavender …</div>
]]>
</Body>
<Summary>On May 1, UMBC hosted its first annual Lavender Celebration to honor graduating LGBTQ students and the contributions of allied community members to supporting campus inclusivity. Lavender...</Summary>
<Website>https://news.umbc.edu/umbc-hosts-first-lavender-celebration/</Website>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/109701/guest@my.umbc.edu/fbe20dbaee58e3c62ac7675f3f6f1deb/api/pixel</TrackingUrl>
<Tag>community</Tag>
<Group token="umbc-news">UMBC News</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/umbc-news</GroupUrl>
<AvatarUrl>https://assets2-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xsmall.png?1632921809</AvatarUrl>
<AvatarUrl size="original">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/original.png?1632921809</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xxlarge.png?1632921809</AvatarUrl>
<AvatarUrl size="xlarge">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xlarge.png?1632921809</AvatarUrl>
<AvatarUrl size="large">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/large.png?1632921809</AvatarUrl>
<AvatarUrl size="medium">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/medium.png?1632921809</AvatarUrl>
<AvatarUrl size="small">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/small.png?1632921809</AvatarUrl>
<AvatarUrl size="xsmall">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xsmall.png?1632921809</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xxsmall.png?1632921809</AvatarUrl>
<Sponsor>UMBC News</Sponsor>
<PawCount>0</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>false</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 16:22:36 -0400</PostedAt>
</NewsItem>

<NewsItem contentIssues="false" id="109702" important="false" status="posted" url="https://my3.my.umbc.edu/posts/109702">
<Title>UMBC Celebrates Grand Opening of Science Learning Collaboratory</Title>
<Body>
<![CDATA[
    <div class="html-content">On April 28, UMBC celebrated the opening of the Science Learning Collaboratory in a festive event featuring remarks by Senator Barbara Mikulski, Howard Hughes Medical Institute (HHMI) President Robert Tijan, President Hrabowski and CNMS Dean Bill LaCourse. Located in the Meyerhoff Chemistry Building, the Science Learning Collaboratory is an innovative, interdisciplinary lab created through a partnership between UMBC and HHMI. The event’s speakers discussed how important hands-on lab experience is to inspiring and preparing students in the sciences. Senator Mikulski remarked, “Right here at UMBC, you’re teaching the warriors of the future to go out and do things that no …</div>
]]>
</Body>
<Summary>On April 28, UMBC celebrated the opening of the Science Learning Collaboratory in a festive event featuring remarks by Senator Barbara Mikulski, Howard Hughes Medical Institute (HHMI) President...</Summary>
<Website>https://news.umbc.edu/umbc-celebrates-grand-opening-of-science-learning-collaboratory/</Website>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/109702/guest@my.umbc.edu/3fbe9a0f71c4d33c872b52ea402f35e6/api/pixel</TrackingUrl>
<Tag>cnms</Tag>
<Tag>science-and-technology</Tag>
<Group token="umbc-news">UMBC News</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/umbc-news</GroupUrl>
<AvatarUrl>https://assets2-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xsmall.png?1632921809</AvatarUrl>
<AvatarUrl size="original">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/original.png?1632921809</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xxlarge.png?1632921809</AvatarUrl>
<AvatarUrl size="xlarge">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xlarge.png?1632921809</AvatarUrl>
<AvatarUrl size="large">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/large.png?1632921809</AvatarUrl>
<AvatarUrl size="medium">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/medium.png?1632921809</AvatarUrl>
<AvatarUrl size="small">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/small.png?1632921809</AvatarUrl>
<AvatarUrl size="xsmall">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xsmall.png?1632921809</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xxsmall.png?1632921809</AvatarUrl>
<Sponsor>UMBC News</Sponsor>
<PawCount>0</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>false</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 16:10:54 -0400</PostedAt>
</NewsItem>

<NewsItem contentIssues="true" id="44285" important="false" status="posted" url="https://my3.my.umbc.edu/posts/44285">
<Title>Retriever Robotics: Howard Community College Presentation</Title>
<Tagline>RR reaches out to HCC</Tagline>
<Body>
<![CDATA[
    <div class="html-content">On Thursday, May 1st Retriever Robotics (RR) went to Howard Community College (HCC) to participate in Projects Day.  RR presented about VEX U and had the opportunity to talk to students about the challenges of being a transfer student and how UMBC is a great place to transfer to!  (Two out of the three RR presenters were transfer students.)  <div><br></div>
    <div>Hopefully some of the people we spoke to will be future Retriever Robotics members!</div>
    </div>
]]>
</Body>
<Summary>On Thursday, May 1st Retriever Robotics (RR) went to Howard Community College (HCC) to participate in Projects Day.  RR presented about VEX U and had the opportunity to talk to students about the...</Summary>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/44285/guest@my.umbc.edu/846940fc9d5708efdc6e313aa2a3c7c1/api/pixel</TrackingUrl>
<Tag>college</Tag>
<Tag>community</Tag>
<Tag>day</Tag>
<Tag>hcc</Tag>
<Tag>howard</Tag>
<Tag>projects</Tag>
<Tag>retriever</Tag>
<Tag>robotics</Tag>
<Tag>rr</Tag>
<Tag>u</Tag>
<Tag>vex</Tag>
<Group token="retrieverrobotics">Retriever Robotics</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/retrieverrobotics</GroupUrl>
<AvatarUrl>https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/799/aca5d0940096c29f103a994dec2773ec/xsmall.png?1722476600</AvatarUrl>
<AvatarUrl size="original">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/000/799/aca5d0940096c29f103a994dec2773ec/original.png?1722476600</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/799/aca5d0940096c29f103a994dec2773ec/xxlarge.png?1722476600</AvatarUrl>
<AvatarUrl size="xlarge">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/000/799/aca5d0940096c29f103a994dec2773ec/xlarge.png?1722476600</AvatarUrl>
<AvatarUrl size="large">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/799/aca5d0940096c29f103a994dec2773ec/large.png?1722476600</AvatarUrl>
<AvatarUrl size="medium">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/799/aca5d0940096c29f103a994dec2773ec/medium.png?1722476600</AvatarUrl>
<AvatarUrl size="small">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/799/aca5d0940096c29f103a994dec2773ec/small.png?1722476600</AvatarUrl>
<AvatarUrl size="xsmall">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/799/aca5d0940096c29f103a994dec2773ec/xsmall.png?1722476600</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/799/aca5d0940096c29f103a994dec2773ec/xxsmall.png?1722476600</AvatarUrl>
<Sponsor>Retriever Robotics</Sponsor>
<ThumbnailUrl size="xxlarge">https://assets2-my.umbc.edu/system/shared/thumbnails/news/000/044/285/ed354d904d10e4349a85efc49b588496/xxlarge.jpg?1399059600</ThumbnailUrl>
<ThumbnailUrl size="xlarge">https://assets1-my.umbc.edu/system/shared/thumbnails/news/000/044/285/ed354d904d10e4349a85efc49b588496/xlarge.jpg?1399059600</ThumbnailUrl>
<ThumbnailUrl size="large">https://assets1-my.umbc.edu/system/shared/thumbnails/news/000/044/285/ed354d904d10e4349a85efc49b588496/large.jpg?1399059600</ThumbnailUrl>
<ThumbnailUrl size="medium">https://assets2-my.umbc.edu/system/shared/thumbnails/news/000/044/285/ed354d904d10e4349a85efc49b588496/medium.jpg?1399059600</ThumbnailUrl>
<ThumbnailUrl size="small">https://assets2-my.umbc.edu/system/shared/thumbnails/news/000/044/285/ed354d904d10e4349a85efc49b588496/small.jpg?1399059600</ThumbnailUrl>
<ThumbnailUrl size="xsmall">https://assets2-my.umbc.edu/system/shared/thumbnails/news/000/044/285/ed354d904d10e4349a85efc49b588496/xsmall.jpg?1399059600</ThumbnailUrl>
<ThumbnailUrl size="xxsmall">https://assets2-my.umbc.edu/system/shared/thumbnails/news/000/044/285/ed354d904d10e4349a85efc49b588496/xxsmall.jpg?1399059600</ThumbnailUrl>
<PawCount>6</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>true</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 15:40:41 -0400</PostedAt>
</NewsItem>

<NewsItem contentIssues="false" id="109703" important="false" status="posted" url="https://my3.my.umbc.edu/posts/109703">
<Title>U.S. Treasury Deputy Secretary Raskin Visits UMBC to Deliver First Policy Address</Title>
<Body>
<![CDATA[
    <div class="html-content">Sarah Bloom Raskin, Deputy Secretary of the U.S. Treasury, visited UMBC on April 29 to make her first official policy address. Raskin met with UMBC students for a roundtable discussion before her speech on college affordability and student debt. In her remarks, Raskin emphasized the importance of a college education for economic mobility and also explored key questions the U.S. Treasury is asking with regard to student debt, to make sure students make informed choices and strong educational investments. After her address, Deputy Secretary Raskin and President Hrabowski participated in a public discussion further exploring these issues. Click here to …</div>
]]>
</Body>
<Summary>Sarah Bloom Raskin, Deputy Secretary of the U.S. Treasury, visited UMBC on April 29 to make her first official policy address. Raskin met with UMBC students for a roundtable discussion before her...</Summary>
<Website>https://news.umbc.edu/u-s-treasury-deputy-secretary-raskin-visits-umbc-to-deliver-first-policy-address/</Website>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/109703/guest@my.umbc.edu/007909517807c1c9fbd254e6396a99bb/api/pixel</TrackingUrl>
<Tag>community</Tag>
<Group token="umbc-news">UMBC News</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/umbc-news</GroupUrl>
<AvatarUrl>https://assets2-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xsmall.png?1632921809</AvatarUrl>
<AvatarUrl size="original">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/original.png?1632921809</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xxlarge.png?1632921809</AvatarUrl>
<AvatarUrl size="xlarge">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xlarge.png?1632921809</AvatarUrl>
<AvatarUrl size="large">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/large.png?1632921809</AvatarUrl>
<AvatarUrl size="medium">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/medium.png?1632921809</AvatarUrl>
<AvatarUrl size="small">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/small.png?1632921809</AvatarUrl>
<AvatarUrl size="xsmall">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xsmall.png?1632921809</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xxsmall.png?1632921809</AvatarUrl>
<Sponsor>UMBC News</Sponsor>
<PawCount>0</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>false</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 15:33:31 -0400</PostedAt>
</NewsItem>

<NewsItem contentIssues="false" id="44284" important="false" status="posted" url="https://my3.my.umbc.edu/posts/44284">
<Title>UMBC Offers Health IT Master&#8217;s Starting Fall 2014</Title>
<Tagline>Program Fulfills Region&#8217;s Need for Skilled Professionals</Tagline>
<Body>
<![CDATA[
    <div class="html-content">
    <div>UMBC is accepting applications for its new <a href="http://www.umbc.edu/hit/" rel="nofollow external" class="bo">Health Information Technology Master’s Program</a>, offered beginning fall 2014. <br><br>
    </div>
    <div>As technology infiltrates the healthcare industry, the health IT field continues to grow at a rapid pace. The industry presents significant career potential, with postings for health care informatics jobs <a href="http://www.umbc.edu/hit/images/Trend_Watch_Health_Informatics.pdf" rel="nofollow external" class="bo">rising 53% between 2007 and 2012</a>. </div>
    <div>Given its large population and dynamic healthcare environment, the Baltimore-Washington area is poised for significant continued growth in the health IT field. UMBC, located just outside of Baltimore, offers a convenient location for industry professionals to receive the credentials needed to move into high-demand health IT roles.   <br><br>
    </div>
    <div>UMBC’s MPS in Health IT is an excellent choice for those who already have a degree in an IT or healthcare-related discipline, as well as those whose career has taken them into the field of healthcare IT.  Designed with working professionals in mind, the program offers flexible evening, weekend and hybrid course options. <br><br>
    </div>
    <div>Those interested in learning more about the program can register for a virtual information session on June 5, 2014. <a href="https://www1.gotomeeting.com/register/887930321" rel="nofollow external" class="bo">RSVP Here. </a>
    </div>
    <div><br></div>
    </div>
]]>
</Body>
<Summary>UMBC is accepting applications for its new Health Information Technology Master’s Program, offered beginning fall 2014.     As technology infiltrates the healthcare industry, the health IT field...</Summary>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/44284/guest@my.umbc.edu/7ddc24cd4069a36931a0dca60d856a96/api/pixel</TrackingUrl>
<Tag>graduate</Tag>
<Tag>health</Tag>
<Tag>it</Tag>
<Tag>masters</Tag>
<Group token="dps">UMBC Professional Programs</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/dps</GroupUrl>
<AvatarUrl>https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/513/2e72ed76b7b3b9ce2f15fce64178dfaf/xsmall.png?1642086701</AvatarUrl>
<AvatarUrl size="original">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/513/2e72ed76b7b3b9ce2f15fce64178dfaf/original.png?1642086701</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/513/2e72ed76b7b3b9ce2f15fce64178dfaf/xxlarge.png?1642086701</AvatarUrl>
<AvatarUrl size="xlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/513/2e72ed76b7b3b9ce2f15fce64178dfaf/xlarge.png?1642086701</AvatarUrl>
<AvatarUrl size="large">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/513/2e72ed76b7b3b9ce2f15fce64178dfaf/large.png?1642086701</AvatarUrl>
<AvatarUrl size="medium">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/513/2e72ed76b7b3b9ce2f15fce64178dfaf/medium.png?1642086701</AvatarUrl>
<AvatarUrl size="small">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/513/2e72ed76b7b3b9ce2f15fce64178dfaf/small.png?1642086701</AvatarUrl>
<AvatarUrl size="xsmall">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/513/2e72ed76b7b3b9ce2f15fce64178dfaf/xsmall.png?1642086701</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/000/513/2e72ed76b7b3b9ce2f15fce64178dfaf/xxsmall.png?1642086701</AvatarUrl>
<Sponsor>Division of Professional Studies</Sponsor>
<PawCount>0</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>true</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 15:33:09 -0400</PostedAt>
</NewsItem>

<NewsItem contentIssues="true" id="44295" important="false" status="posted" url="https://my3.my.umbc.edu/posts/44295">
<Title>Refactoring Legacy Code: Part 3 - Complex Conditionals</Title>
<Body>
<![CDATA[
    <div class="html-content">
    <p>Old code. Ugly code. Complicated code. Spaghetti code. Gibberish nonsense. In two words, <em>Legacy Code</em>. This is a series that will help you work and deal with it.<br></p>
    
    <p>I like to think about code just as I think about prose. Long, nested, composed sentences with exotic words are hard to understand. From time to time you need one, but most of the time, you can just use plain simple words in short sentences. This is very true for source code also. Complex conditionals are hard to understand. Long methods are like endless sentences.</p>
    
    <h2>From Prose to Code</h2>
    
    <p>Here is a "prosaic" example to cheer you up. First, the all-in-one sentence. The ugly one.</p>
    <p><em>If temperature in the server room is below five degrees, and humidity rises over fifty percent but remains under eighty, and the air pressure is steady, then the senior technician John, who has at least three years of work experience in networking and servers administration should be notified, and he must wake up in the middle of the night, dress up, go out, take his car or call a cab if he does not have a car, drive to the office, enter the building, start the air conditioning and wait until temperature raises over ten degrees and humidity falls below twenty percent.</em></p>
    
    <p>If you can understand, comprehend, and remember that paragraph without re-reading it, I give you a medal (virtual of course). Long, entangled paragraphs written in a single complicated sentence are difficult to understand. Unfortunately, I don't know enough exotic English words to make that even harder to understand.</p>
    <h3>Simplification</h3>
    
    <p>Let's find a way to simplify it a little bit. All of its first part, up until the "then" is a condition. Yes, it is complicated but we could sum it up like this: <em>If environmental conditions represent a risk...</em> ... then something should be done. The complicated expression says we should notify someone who satisfies a lot of conditions: <em>then notify level three tech support</em>. Finally, a whole process is described from waking up the tech guy until all is fixed: <em>and expect environment to be restored within normal parameters.</em> Let's put it all together.</p>
    
    <p><em>If environmental conditions represent a risk, notify level three tech support and expect environment to be restored within normal parameters.</em></p>
    
    <p>Now, that's only about 20% in length compared to the original text. We don't know the details and in the significant majority of the cases, we don't care. And this is very true for source code also. How many times did you care about the implementation details of a <code>logInfo("Some message");</code> method? Probably once, if and when you implemented it. Then it just logs the message into the "info" category. Or when a user purchases one of your products, do you care how to invoice him? No. All you want to care about is <em>if the product was bought, discard it from inventory and invoice it to the buyer</em>. The examples could be endless. They are basically how we write correct software.</p>
    
    <h2>Complex Conditionals</h2>
    
    <p>In this section we will try to apply the prose philosophy to our trivia game. One step at a time. Starting with complex conditionals. Let's begin with some easy code. Just to warm up.</p>
    
    <p>Line twenty of the <code>GameRunner.php</code> file reads like this:</p>
    
    <pre>if (rand($minAnswerId, $maxAnswerId) == $wrongAnswerId)</pre>
    
    <p>How would that sound in prose? <em>If a random number between minimum answer ID and maximum answer ID equals the wrong answer's ID, then...</em></p>
    
    <p>This is not very complicated, but we can still make it simpler. What about this? <em>If wrong answer is selected, then...</em> Better, isn't it?</p>
    
    <h3>The Extract Method Refactoring</h3>
    
    <p>We need a way, a procedure, a technique to move that conditional statement somewhere else. That destination can easily be a method. Or in our case, since we are not inside a class here, a function. This moving of behavior into a new method or function is called the "Extract Method" refactoring. Below are the steps, as defined by Martin Fowler in his excellent book Refactoring: Improving the Design of Existing Code. If you didn't read this book, you should put it on your "To read" list now. It is one of the most essential books for a modern day programmer.</p>
    
    <p>For our tutorial, I have taken the original steps and simplified them a little bit to better fit our needs and our type of tutorial.</p>
    
    <ol>
    	<li>Create a new method and name it after what it does, not how it does it.</li>
    	<li>Copy the code from the extracted place, into the method. Please note, this is <em>copy</em>, do not yet delete the original code.</li>
    	<li>Scan the extracted code for any variables that are local. They must be made parameters for the method.</li>
    	<li>See if any temporary variables are used inside the extracted method. If so, declare them inside it and drop the extra parameter.</li>
    	<li>Pass into the target method the variables as parameters.</li>
    	<li>Replace the extracted code with the call to the target method.</li>
    	<li>Run your tests.</li>
    </ol>
    
    <p>Now this is quite complicated. However, the extract method is arguably the most frequently used refactoring, except for renaming maybe. So you must understand its mechanics.</p>
    
    <p>Luckily for us, modern day IDEs like PHPStorm provide great refactoring tools, as we've seen in the tutorial <a href="http://code.tutsplus.com/tutorials/phpstorm-when-the-ide-really-matters--cms-20787" rel="nofollow external" class="bo">PHPStorm: When the IDE Really Matters</a>. So we will use the features we have at our fingertips, instead of doing it all by hand. This is less error prone and much, much faster.</p>
    
    <p>Just select the desired part of the code and <strong>right-click</strong> it.</p>
    <img alt="" src="https://s3.amazonaws.com/cms-assets.tutsplus.com/uploads/users/45/posts/20944/image/extract-method-phpstorm.png" style="max-width: 100%; height: auto;">
    
    <p>The IDE will automatically understand that we need three parameters to run our code and it will propose the following solution.</p>
    
    <pre>// ... //&#x000A;    $minAnswerId = 0;&#x000A;    $maxAnswerId = 9;&#x000A;    $wrongAnswerId = 7;&#x000A;    function isCurrentAnswerWrong($minAnswerId, $maxAnswerId, $wrongAnswerId) {&#x000A;    	return rand($minAnswerId, $maxAnswerId) == $wrongAnswerId;&#x000A;    }&#x000A;    &#x000A;    do {&#x000A;    	$dice = rand(0, 5) + 1;&#x000A;    	$aGame-&gt;roll($dice);&#x000A;    &#x000A;    	if (isCurrentAnswerWrong($minAnswerId, $maxAnswerId, $wrongAnswerId)) {&#x000A;    		$notAWinner = $aGame-&gt;wrongAnswer();&#x000A;    	} else {&#x000A;    		$notAWinner = $aGame-&gt;wasCorrectlyAnswered();&#x000A;    	}&#x000A;    &#x000A;    } while ($notAWinner);</pre>
    
    <p>While this code is syntactically correct, it will break our tests. Between all the noise shown to us in red, blue and black colors, we can spot the reason why:</p>
    
    <pre>Fatal error: Cannot redeclare isCurrentAnswerWrong()&#x000A;    (previously declared in /home/csaba/Personal/Programming/NetTuts&#x000A;    /Refactoring Legacy Code - Part 3: Complex Conditionals and Long Methods&#x000A;    /Source/trivia/php/GameRunner.php:16)&#x000A;    in /home/csaba/Personal/Programming/NetTuts&#x000A;    /Refactoring Legacy Code - Part 3: Complex Conditionals and Long Methods&#x000A;    /Source/trivia/php/GameRunner.php on line 18</pre>
    
    <p>It basically says that we want to declare the function twice. But how can that happen? We have it only once in our <code>GameRunner.php</code>!</p>
    
    <p>Take a look at the tests. There is a <code>generateOutput()</code> method that does a <code>require()</code> on our <code>GameRunner.php</code>. It is called at least twice. Here is the source of the error.</p>
    
    <p>Now we have a dilemma. Because of the seeding of the random generator, we need to call this code with controlled values.</p>
    
    <pre>private function generateOutput($seed) {&#x000A;    	ob_start();&#x000A;    	srand($seed);&#x000A;    	require __DIR__ . '/../trivia/php/GameRunner.php';&#x000A;    	$output = ob_get_contents();&#x000A;    	ob_end_clean();&#x000A;    	return $output;&#x000A;    }</pre>
    
    <p>But there is no way to declare a function twice in PHP, so we need another solution. We start to feel the burden of our golden master testing. Running the whole thing 20000 times, every time we change a piece of code, may not be a solution for the long term. Besides the fact that it takes ages to run, it forces us to change our code to accommodate the way we test it. This is usually a sign of bad tests. The code should change and still make the test pass, but the changes should have reasons to change, coming only from the source code.</p>
    
    <p>But enough talk, we need a solution, even a temporary one will do for now. Migrating to unit tests will start with our next lesson.</p>
    
    <p>One way to solve our problem is to take all the rest of the code in <code>GameRunner.php</code> and put it in a function. Let's say <code>run()</code></p>
    
    <pre>include_once __DIR__ . '/Game.php';&#x000A;    &#x000A;    function isCurrentAnswerWrong($minAnswerId, $maxAnswerId, $wrongAnswerId) {&#x000A;    	return rand($minAnswerId, $maxAnswerId) == $wrongAnswerId;&#x000A;    }&#x000A;    &#x000A;    function run() {&#x000A;    	$notAWinner;&#x000A;    &#x000A;    	$aGame = new Game();&#x000A;    &#x000A;    	$aGame-&gt;add("Chet");&#x000A;    	$aGame-&gt;add("Pat");&#x000A;    	$aGame-&gt;add("Sue");&#x000A;    &#x000A;    	$minAnswerId = 0;&#x000A;    	$maxAnswerId = 9;&#x000A;    	$wrongAnswerId = 7;&#x000A;    	do {&#x000A;    		$dice = rand(0, 5) + 1;&#x000A;    		$aGame-&gt;roll($dice);&#x000A;    &#x000A;    		if (isCurrentAnswerWrong($minAnswerId, $maxAnswerId, $wrongAnswerId)) {&#x000A;    			$notAWinner = $aGame-&gt;wrongAnswer();&#x000A;    		} else {&#x000A;    			$notAWinner = $aGame-&gt;wasCorrectlyAnswered();&#x000A;    		}&#x000A;    &#x000A;    	} while ($notAWinner);&#x000A;    }</pre>
    
    <p>This will allow us to test it, but be aware that running the code from the console will not run the game. We did a slight change in behavior. We gained testability at the cost of a behavioral change, which we did not want to do in the first place. If you want to run the code from the console, now you will need another PHP file that includes or requires the runner and then explicitly calls the run method on it. Not that big of a change but a must to remember, especially if you have third parties using your existing code.</p>
    
    <p>On the other hand, we can now just include the file in our test.</p>
    
    <pre>require __DIR__ . '/../trivia/php/GameRunner.php';</pre>
    
    <p>And then call <code>run()</code> inside the generateOutput() method.</p>
    
    <pre>private function generateOutput($seed) {&#x000A;    	ob_start();&#x000A;    	srand($seed);&#x000A;    	run();&#x000A;    	$output = ob_get_contents();&#x000A;    	ob_end_clean();&#x000A;    	return $output;&#x000A;    }</pre>
    
    <h3>Directory Structure, Files, &amp; Naming</h3>
    
    <p>Maybe this is a good opportunity to think about the structure of our directories and files. There are no more complex conditionals in our <code>GameRunner.php</code>, but before we continue to the <code>Game.php</code> file, we must not leave a mess behind us. Our <code>GameRunner.php</code> is not running anything, anymore and we needed to hack methods together to make it testable, which broke our public interface. The reason for this, is that maybe we are testing the wrong thing.</p>
    <img alt="" src="https://s3.amazonaws.com/cms-assets.tutsplus.com/uploads/users/45/posts/20944/image/testing-deps-schema.png" style="max-width: 100%; height: auto;">
    
    <p>Our test calls <code>run()</code> in the <code>GameRunner.php</code> file, which includes <code>Game.php</code>, plays the game and a new golden master file is generated. What if we introduce another file? We make the <code>GameRunner.php</code> to actually run the game by calling <code>run()</code> and nothing else. So what if there's no logic in there that could go wrong and no tests are needed, and then we move our current code into another file?</p>
    <img alt="" src="https://s3.amazonaws.com/cms-assets.tutsplus.com/uploads/users/45/posts/20944/image/testing-deps-with-new-runner.png" style="max-width: 100%; height: auto;">
    
    <p>Now this is a whole different story. Now our tests are accessing the code just under the runner. Basically, our tests are just runners. And of course in our new <code>GameRunner.php</code> there will only be a call to run the game. This is a true runner, it does nothing else but call the <code>run()</code> method. No logic means no tests are needed.</p>
    
    <pre>require_once __DIR__ . '/RunnerFunctions.php';&#x000A;    run();</pre>
    
    <p>There are other questions we could ask ourselves at this point. Do we really need a <code>RunnerFunctions.php</code>? Couldn't we just take the functions from there and move them to <code>Game.php</code>? We probably could, but with our current understanding of, what function belongs where? Is not enough. We will find a place for our method in an upcoming lesson.</p>
    
    <p>We also tried to name our files according to what the code inside them is doing. One is just a bunch of functions for the runner, functions we, at this point consider to belong together, in order to satisfy the needs of the runner. Will this become a class at one point in the future? Maybe. Maybe not. For now, it is good enough.</p>
    
    <h3>Cleaning Up RunnerFunctions</h3>
    
    <p>If we take a look at the <code>RunnerFunctions.php</code> file, there is a little bit of a mess that we've introduced.</p>
    
    <p>We define:</p>
    
    <pre>$minAnswerId = 0;&#x000A;    $maxAnswerId = 9;&#x000A;    $wrongAnswerId = 7;</pre>
    
    <p>... inside the <code>run()</code> method. They have a single reason to exist and a single place where they are used. Why not just define them inside that method and get rid of the parameters altogether?</p>
    
    <pre>function isCurrentAnswerWrong() {&#x000A;    	$minAnswerId = 0;&#x000A;    	$maxAnswerId = 9;&#x000A;    	$wrongAnswerId = 7;&#x000A;    	return rand($minAnswerId, $maxAnswerId) == $wrongAnswerId;&#x000A;    }</pre>
    
    <p>Ok, the tests are passing and the code is much nicer. But not good enough.</p>
    
    <h3>Negative Conditionals</h3>
    
    <p>It is much easier, for the human mind, to comprehend positive reasoning. So if you can avoid negative conditionals, you should always take that path. In our current example, the method checks for a wrong answer. It would be much easier to understand a method that checks for a validity and negate that, when needed.</p>
    
    <pre>function isCurrentAnswerCorrect() {&#x000A;    	$minAnswerId = 0;&#x000A;    	$maxAnswerId = 9;&#x000A;    	$wrongAnswerId = 7;&#x000A;    	return rand($minAnswerId, $maxAnswerId) != $wrongAnswerId;&#x000A;    }</pre>
    
    <p>We used the Rename Method refactoring. This is again, pretty complicated if used by hand, but in any IDE it is as simple as hitting <strong>CTRL+r</strong>, or selecting the appropriate option in the menu. To make our tests pass, we also need to update our conditional statement with a negation.</p>
    
    <pre>if (!isCurrentAnswerCorrect()) {&#x000A;    	$notAWinner = $aGame-&gt;wrongAnswer();&#x000A;    } else {&#x000A;    	$notAWinner = $aGame-&gt;wasCorrectlyAnswered();&#x000A;    }</pre>
    
    <p>This brings us one step closer to our understanding of the conditional. Using <code>!</code> in an <code>if()</code> statement, actually helps. It stands out and highlights the fact that something is actually negated there. But can we reverse this in order, to avoid negation completely? Yes we can.</p>
    
    <pre>if (isCurrentAnswerCorrect()) {&#x000A;    	$notAWinner = $aGame-&gt;wasCorrectlyAnswered();&#x000A;    } else {&#x000A;    	$notAWinner = $aGame-&gt;wrongAnswer();&#x000A;    }</pre>
    
    <p>Now we have no logical negation by using <code>!</code>, nor lexical negation by naming and returning the wrong things. All these steps made our conditional much, much more easier to comprehend.</p>
    
    <h2>Conditionals in <code>Game.php</code>
    </h2>
    
    <p>We simplified to the extreme, <code>RunnerFunctions.php</code>. Let's attack our <code>Game.php</code> file now. There are several ways you can search for conditionals. If you prefer, you can just scan the code by simply looking at it. This is slower, but has the added value of forcing you to try to understand it sequentially.</p>
    
    <p>The second obvious way to search for conditionals, is to just do a find for "if" or "if (". If you formatted your code with the built-in features of your IDE, you can be sure that all conditional statements have the same specific form. In my case, there is a space between the "if" and the parenthesis. Also, if you use the built-in search, the found results will be highlighted in a strident color, in my case yellow.</p>
    <img alt="" src="https://s3.amazonaws.com/cms-assets.tutsplus.com/uploads/users/45/posts/20944/image/ide-find-highlights.png" style="max-width: 100%; height: auto;">
    
    <p>Now that we have all of them lighting up our code like a Christmas tree, we can take them one by one. We know the drill, we know the techniques we can use, it's time to apply them.</p>
    
    <pre>if ($this-&gt;inPenaltyBox[$this-&gt;currentPlayer])</pre>
    
    <p>This seems pretty reasonable. We could extract it into a method, but would there be a name for that method in order to make the condition clearer?</p>
    
    <pre>if ($roll % 2 != 0) </pre>
    
    <p>I bet 90% of all programmers can understand the problem in the above <code>if</code> statement. We are trying to concentrate on what our current method does. And our brain is wired into the domain of the problem. We don't want to "start another thread" to compute that mathematical expression in order to understand that it just checks if a number is odd. This is one of those small distractions that can ruin a difficult logical deduction. So I say let's extract it.</p>
    
    <pre>if ($this-&gt;isOdd($roll))</pre>
    
    <p>That is better because it is about the problem's domain and requires no additional brain power.</p>
    
    <pre>if ($this-&gt;places[$this-&gt;currentPlayer] &gt; $lastPositionOnTheBoard)</pre>
    
    <p>This seems to be another good candidate. It is not that difficult to understand as a mathematical expression, but again, it is an expression that needs side-processing. I am asking myself, what does it mean if the current player's position reached the end of the board? Can't we express this state in a more concise way? We probably can.</p>
    
    <pre>if ($this-&gt;playerReachedEndOfBoard($lastPositionOnTheBoard))</pre>
    
    <p>This is better. But what actually happens inside the <code>if</code>? The player is repositioned at the beginning of the board. The player starts a new "lap" in the race. What if in the future, we will have a different reason for starting a new lap? Should our <code>if</code> statement change when we change the underlying logic in the private method? Absolutely not! So, let's rename this method into what the <code>if</code> represents, into what happens, not what we are checking for. </p>
    
    <pre>if ($this-&gt;playerShouldStartANewLap($lastPositionOnTheBoard))</pre>
    
    <p>When you try to name methods and variables, always think about what the code should do and not what state or condition it represents. Once you get this right, renaming actions in your code will drop significantly. But still, even an experienced programmer needs to rename a method at least three to five times before finding its correct name. So don't be afraid to hit <strong>CTRL+r</strong> and rename frequently. Never commit your changes to the project's VCS if you did not scan the names of your newly added methods and your code does not read like well written prose. Renaming is so cheap in our days, that you can rename things just to try out various versions and revert with a single hit of a button.</p>
    
    <p>The <code>if</code> statement at line 90 is the same as our previous one. We can just reuse our extracted method. Voila, duplication eliminated! And don't forget to run your tests now-and-then, even when you refactor by using your IDE's magic. Which leads us to our next observation. Magic, sometimes, fails. Check out line 65.</p>
    
    <pre>$lastPositionOnTheBoard = 11;</pre>
    
    <p>We declare a variable and use it only in a single place, as a parameter to our newly extracted method. This strongly suggests that the variable should be inside the method.</p>
    
    <pre>private function playerShouldStartANewLap() {&#x000A;    	$lastPositionOnTheBoard = 11;&#x000A;    	return $this-&gt;places[$this-&gt;currentPlayer] &gt; $lastPositionOnTheBoard;&#x000A;    }</pre>
    
    <p>And don't forget to call the method without any parameters in your <code>if</code> statements.</p>
    
    <pre>if ($this-&gt;playerShouldStartANewLap())</pre>
    
    <p>The <code>if</code> statements in the <code>askQuestion()</code> method seem to be all right, as well as the ones in <code>currentCategory()</code>.</p>
    
    <pre>if ($this-&gt;inPenaltyBox[$this-&gt;currentPlayer])</pre>
    
    <p>This is a little bit more complicated, but in the domain and expressive enough.</p>
    
    <pre>if ($this-&gt;currentPlayer == count($this-&gt;players))</pre>
    
    <p>We can work on this one. It is obvious the comparison means, if the current player is out of bound. But as we learned above, we want intention not state. </p>
    
    <pre>if ($this-&gt;shouldResetCurrentPlayer())</pre>
    
    <p>That's much better, and we will reuse it at line 172, 189 and 203. Duplication, I mean triplication, I mean quadruplication, eliminated!</p>
    
    <p>Tests are passing and all <code>if</code> statements were evaluated for complexity.</p>
    
    <h2>Final Thoughts</h2>
    
    <p>There are several lessons that can be learned from refactoring conditionals. First of all, they help better understand the intent of the code. Then if you name the extracted method to represent the intent correctly, you will avoid future name changes. Finding duplication in logic is more difficult than finding duplicated lines of simple code. You may have thought we should do a conscious duplication, but I prefer to deal with duplication when I have unit tests I can trust my life with. The Golden Master is good, but it is at most a safety net, not a parachute.</p>
    
    <p>Thanks for reading and stay tuned for our next tutorial when we will introduce our first unit tests.</p>
    </div>
]]>
</Body>
<Summary>Old code. Ugly code. Complicated code. Spaghetti code. Gibberish nonsense. In two words, Legacy Code. This is a series that will help you work and deal with it.     I like to think about code just...</Summary>
<Website>http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-3-complex-conditionals--cms-20944</Website>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/44295/guest@my.umbc.edu/cfd305f03d395b9969d039dc8acd9003/api/pixel</TrackingUrl>
<Tag>css</Tag>
<Tag>development</Tag>
<Tag>html</Tag>
<Tag>javascript</Tag>
<Tag>mysql</Tag>
<Tag>php</Tag>
<Tag>sql</Tag>
<Tag>wed</Tag>
<Group token="retired-583">Web Developer - Build Group</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/retired-583</GroupUrl>
<AvatarUrl>https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xsmall.png?1363101197</AvatarUrl>
<AvatarUrl size="original">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/original.jpg?1363101197</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xxlarge.png?1363101197</AvatarUrl>
<AvatarUrl size="xlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xlarge.png?1363101197</AvatarUrl>
<AvatarUrl size="large">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/large.png?1363101197</AvatarUrl>
<AvatarUrl size="medium">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/medium.png?1363101197</AvatarUrl>
<AvatarUrl size="small">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/small.png?1363101197</AvatarUrl>
<AvatarUrl size="xsmall">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xsmall.png?1363101197</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xxsmall.png?1363101197</AvatarUrl>
<Sponsor>Web Developer - Build Group</Sponsor>
<PawCount>0</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>true</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 15:32:42 -0400</PostedAt>
</NewsItem>

<NewsItem contentIssues="true" id="44286" important="false" status="posted" url="https://my3.my.umbc.edu/posts/44286">
<Title>Refactoring Legacy Code: Part 3 - Complex Conditionals &amp; Long Methods</Title>
<Body>
<![CDATA[
    <div class="html-content">
    <p>Old code. Ugly code. Complicated code. Spaghetti code. Gibberish nonsense. In two words, <em>Legacy Code</em>. This is a series that will help you work and deal with it.<br></p>
    
    <p>I like to think about code just as I think about prose. Long, nested, composed sentences with exotic words are hard to understand. From time to time you need one, but most of the time, you can just use plain simple words in short sentences. This is very true for source code also. Complex conditionals are hard to understand. Long methods are like endless sentences.</p>
    
    <h2>From Prose to Code</h2>
    
    <p>Here is a "prosaic" example to cheer you up. First, the all-in-one sentence. The ugly one.</p>
    <p><em>If temperature in the server room is below five degrees, and humidity rises over fifty percent but remains under eighty, and the air pressure is steady, then the senior technician John, who has at least three years of work experience in networking and servers administration should be notified, and he must wake up in the middle of the night, dress up, go out, take his car or call a cab if he does not have a car, drive to the office, enter the building, start the air conditioning and wait until temperature raises over ten degrees and humidity falls below twenty percent.</em></p>
    
    <p>If you can understand, comprehend, and remember that paragraph without re-reading it, I give you a medal (virtual of course). Long, entangled paragraphs written in a single complicated sentence are difficult to understand. Unfortunately, I don't know enough exotic English words to make that even harder to understand.</p>
    <h3>Simplification</h3>
    
    <p>Let's find a way to simplify it a little bit. All of its first part, up until the "then" is a condition. Yes, it is complicated but we could sum it up like this: <em>If environmental conditions represent a risk...</em> ... then something should be done. The complicated expression says we should notify someone who satisfies a lot of conditions: <em>then notify level three tech support</em>. Finally, a whole process is described from waking up the tech guy until all is fixed: <em>and expect environment to be restored within normal parameters.</em> Let's put it all together.</p>
    
    <p><em>If environmental conditions represent a risk, notify level three tech support and expect environment to be restored within normal parameters.</em></p>
    
    <p>Now, that's only about 20% in length compared to the original text. We don't know the details and in the significant majority of the cases, we don't care. And this is very true for source code also. How many times did you care about the implementation details of a <code>logInfo("Some message");</code> method? Probably once, if and when you implemented it. Then it just logs the message into the "info" category. Or when a user purchases one of your products, do you care how to invoice him? No. All you want to care about is <em>if the product was bought, discard it from inventory and invoice it to the buyer</em>. The examples could be endless. They are basically how we write correct software.</p>
    
    <h2>Complex Conditionals</h2>
    
    <p>In this section we will try to apply the prose philosophy to our trivia game. One step at a time. Starting with complex conditionals. Let's begin with some easy code. Just to warm up.</p>
    
    <p>Line twenty of the <code>GameRunner.php</code> file reads like this:</p>
    
    <pre>if (rand($minAnswerId, $maxAnswerId) == $wrongAnswerId)</pre>
    
    <p>How would that sound in prose? <em>If a random number between minimum answer ID and maximum answer ID equals the wrong answer's ID, then...</em></p>
    
    <p>This is not very complicated, but we can still make it simpler. What about this? <em>If wrong answer is selected, then...</em> Better, isn't it?</p>
    
    <h3>The Extract Method Refactoring</h3>
    
    <p>We need a way, a procedure, a technique to move that conditional statement somewhere else. That destination can easily be a method. Or in our case, since we are not inside a class here, a function. This moving of behavior into a new method or function is called the "Extract Method" refactoring. Below are the steps, as defined by Martin Fowler in his excellent book Refactoring: Improving the Design of Existing Code. If you didn't read this book, you should put it on your "To read" list now. It is one of the most essential books for a modern day programmer.</p>
    
    <p>For our tutorial, I have taken the original steps and simplified them a little bit to better fit our needs and our type of tutorial.</p>
    
    <ol>
    	<li>Create a new method and name it after what it does, not how it does it.</li>
    	<li>Copy the code from the extracted place, into the method. Please note, this is <em>copy</em>, do not yet delete the original code.</li>
    	<li>Scan the extracted code for any variables that are local. They must be made parameters for the method.</li>
    	<li>See if any temporary variables are used inside the extracted method. If so, declare them inside it and drop the extra parameter.</li>
    	<li>Pass into the target method the variables as parameters.</li>
    	<li>Replace the extracted code with the call to the target method.</li>
    	<li>Run your tests.</li>
    </ol>
    
    <p>Now this is quite complicated. However, the extract method is arguably the most frequently used refactoring, except for renaming maybe. So you must understand its mechanics.</p>
    
    <p>Luckily for us, modern day IDEs like PHPStorm provide great refactoring tools, as we've seen in the tutorial <a href="http://code.tutsplus.com/tutorials/phpstorm-when-the-ide-really-matters--cms-20787" rel="nofollow external" class="bo">PHPStorm: When the IDE Really Matters</a>. So we will use the features we have at our fingertips, instead of doing it all by hand. This is less error prone and much, much faster.</p>
    
    <p>Just select the desired part of the code and <strong>right-click</strong> it.</p>
    <img alt="" src="https://s3.amazonaws.com/cms-assets.tutsplus.com/uploads/users/45/posts/20944/image/extract-method-phpstorm.png" style="max-width: 100%; height: auto;">
    
    <p>The IDE will automatically understand that we need three parameters to run our code and it will propose the following solution.</p>
    
    <pre>// ... //&#x000A;    $minAnswerId = 0;&#x000A;    $maxAnswerId = 9;&#x000A;    $wrongAnswerId = 7;&#x000A;    function isCurrentAnswerWrong($minAnswerId, $maxAnswerId, $wrongAnswerId) {&#x000A;    	return rand($minAnswerId, $maxAnswerId) == $wrongAnswerId;&#x000A;    }&#x000A;    &#x000A;    do {&#x000A;    	$dice = rand(0, 5) + 1;&#x000A;    	$aGame-&gt;roll($dice);&#x000A;    &#x000A;    	if (isCurrentAnswerWrong($minAnswerId, $maxAnswerId, $wrongAnswerId)) {&#x000A;    		$notAWinner = $aGame-&gt;wrongAnswer();&#x000A;    	} else {&#x000A;    		$notAWinner = $aGame-&gt;wasCorrectlyAnswered();&#x000A;    	}&#x000A;    &#x000A;    } while ($notAWinner);</pre>
    
    <p>While this code is syntactically correct, it will break our tests. Between all the noise shown to us in red, blue and black colors, we can spot the reason why:</p>
    
    <pre>Fatal error: Cannot redeclare isCurrentAnswerWrong()&#x000A;    (previously declared in /home/csaba/Personal/Programming/NetTuts&#x000A;    /Refactoring Legacy Code - Part 3: Complex Conditionals and Long Methods&#x000A;    /Source/trivia/php/GameRunner.php:16)&#x000A;    in /home/csaba/Personal/Programming/NetTuts&#x000A;    /Refactoring Legacy Code - Part 3: Complex Conditionals and Long Methods&#x000A;    /Source/trivia/php/GameRunner.php on line 18</pre>
    
    <p>It basically says that we want to declare the function twice. But how can that happen? We have it only once in our <code>GameRunner.php</code>!</p>
    
    <p>Take a look at the tests. There is a <code>generateOutput()</code> method that does a <code>require()</code> on our <code>GameRunner.php</code>. It is called at least twice. Here is the source of the error.</p>
    
    <p>Now we have a dilemma. Because of the seeding of the random generator, we need to call this code with controlled values.</p>
    
    <pre>private function generateOutput($seed) {&#x000A;    	ob_start();&#x000A;    	srand($seed);&#x000A;    	require __DIR__ . '/../trivia/php/GameRunner.php';&#x000A;    	$output = ob_get_contents();&#x000A;    	ob_end_clean();&#x000A;    	return $output;&#x000A;    }</pre>
    
    <p>But there is no way to declare a function twice in PHP, so we need another solution. We start to feel the burden of our golden master testing. Running the whole thing 20000 times, every time we change a piece of code, may not be a solution for the long term. Besides the fact that it takes ages to run, it forces us to change our code to accommodate the way we test it. This is usually a sign of bad tests. The code should change and still make the test pass, but the changes should have reasons to change, coming only from the source code.</p>
    
    <p>But enough talk, we need a solution, even a temporary one will do for now. Migrating to unit tests will start with our next lesson.</p>
    
    <p>One way to solve our problem is to take all the rest of the code in <code>GameRunner.php</code> and put it in a function. Let's say <code>run()</code></p>
    
    <pre>include_once __DIR__ . '/Game.php';&#x000A;    &#x000A;    function isCurrentAnswerWrong($minAnswerId, $maxAnswerId, $wrongAnswerId) {&#x000A;    	return rand($minAnswerId, $maxAnswerId) == $wrongAnswerId;&#x000A;    }&#x000A;    &#x000A;    function run() {&#x000A;    	$notAWinner;&#x000A;    &#x000A;    	$aGame = new Game();&#x000A;    &#x000A;    	$aGame-&gt;add("Chet");&#x000A;    	$aGame-&gt;add("Pat");&#x000A;    	$aGame-&gt;add("Sue");&#x000A;    &#x000A;    	$minAnswerId = 0;&#x000A;    	$maxAnswerId = 9;&#x000A;    	$wrongAnswerId = 7;&#x000A;    	do {&#x000A;    		$dice = rand(0, 5) + 1;&#x000A;    		$aGame-&gt;roll($dice);&#x000A;    &#x000A;    		if (isCurrentAnswerWrong($minAnswerId, $maxAnswerId, $wrongAnswerId)) {&#x000A;    			$notAWinner = $aGame-&gt;wrongAnswer();&#x000A;    		} else {&#x000A;    			$notAWinner = $aGame-&gt;wasCorrectlyAnswered();&#x000A;    		}&#x000A;    &#x000A;    	} while ($notAWinner);&#x000A;    }</pre>
    
    <p>This will allow us to test it, but be aware that running the code from the console will not run the game. We did a slight change in behavior. We gained testability at the cost of a behavioral change, which we did not want to do in the first place. If you want to run the code from the console, now you will need another PHP file that includes or requires the runner and then explicitly calls the run method on it. Not that big of a change but a must to remember, especially if you have third parties using your existing code.</p>
    
    <p>On the other hand, we can now just include the file in our test.</p>
    
    <pre>require __DIR__ . '/../trivia/php/GameRunner.php';</pre>
    
    <p>And then call <code>run()</code> inside the generateOutput() method.</p>
    
    <pre>private function generateOutput($seed) {&#x000A;    	ob_start();&#x000A;    	srand($seed);&#x000A;    	run();&#x000A;    	$output = ob_get_contents();&#x000A;    	ob_end_clean();&#x000A;    	return $output;&#x000A;    }</pre>
    
    <h3>Directory Structure, Files, &amp; Naming</h3>
    
    <p>Maybe this is a good opportunity to think about the structure of our directories and files. There are no more complex conditionals in our <code>GameRunner.php</code>, but before we continue to the <code>Game.php</code> file, we must not leave a mess behind us. Our <code>GameRunner.php</code> is not running anything, anymore and we needed to hack methods together to make it testable, which broke our public interface. The reason for this, is that maybe we are testing the wrong thing.</p>
    <img alt="" src="https://s3.amazonaws.com/cms-assets.tutsplus.com/uploads/users/45/posts/20944/image/testing-deps-schema.png" style="max-width: 100%; height: auto;">
    
    <p>Our test calls <code>run()</code> in the <code>GameRunner.php</code> file, which includes <code>Game.php</code>, plays the game and a new golden master file is generated. What if we introduce another file? We make the <code>GameRunner.php</code> to actually run the game by calling <code>run()</code> and nothing else. So what if there's no logic in there that could go wrong and no tests are needed, and then we move our current code into another file?</p>
    <img alt="" src="https://s3.amazonaws.com/cms-assets.tutsplus.com/uploads/users/45/posts/20944/image/testing-deps-with-new-runner.png" style="max-width: 100%; height: auto;">
    
    <p>Now this is a whole different story. Now our tests are accessing the code just under the runner. Basically, our tests are just runners. And of course in our new <code>GameRunner.php</code> there will only be a call to run the game. This is a true runner, it does nothing else but call the <code>run()</code> method. No logic means no tests are needed.</p>
    
    <pre>require_once __DIR__ . '/RunnerFunctions.php';&#x000A;    run();</pre>
    
    <p>There are other questions we could ask ourselves at this point. Do we really need a <code>RunnerFunctions.php</code>? Couldn't we just take the functions from there and move them to <code>Game.php</code>? We probably could, but with our current understanding of, what function belongs where? Is not enough. We will find a place for our method in an upcoming lesson.</p>
    
    <p>We also tried to name our files according to what the code inside them is doing. One is just a bunch of functions for the runner, functions we, at this point consider to belong together, in order to satisfy the needs of the runner. Will this become a class at one point in the future? Maybe. Maybe not. For now, it is good enough.</p>
    
    <h3>Cleaning Up RunnerFunctions</h3>
    
    <p>If we take a look at the <code>RunnerFunctions.php</code> file, there is a little bit of a mess that we've introduced.</p>
    
    <p>We define:</p>
    
    <pre>$minAnswerId = 0;&#x000A;    $maxAnswerId = 9;&#x000A;    $wrongAnswerId = 7;</pre>
    
    <p>... inside the <code>run()</code> method. They have a single reason to exist and a single place where they are used. Why not just define them inside that method and get rid of the parameters altogether?</p>
    
    <pre>function isCurrentAnswerWrong() {&#x000A;    	$minAnswerId = 0;&#x000A;    	$maxAnswerId = 9;&#x000A;    	$wrongAnswerId = 7;&#x000A;    	return rand($minAnswerId, $maxAnswerId) == $wrongAnswerId;&#x000A;    }</pre>
    
    <p>Ok, the tests are passing and the code is much nicer. But not good enough.</p>
    
    <h3>Negative Conditionals</h3>
    
    <p>It is much easier, for the human mind, to comprehend positive reasoning. So if you can avoid negative conditionals, you should always take that path. In our current example, the method checks for a wrong answer. It would be much easier to understand a method that checks for a validity and negate that, when needed.</p>
    
    <pre>function isCurrentAnswerCorrect() {&#x000A;    	$minAnswerId = 0;&#x000A;    	$maxAnswerId = 9;&#x000A;    	$wrongAnswerId = 7;&#x000A;    	return rand($minAnswerId, $maxAnswerId) != $wrongAnswerId;&#x000A;    }</pre>
    
    <p>We used the Rename Method refactoring. This is again, pretty complicated if used by hand, but in any IDE it is as simple as hitting <strong>CTRL+r</strong>, or selecting the appropriate option in the menu. To make our tests pass, we also need to update our conditional statement with a negation.</p>
    
    <pre>if (!isCurrentAnswerCorrect()) {&#x000A;    	$notAWinner = $aGame-&gt;wrongAnswer();&#x000A;    } else {&#x000A;    	$notAWinner = $aGame-&gt;wasCorrectlyAnswered();&#x000A;    }</pre>
    
    <p>This brings us one step closer to our understanding of the conditional. Using <code>!</code> in an <code>if()</code> statement, actually helps. It stands out and highlights the fact that something is actually negated there. But can we reverse this in order, to avoid negation completely? Yes we can.</p>
    
    <pre>if (isCurrentAnswerCorrect()) {&#x000A;    	$notAWinner = $aGame-&gt;wasCorrectlyAnswered();&#x000A;    } else {&#x000A;    	$notAWinner = $aGame-&gt;wrongAnswer();&#x000A;    }</pre>
    
    <p>Now we have no logical negation by using <code>!</code>, nor lexical negation by naming and returning the wrong things. All these steps made our conditional much, much more easier to comprehend.</p>
    
    <h2>Conditionals in <code>Game.php</code>
    </h2>
    
    <p>We simplified to the extreme, <code>RunnerFunctions.php</code>. Let's attack our <code>Game.php</code> file now. There are several ways you can search for conditionals. If you prefer, you can just scan the code by simply looking at it. This is slower, but has the added value of forcing you to try to understand it sequentially.</p>
    
    <p>The second obvious way to search for conditionals, is to just do a find for "if" or "if (". If you formatted your code with the built-in features of your IDE, you can be sure that all conditional statements have the same specific form. In my case, there is a space between the "if" and the parenthesis. Also, if you use the built-in search, the found results will be highlighted in a strident color, in my case yellow.</p>
    <img alt="" src="https://s3.amazonaws.com/cms-assets.tutsplus.com/uploads/users/45/posts/20944/image/ide-find-highlights.png" style="max-width: 100%; height: auto;">
    
    <p>Now that we have all of them lighting up our code like a Christmas tree, we can take them one by one. We know the drill, we know the techniques we can use, it's time to apply them.</p>
    
    <pre>if ($this-&gt;inPenaltyBox[$this-&gt;currentPlayer])</pre>
    
    <p>This seems pretty reasonable. We could extract it into a method, but would there be a name for that method in order to make the condition clearer?</p>
    
    <pre>if ($roll % 2 != 0) </pre>
    
    <p>I bet 90% of all programmers can understand the problem in the above <code>if</code> statement. We are trying to concentrate on what our current method does. And our brain is wired into the domain of the problem. We don't want to "start another thread" to compute that mathematical expression in order to understand that it just checks if a number is odd. This is one of those small distractions that can ruin a difficult logical deduction. So I say let's extract it.</p>
    
    <pre>if ($this-&gt;isOdd($roll))</pre>
    
    <p>That is better because it is about the problem's domain and requires no additional brain power.</p>
    
    <pre>if ($this-&gt;places[$this-&gt;currentPlayer] &gt; $lastPositionOnTheBoard)</pre>
    
    <p>This seems to be another good candidate. It is not that difficult to understand as a mathematical expression, but again, it is an expression that needs side-processing. I am asking myself, what does it mean if the current player's position reached the end of the board? Can't we express this state in a more concise way? We probably can.</p>
    
    <pre>if ($this-&gt;playerReachedEndOfBoard($lastPositionOnTheBoard))</pre>
    
    <p>This is better. But what actually happens inside the <code>if</code>? The player is repositioned at the beginning of the board. The player starts a new "lap" in the race. What if in the future, we will have a different reason for starting a new lap? Should our <code>if</code> statement change when we change the underlying logic in the private method? Absolutely not! So, let's rename this method into what the <code>if</code> represents, into what happens, not what we are checking for. </p>
    
    <pre>if ($this-&gt;playerShouldStartANewLap($lastPositionOnTheBoard))</pre>
    
    <p>When you try to name methods and variables, always think about what the code should do and not what state or condition it represents. Once you get this right, renaming actions in your code will drop significantly. But still, even an experienced programmer needs to rename a method at least three to five times before finding its correct name. So don't be afraid to hit <strong>CTRL+r</strong> and rename frequently. Never commit your changes to the project's VCS if you did not scan the names of your newly added methods and your code does not read like well written prose. Renaming is so cheap in our days, that you can rename things just to try out various versions and revert with a single hit of a button.</p>
    
    <p>The <code>if</code> statement at line 90 is the same as our previous one. We can just reuse our extracted method. Voila, duplication eliminated! And don't forget to run your tests now-and-then, even when you refactor by using your IDE's magic. Which leads us to our next observation. Magic, sometimes, fails. Check out line 65.</p>
    
    <pre>$lastPositionOnTheBoard = 11;</pre>
    
    <p>We declare a variable and use it only in a single place, as a parameter to our newly extracted method. This strongly suggests that the variable should be inside the method.</p>
    
    <pre>private function playerShouldStartANewLap() {&#x000A;    	$lastPositionOnTheBoard = 11;&#x000A;    	return $this-&gt;places[$this-&gt;currentPlayer] &gt; $lastPositionOnTheBoard;&#x000A;    }</pre>
    
    <p>And don't forget to call the method without any parameters in your <code>if</code> statements.</p>
    
    <pre>if ($this-&gt;playerShouldStartANewLap())</pre>
    
    <p>The <code>if</code> statements in the <code>askQuestion()</code> method seem to be all right, as well as the ones in <code>currentCategory()</code>.</p>
    
    <pre>if ($this-&gt;inPenaltyBox[$this-&gt;currentPlayer])</pre>
    
    <p>This is a little bit more complicated, but in the domain and expressive enough.</p>
    
    <pre>if ($this-&gt;currentPlayer == count($this-&gt;players))</pre>
    
    <p>We can work on this one. It is obvious the comparison means, if the current player is out of bound. But as we learned above, we want intention not state. </p>
    
    <pre>if ($this-&gt;shouldResetCurrentPlayer())</pre>
    
    <p>That's much better, and we will reuse it at line 172, 189 and 203. Duplication, I mean triplication, I mean quadruplication, eliminated!</p>
    
    <p>Tests are passing and all <code>if</code> statements were evaluated for complexity.</p>
    
    <h2>Final Thoughts</h2>
    
    <p>There are several lessons that can be learned from refactoring conditionals. First of all, they help better understand the intent of the code. Then if you name the extracted method to represent the intent correctly, you will avoid future name changes. Finding duplication in logic is more difficult than finding duplicated lines of simple code. You may have thought we should do a conscious duplication, but I prefer to deal with duplication when I have unit tests I can trust my life with. The Golden Master is good, but it is at most a safety net, not a parachute.</p>
    
    <p>Thanks for reading and stay tuned for our next tutorial when we will introduce our first unit tests.</p>
    </div>
]]>
</Body>
<Summary>Old code. Ugly code. Complicated code. Spaghetti code. Gibberish nonsense. In two words, Legacy Code. This is a series that will help you work and deal with it.     I like to think about code just...</Summary>
<Website>http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-3-complex-conditionals-long-methods--cms-20944</Website>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/44286/guest@my.umbc.edu/eb2dd89101d2aca86acb9699a9c1c282/api/pixel</TrackingUrl>
<Tag>css</Tag>
<Tag>development</Tag>
<Tag>html</Tag>
<Tag>javascript</Tag>
<Tag>mysql</Tag>
<Tag>php</Tag>
<Tag>sql</Tag>
<Tag>wed</Tag>
<Group token="retired-583">Web Developer - Build Group</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/retired-583</GroupUrl>
<AvatarUrl>https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xsmall.png?1363101197</AvatarUrl>
<AvatarUrl size="original">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/original.jpg?1363101197</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xxlarge.png?1363101197</AvatarUrl>
<AvatarUrl size="xlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xlarge.png?1363101197</AvatarUrl>
<AvatarUrl size="large">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/large.png?1363101197</AvatarUrl>
<AvatarUrl size="medium">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/medium.png?1363101197</AvatarUrl>
<AvatarUrl size="small">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/small.png?1363101197</AvatarUrl>
<AvatarUrl size="xsmall">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xsmall.png?1363101197</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/583/fc60f5d7abc2e080599bb6dc465db54d/xxsmall.png?1363101197</AvatarUrl>
<Sponsor>Web Developer - Build Group</Sponsor>
<PawCount>0</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>true</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 15:32:42 -0400</PostedAt>
</NewsItem>

<NewsItem contentIssues="false" id="109704" important="false" status="posted" url="https://my3.my.umbc.edu/posts/109704">
<Title>Advancing Excellence: Innovative Curriculum and Pedagogy</Title>
<Body>
<![CDATA[
    <div class="html-content">This is the third in a series of articles on the four focus areas that are part of UMBC’s strategic planning process. The primary goal of the Innovative Curriculum and Pedagogy strategy group is to develop strategies and goals that will enable UMBC to continue its leadership in innovative curricula and academic programs that support and enhance undergraduate and graduate student success; prepare students for meaningful careers, lifelong learning, and engaged citizenship; and thereby maintain and enhance UMBC’s position as a national leader in undergraduate and graduate education. Jeff Leips, associate professor, biological sciences, and Carole McCann, professor and chair, …</div>
]]>
</Body>
<Summary>This is the third in a series of articles on the four focus areas that are part of UMBC’s strategic planning process. The primary goal of the Innovative Curriculum and Pedagogy strategy group is...</Summary>
<Website>https://news.umbc.edu/advancing-excellence-innovative-curriculum-and-pedagogy/</Website>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/109704/guest@my.umbc.edu/0707193e66d4cf7f2e1f57853b561ed0/api/pixel</TrackingUrl>
<Tag>community</Tag>
<Group token="umbc-news">UMBC News</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/umbc-news</GroupUrl>
<AvatarUrl>https://assets2-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xsmall.png?1632921809</AvatarUrl>
<AvatarUrl size="original">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/original.png?1632921809</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xxlarge.png?1632921809</AvatarUrl>
<AvatarUrl size="xlarge">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xlarge.png?1632921809</AvatarUrl>
<AvatarUrl size="large">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/large.png?1632921809</AvatarUrl>
<AvatarUrl size="medium">https://assets1-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/medium.png?1632921809</AvatarUrl>
<AvatarUrl size="small">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/small.png?1632921809</AvatarUrl>
<AvatarUrl size="xsmall">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xsmall.png?1632921809</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/001/944/2c79aeea85b1abb37f8cf9fbcdc382b0/xxsmall.png?1632921809</AvatarUrl>
<Sponsor>UMBC News</Sponsor>
<PawCount>0</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>false</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 15:24:35 -0400</PostedAt>
</NewsItem>

<NewsItem contentIssues="false" id="44279" important="false" status="posted" url="https://my3.my.umbc.edu/posts/44279">
<Title>Office hours - Commons Drive!!</Title>
<Body>
<![CDATA[
    <div class="html-content">
    <div>Attention Team Study Groups!</div>
    <div><br></div>If you missed my office hours today, do not worry, you can stop by to see me on Monday!  I will be holding office hours<strong> Monday, 5/5,</strong> in the Commons from<strong> 11am - 1:00pm</strong>. <div><br></div>
    <div>Stop by to register your current study groups (<u><em><strong>ANY STUDY GROUP</strong></em></u> that you have been involved with during the Spring 2014 semester), receive help finding study groups, or give me updates.<div>
    <div><br></div>
    <div>Hope to see you there!</div>
    <div><br></div>
    <div>Dr. Felix</div>
    </div>
    </div>
    </div>
]]>
</Body>
<Summary>Attention Team Study Groups!    If you missed my office hours today, do not worry, you can stop by to see me on Monday!  I will be holding office hours Monday, 5/5, in the Commons from 11am -...</Summary>
<TrackingUrl>https://my3.my.umbc.edu/api/v0/pixel/news/44279/guest@my.umbc.edu/a4b0caeed60baaf41999abf6edae6888/api/pixel</TrackingUrl>
<Group token="retired-635">iCubed Cohort 3: Team Study Groups</Group>
<GroupUrl>https://my3.my.umbc.edu/groups/retired-635</GroupUrl>
<AvatarUrl>https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/635/8e47b6819f70d10722612702859d8ae2/xsmall.png?1375732423</AvatarUrl>
<AvatarUrl size="original">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/635/8e47b6819f70d10722612702859d8ae2/original.png?1375732423</AvatarUrl>
<AvatarUrl size="xxlarge">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/635/8e47b6819f70d10722612702859d8ae2/xxlarge.png?1375732423</AvatarUrl>
<AvatarUrl size="xlarge">https://assets3-my.umbc.edu/system/shared/avatars/groups/000/000/635/8e47b6819f70d10722612702859d8ae2/xlarge.png?1375732423</AvatarUrl>
<AvatarUrl size="large">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/635/8e47b6819f70d10722612702859d8ae2/large.png?1375732423</AvatarUrl>
<AvatarUrl size="medium">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/635/8e47b6819f70d10722612702859d8ae2/medium.png?1375732423</AvatarUrl>
<AvatarUrl size="small">https://assets2-my.umbc.edu/system/shared/avatars/groups/000/000/635/8e47b6819f70d10722612702859d8ae2/small.png?1375732423</AvatarUrl>
<AvatarUrl size="xsmall">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/635/8e47b6819f70d10722612702859d8ae2/xsmall.png?1375732423</AvatarUrl>
<AvatarUrl size="xxsmall">https://assets4-my.umbc.edu/system/shared/avatars/groups/000/000/635/8e47b6819f70d10722612702859d8ae2/xxsmall.png?1375732423</AvatarUrl>
<Sponsor>iCubed Cohort 3: Team Study Groups</Sponsor>
<PawCount>0</PawCount>
<CommentCount>0</CommentCount>
<CommentsAllowed>true</CommentsAllowed>
<PostedAt>Fri, 02 May 2014 15:15:08 -0400</PostedAt>
</NewsItem>

</News>
