RefactoringGroup 1
 Bad Smells in Code Building Tests Composing Methods   Confidential          2
Bad Smells in CodeWho          What            WhenWhere        Why             How              Confidential          3
Confidential   4
…..<app key=“ContactEmailAddress” value=“jdoe@initrode.com” />…..                                             app.config (...
// I decided not to use built-in feature to                                                                     convert st...
// Translates Roman Numbers to                                                           Decimal NumbersFunction GetNewGui...
function checkdata() {  dataok = true;  t1 = document.forms.signup.firstName.value;  t2 = document.forms.signup.lastName.v...
// Self-document codeprivate bool TrueBecauseThisEventDoesNotRegistrictBasedUponActivityType(){  return true;}private bool...
# Find the last 200 transactions    logging.debug( "Finding the last 600 transactions" )    ConnMysql.query("select Id fro...
 Bad Smells in Code   Building Tests Composing Methods   Confidential        11
Self-testing Code      Confidential   12
Without Self-testing CodeDeveloper jobs Fix bugs   Others                     Confidential   13
 Bad Smells in Code Building Tests   Composing Methods   Confidential        14
Catalog of RefactoringsComposing Methods Simplifying ConditionalMoving Features    Expressions Between Objects   Makin...
Inline Method  Extract Method                           Substitute AlgorithmReplace Temp with Query           Inline Temp ...
THANK YOU
Upcoming SlideShare
Loading in...5
×

Refactoring group 1 - chapter 3,4,6

200

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
200
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Who is it about?  other presentsWhat happened?  other presentsWhen did it take place?Where did it take place?  computerWhy did it happen?  other presentsHow did it happen?  other presentsGive audience some real example indications that there is trouble that can be solved by a refactoringhttp://thedailywtf.com/Articles/FAIL-FAIL,FAIL-FAIL,FAIL-FAIL-and-More.aspxhttp://thedailywtf.com/Comments/The-Bit-Setter.aspxhttp://thedailywtf.com/Comments/Mybad.aspxhttp://thedailywtf.com/Articles/Self-Documenting.aspxhttp://thedailywtf.com/Articles/Roman-Enumeration.aspx
  • Add a Hungarian Notation prefix to a configuration file setting, in case we weren&apos;t sure that &apos;ContactEmailAddress&apos; was a string
  • This is to convert a string to false value and don’t want to use built-in language feature
  • self-document code 
  • what the link between the 3 numbers is
  • Vaccine is kind of alike to self-testing code. It operates the system (virus) on real environment (body) in safe manner so that issues can be found at very soon
  • Some time is spent figuring out what ought to be going on, some time is spent designing, but most time is spent debugging. Fixing the bug is usually pretty quick, but finding it is a nightmare
  • Sample coffee script to demonstrate : extract method, introduce explaining variable, replace temp with queryStoryBoard = require &apos;./storyboard&apos;Constants = require &apos;./core/Constants&apos;class ViewerScreen extends GameScreenplayerMovesInChineseChess: (response) -&gt; if response.group == Global.GROUP.CHINESE_CHESS and response.type == Global.TYPE.PLAYER_MOVES_IN_CHINESE_CHESS_TABLE if response.code == Global.CODE.BROADCASTING_REQUEST if response.data.player == Constants.HOST_ROLE @view.startTopTimer() @view.stopBottomTimer() else response.data.player == Constants.GUEST_ROLE @view.stopTopTimer() @view.startBottomTimer()killChineseChess: (response) -&gt; if response.group == Global.GROUP.CHINESE_CHESS and response.type == Global.TYPE.KILL_CHINESE_CHESS_TABLE if response.code == Global.CODE.BROADCASTING_REQUEST data = response.data if @match.status &lt; Global.GAME_STATUS.PLAYING @msgBar.showdata.username + &apos; &apos; + Global.MUI.HAS_QUITEDhostKicksGuestOutOfChineseChess : (response) -&gt; if response.group == Global.GROUP.CHINESE_CHESS and response.type == Global.TYPE.KICKS_GUEST_OUT_OF_CHINESE_CHESS_TABLE if response.code == Global.CODE.BROADCASTING_REQUEST data = response.data @msgBar.show @match.host.username + &apos; &apos; + Global.MUI.KICKS + &apos; &apos; + @match.guest.usernamedetailsOfTableCallback: (response) -&gt; if response.group == Global.GROUP.CHINESE_CHESS and response.type == Global.TYPE.GET_DETAILS_OF_CHINESE_CHESS_TABLE if response.code == Global.CODE.SUCCESSFUL_REQUEST data = response.data if @match.status &gt;= Global.GAME_STATUS.WAITING then# ... else if response.code == Global.CODE.FAILED_REQUEST# ...
  • Refactoring group 1 - chapter 3,4,6

    1. 1. RefactoringGroup 1
    2. 2.  Bad Smells in Code Building Tests Composing Methods Confidential 2
    3. 3. Bad Smells in CodeWho What WhenWhere Why How Confidential 3
    4. 4. Confidential 4
    5. 5. …..<app key=“ContactEmailAddress” value=“jdoe@initrode.com” />….. app.config (revision 1)…..<app key=“sContactEmailAddress” value=“jdoe@initrode.com” />….. app.config (revision 2) Confidential 5
    6. 6. // I decided not to use built-in feature to convert string to boolean if ( is_string($switch) ) { switch ($switch) { Public Function Save() As Boolean case false : Try case down : SaveMeeting() case off : Catch ex As Exception case not : Throw ex case 0 : End Try case : End Function $switch = false; break; default : $switch = true; break; } }<a href="/the/path/to/the/url"onclick="window.open(this.getAttribute(href),_blank);return false;"> link text</a> Confidential 6
    7. 7. // Translates Roman Numbers to Decimal NumbersFunction GetNewGuid() public string rom2num(string r) Dim cnGuid, rsGuid { if (r == "I") return "1"; Set cnGuid = CreateObject("ADODB.Connection") if (r == "II") return "2"; Set rsGuid = CreateObject("ADODB.Recordset") if (r == "III") return "3"; if (r == "IV") return "4"; cnGuid.Open = _ if (r == "V") return "5"; "Provider=SQLOLEDB.1;" + if (r == "VI") return "6"; "Data Source=<production server>; " + if (r == "VII") return "7"; "Initial Catalog=<production DB> " + if (r == "VIII") return "8"; "user id = ********;" + if (r == "IX") return "9"; "password=*********"" // // Snipped LOTS of "code" here rsGuid.Open "SELECT newid() as Guid", cnGuid // if (r == "MMVIII") return "2008"; If Not rsGuid.EOF Then if (r == "MMIX") return "2009"; GetNewGuid = rsGuid("Guid").Value if (r == "MMX") return "2010"; End If if (r == "MMXI") return "2011";End Function return "E"; } Confidential 7
    8. 8. function checkdata() { dataok = true; t1 = document.forms.signup.firstName.value; t2 = document.forms.signup.lastName.value; t9 = document.forms.signup.locale.options.selectedIndex; t10 = document.forms.signup.currency.options.selectedIndex; t11 = document.forms.signup.timezone.options.selectedIndex; t12 = document.forms.signup.packetType.options.selectedIndex; t13 = document.forms.signup.captcha_code.value; if (t1 == || t2 == „ ) { alert("Please fill-up all the fields"); dataok = false; return(dataok);} if (t4 != t5) { alert("Please enter the password again"); dataok = false; return(dataok);} if (t9 == 0) { alert("Please select a locale"); dataok = false; return(dataok);} if (t10 == 0) { alert("Please select a currency"); dataok = false; return(dataok);} return(dataok);} Confidential 8
    9. 9. // Self-document codeprivate bool TrueBecauseThisEventDoesNotRegistrictBasedUponActivityType(){ return true;}private bool FalseBecauseNoActivityTypesAreAvailableForUsersWhoAreNotLoggedIn(){ return false;}private bool NoActivityTypesAreAttachedToThisEvent(IEnumerable<ActivityType>activityTypes){ return activityTypes.Any() == false;} Confidential 9
    10. 10. # Find the last 200 transactions logging.debug( "Finding the last 600 transactions" ) ConnMysql.query("select Id from Transactions order by ts desc limit 0,10000 ")private void EditTDemensions(bool blnYes){ //bln is the introvert of blnYes bool bln = (blnYes ? false : true); //Display or Hide buttons btnDemensionsEdit.Visible = bln; btnDemensionsSave.Visible = blnYes; btnDemensionsCancel.Visible = blnYes;} Confidential 10
    11. 11.  Bad Smells in Code  Building Tests Composing Methods Confidential 11
    12. 12. Self-testing Code Confidential 12
    13. 13. Without Self-testing CodeDeveloper jobs Fix bugs Others Confidential 13
    14. 14.  Bad Smells in Code Building Tests  Composing Methods Confidential 14
    15. 15. Catalog of RefactoringsComposing Methods Simplifying ConditionalMoving Features Expressions Between Objects Making Method CallsOrganizing Data Simpler Dealing with Generalization Confidential 15
    16. 16. Inline Method Extract Method Substitute AlgorithmReplace Temp with Query Inline Temp Introduce Explaining Variable Replace Method with Method Object Split Temporary VariableRemove Assignments to Parameters Confidential 16
    17. 17. THANK YOU
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×