Your SlideShare is downloading. ×
Refactoring   group 1 - chapter 3,4,6
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Refactoring group 1 - chapter 3,4,6

164
views

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
164
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
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't sure that 'ContactEmailAddress' 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 './storyboard'Constants = require './core/Constants'class ViewerScreen extends GameScreenplayerMovesInChineseChess: (response) -> 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) -> 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 < Global.GAME_STATUS.PLAYING @msgBar.showdata.username + ' ' + Global.MUI.HAS_QUITEDhostKicksGuestOutOfChineseChess : (response) -> 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 + ' ' + Global.MUI.KICKS + ' ' + @match.guest.usernamedetailsOfTableCallback: (response) -> 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 >= Global.GAME_STATUS.WAITING then# ... else if response.code == Global.CODE.FAILED_REQUEST# ...
  • Transcript

    • 1. RefactoringGroup 1
    • 2.  Bad Smells in Code Building Tests Composing Methods Confidential 2
    • 3. Bad Smells in CodeWho What WhenWhere Why How Confidential 3
    • 4. Confidential 4
    • 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. // 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. // 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. 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. // 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. # 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.  Bad Smells in Code  Building Tests Composing Methods Confidential 11
    • 12. Self-testing Code Confidential 12
    • 13. Without Self-testing CodeDeveloper jobs Fix bugs Others Confidential 13
    • 14.  Bad Smells in Code Building Tests  Composing Methods Confidential 14
    • 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. 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. THANK YOU