• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Ugly code
 

Ugly code

on

  • 876 views

 

Statistics

Views

Total Views
876
Views on SlideShare
816
Embed Views
60

Actions

Likes
0
Downloads
12
Comments
0

4 Embeds 60

http://agiletourchina.agilewizard.org 51
http://2010.agiletourchina.org 7
http://agilewizard.com 1
http://agiletourchina.rubybear.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Ugly code Ugly code Presentation Transcript

    •  yzheng@thoughtworks.com
    • 
    • 
    • 
    • char* servNumber;XString domain;db->getParameter(”domain", domain);if (0 == strcmp(domain.getData(), "")) { domain.setData(servNumber);} else { XString tmpValue; XString tmpServnumber; tmpServnumber.setData(servNumber); tmpValue = tmpServnumber + domain; domain.setData(tmpValue.getData());}
    • 
    • XString& servNumber;XString domain;db->getParameter(”domain", domain);domain = servNumber + domain;
    • 
    • 
    • if (1 == insertFlag) { if (1 == insertFlag) { retList.insert(i, newCatalog); retList.insert(m, newCatalog);} else { } else { retList.add(newCatalog); retList.add(newCatalog);}! } !if (1 == insertFlag) { retList.insert(j, newPrivNode);} else { retList.add(newPrivNode);}!
    • if ( "" != *OPRNUMB) { para.insert("OPRNUMB", OPRNUMB->getData());}if ( "" != *MSISDN) { para.insert("TELNUM", MSISDN->getData());}if ( "" != *TMSISDN) { para.insert("TMSISDN", TMSISDN->getData());}!
    • 
    • if ( strcmp(type, “DropGroup") == 0 || strcmp(type, "CancelUserGroup") == 0 || strcmp(type, "QFUserGroup") == 0 || strcmp(type, "CancelQFUserGroup") == 0 || strcmp(type, "QZUserGroup") == 0 || strcmp(type, "CancelQZUserGroup") == 0 || strcmp(type, "SQUserGroup") == 0 || strcmp(type, "CancelSQUserGroup") == 0 || strcmp(type, “UseGroup") == 0 || strcmp(type, "CancelGroup") == 0) 
    • 
    • if if (0 == retCode) { SendMsg("000", "Process Success", outResult);} else { SendMsg("000", "Process Failure", outResult);}const char* msg = (0 == retCode ? "Process Success" : "Process Failure");SendMsg("000", msg, outResult);
    • if(!strcmp(pRec->GetType(), RECTYPE::INSTALL)) { CommDM.ChangGroupInfo( const_cast(CommDM.GetAttr("IPAddress", &(pGroup->m_Attr))), true);} else { CommDM.ChangGroupInfo( const_cast(CommDM.GetAttr("IPAddress", &(pGroup->m_Attr))), false);}
    • 
    • switch(firstChar) {case ‘N’: nextFirstChar = ‘O’; break;case ‘O’: switch(firstChar) { nextFirstChar = ‘P’; case ‘N’: break; case ‘O’:case ‘P’: case ‘P’: nextFirstChar = ‘Q’; case ‘Q’: break; case ‘R’:case ‘Q’: nextFirstChar = firstChar + 1; nextFirstChar = ‘R’; break; break; case ‘T’:case ‘R’: throw IllegalArgumentException(); nextFirstChar = ‘S’; default: break; }!case ‘S’: nextFirstChar = ‘T’; break;case ‘T’: throw IllegalArgumentException();default:}
    • if (firstChar >= ‘N’ && firstChar <= ‘S”) { nextFirstChar = firstChar + 1;} else { throw IllegalArgumentException();}!
    • 
    • void processService(const char *oprCode, const char *subID, const char *oID, XList *callCicsList) { Xstring relaPri(“NULL”);  Xstring relaSec(“NULL”);  Xstring scoutBySec(“0”);  XList *tempList = new Xlist; callCicsList->add(tempList); tempList->add(new XString(oprCode));  tempList->add(new XString(oID));  XString *psTelNum = new XString; tempList->add(psTelNum);  GetServnumberBySubsID(subID, *psTelNum); tempList->add(new CEntityString(esRelaPri.GetData()));  tempList->add(new CEntityString(esRelaSec.GetData()));  tempList->add(new CEntityString(esScoutBySec.GetData())); }!
    • 
    • ColdRule *newRule = new ColdRule();newRule->SetOID(oldRule->GetOID());newRule->SetRegion(oldRule->GetRegion());newRule->SetRebateRuleID(oldRule->GetRebateRuleID());newRule->SetBeginCycle(oldRule->GetBeginCycle() + 1);newRule->SetEndCycle(oldRule->GetEndCycle());newRule->SetMainAcctAmount(oldRule->GetMainAcctAmount());newRule->SetGiftAcctAmount(oldRule->GetGiftAcctAmount());newRule->SetValidDays(0);newRule->SetGiftAcct(oldRule->GetGiftAcct());rules->Add(newRule);
    • ColdRule* CreateNewRule(ColdRule& oldRule) { ColdRule *newRule = new ColdRule(); newRule->SetOID(oldRule.GetOID()); newRule->SetRegion(oldRule.GetRegion()); newRule->SetRebateRuleID(oldRule.GetRebateRuleID()); newRule->SetBeginCycle(oldRule.GetBeginCycle() + 1); newRule->SetEndCycle(oldRule.GetEndCycle()); newRule->SetMainAcctAmount(oldRule.GetMainAcctAmount()); newRule->SetGiftAcctAmount(oldRule.GetGiftAcctAmount()); newRule->SetValidDays(0); newRule->SetGiftAcct(oldRule.GetGiftAcct()); return newRule}rules->Add(CreateNewRule(*oldRule));
    • 
    • return boolint RecComm::setIDBySevNum(const CEntityString& servnumber ) { DB db; db.setSQL("select id from users where servnumber=:servnumber"); db.bind(":servnumber", servnumber.c_str()); db.open(); if (!db.next()) { return -1; } setID(db.getString(”id")); return 0;}!
    • reference void Opcode::notifyCRM(const char * prodid, const char * paramid, CEntityString * retparam) { if (NULL == prodid || NULL == paramid || NULL == retparam) { throw IllegalArgumentsException ( Error::GetErrorMsg(”880022", "Opcode::notifyCRM")); } …}!
    •    
    • 
    • •  •  •  •  if/while/for •  •  •  
    • •  •  Effective XX 
    • http://dreamhead.blogbus.com/tag/ /http://www.infoq.com/cn/ugly-code
    • 
    • 
    •