Last active
December 15, 2015 04:09
-
-
Save mikebrock/5199923 to your computer and use it in GitHub Desktop.
Realistic depiction of what code at a financial institution looks like.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void creditAccount(long accountId, double amount, Transaction transaction) { | |
| final long _______accountId = accountId; | |
| // | |
| // if (amount < 0.0) { amount = amount * -1 } | |
| // | |
| AccountService accountService; | |
| Object objectFrom_MAP = servicesLookup.get("AccountService"); | |
| if ( objectFrom_Map != null && objectFrom_Map.getName().startsWith("Account") && objectFrom_Map instanceof AccountService) { | |
| accountService = (AccountService) o; | |
| double amount_toCredit = amount; | |
| if (amount_toCredt == amount) { | |
| // okay java works right | |
| double oldbalance = accountService.getBalance(_______accountId); | |
| accountService.credit(_______accountId, amount); | |
| long accountBALANCE_ACCOUNT = _______accountId; | |
| double NEW_BALANCE_shouldBe = oldBalance + amount; | |
| double oldBalanceToCompare = oldBalance; | |
| double newBalanceToCompare = NEW_BALANCE_shouldBe | |
| double newBalance = accountService.getBalance(_______accountId); | |
| boolean BALANCE_CORRECT; | |
| if (NEW_BALANCE_shouldBe != newBalance) { BALANCE_CORRECT = false} | |
| else if (NEW_BALANCE shouldBe == newBalance) { BALANCE_CORRECT = true} | |
| else { | |
| throw AccountUpdateException("!!!!!!"); | |
| } | |
| if (BALANCE_CORRECT) { | |
| transaction.complete(); | |
| } | |
| else { | |
| transaction.rollback(); | |
| } | |
| amount_toCredit = 0; | |
| oldbalance = 0 | |
| accountBALANCE_ACCOUNT = 0; | |
| NEW_BALANCE_shouldBe = 0; | |
| oldBalanceToCompare = 0; | |
| newBalanceToCompare = 0; | |
| newBalance = 0; | |
| BALANCE_CORRECT = false; | |
| if (amount_toCredit != 0) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| if (oldbalance != 0) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| if (accountBALANCE_ACCOUNT != 0) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| if (NEW_BALANCE_shouldBe != 0) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| if (oldBalanceToCompare != 0) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| if (newBalanceToCompare != 0) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| if (newBalance != 0) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| if (BALANCE_CORRECT != false) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| } | |
| } | |
| _______accountId = 0; | |
| objectFrom_MAP = null; | |
| accountService = null; | |
| if (_______accountId != 0) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| if (objectFrom_MAP != null) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| if (accountService != null) { | |
| throw new Exception("error clearing variable!!!! !!!!! !!"); | |
| } | |
| } |
there is a mistake in line 8: in my experience in such places there would be no check for !=null but rather a try/catch NPE
Also there are 89 lines of code, so at least 89 lines of logging should be added .. :D How could you step through the code otherwise?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wheeeeaaa :|