Skip to content

Instantly share code, notes, and snippets.

// From Ayush Jindal's exercises for code smells https://github.com/ayjindal/CodeSmells
class Customer {
private readonly name: string;
private readonly currentAddress: Address;
constructor(name: string, address: Address) {
this.name = name;
this.currentAddress = address;
}
// From Code Smells – Part II, Ana Nogal https://www.ananogal.com/blog/code-smells-part-two/
enum EmployeeType {
Worker,
Supervisor,
Manager
}
class Employee {
private readonly salary: number;
// Adapted from Code Smell: Null Check, Joe Eames https://medium.com/thinkster-io/code-smell-null-check-a0c4851fafbf
const DEFAULT_DISCOUNT: number = 1.0;
class DiscountCalculator {
private customerRepository: CustomerRepository;
constructor(customerRepository: CustomerRepository) {
this.customerRepository = customerRepository;
}
// From Fixing Object oriented abusers, Manh Phan https://ducmanhphan.github.io/2020-01-24-Fixing-object-oriented-abusers/
class CheckoutHandlder {
// ...
convertToCurrency(price: number, currencyTo: string): number {
if (currencyTo === "EUR") {
return price * 0.9;
} else if (currencyTo === "CAD") {
return price * 1.35;
} else {
@trikitrok
trikitrok / working_effectively_with_legacy_code.md
Created November 28, 2022 17:07 — forked from jonnyjava/working_effectively_with_legacy_code.md
Working effectively with legacy code summary

WORKING EFFECTIVELY WITH LEGACY CODE

To me, legacy code is simply code without tests. I’ve gotten some grief for this definition. What do tests have to do with whether code is bad? To me, the answer is straightforward, and it is a point that I elaborate throughout the book: Code without tests is bad code. It doesn’t matter how well written it is; it doesn’t matter how pretty or object-oriented or well-encapsulated it is. With tests, we can change the behavior of our code quickly and verifiably. Without them, we really don’t know if our code is getting better or worse.

Chapter 1 Changing Software

Four Reasons to Change Software: For simplicity’s sake, let’s look at four primary reasons to change software.

export class Rover {
// some code
execute(command) {
if (command === 'l' || command === 'r') {
if (this.direction === "N") {
if (command === 'r') {
this.direction = "E";
} else {
this.direction = "W";
import {UnusualSpendingDetector} from "../src/UnusualSpendingDetector";
import {stub} from "./PaymentsRepositoryHelper";
describe('UnusualSpendingDetector', () => {
const currentMonth = '2020-02';
const previousMonth = '2020-01';
const userId = '1234';
let paymentsRepository;
let detector;
let knowingThat;
import {when} from "jest-when";
export function stub(paymentsRepository) {
const monthPaymentsBuilder = {
inMonth: inMonth
};
return knowingThat;
function knowingThat() {
import {UnusualSpendingDetector} from "../src/UnusualSpendingDetector";
import {when} from 'jest-when'
describe('UnusualSpendingDetector', () => {
const currentMonth = '2020-02';
const previousMonth = '2020-01';
const userId = '1234';
let paymentsRepository;
let detector;
import {UnusualSpendingDetector} from "../src/UnusualSpendingDetector";
describe('UnusualSpendingDetector', () => {
const currentMonth = '2020-02';
const previousMonth = '2020-01';
const userId = '1234';
let paymentsRepository;
let detector;
beforeEach(() => {