Ugly code

753 views
715 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
753
On SlideShare
0
From Embeds
0
Number of Embeds
62
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ugly code

  1. 1.  yzheng@thoughtworks.com
  2. 2. 
  3. 3. 
  4. 4. 
  5. 5. 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());}
  6. 6. 
  7. 7. XString& servNumber;XString domain;db->getParameter(”domain", domain);domain = servNumber + domain;
  8. 8. 
  9. 9. 
  10. 10. 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);}!
  11. 11. if ( "" != *OPRNUMB) { para.insert("OPRNUMB", OPRNUMB->getData());}if ( "" != *MSISDN) { para.insert("TELNUM", MSISDN->getData());}if ( "" != *TMSISDN) { para.insert("TMSISDN", TMSISDN->getData());}!
  12. 12. 
  13. 13. 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) 
  14. 14. 
  15. 15. 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);
  16. 16. 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);}
  17. 17. 
  18. 18. 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:}
  19. 19. if (firstChar >= ‘N’ && firstChar <= ‘S”) { nextFirstChar = firstChar + 1;} else { throw IllegalArgumentException();}!
  20. 20. 
  21. 21. 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())); }!
  22. 22. 
  23. 23. 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);
  24. 24. 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));
  25. 25. 
  26. 26. 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;}!
  27. 27. 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")); } …}!
  28. 28.    
  29. 29. 
  30. 30. •  •  •  •  if/while/for •  •  •  
  31. 31. •  •  Effective XX 
  32. 32. http://dreamhead.blogbus.com/tag/ /http://www.infoq.com/cn/ugly-code
  33. 33. 
  34. 34. 
  35. 35. 

×