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
class Auto { | |
constructor(motor) { | |
this.motor = motor | |
} | |
// 1. Identify methods that receive owned attributes | |
startEngine() { | |
// 2. Remove those parameters from the method signature | |
// 4. Rename the method if needed to match the new intention | |
this.motor.ignite() |
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
class Auto { | |
constructor(motor) { | |
this.motor = motor | |
} | |
startEngine(motor) { | |
motor.ignite() | |
} | |
} |
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
import pytz | |
from datetime import datetime, timedelta | |
from dateutil.relativedelta import relativedelta | |
from zoneinfo import ZoneInfo | |
class TimeHandler: | |
def __init__(self, timezone='UTC'): | |
self.timezone = ZoneInfo(timezone) | |
def add_business_days(self, start_date, days): |
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
from datetime import datetime, timedelta | |
class TimeCalculator: | |
def add_business_days(self, start_date, days): | |
# Assumes every day has 24 hours | |
result = start_date | |
for _ in range(days): | |
result += timedelta(days=1) | |
# Skip weekends | |
while result.weekday() >= 5: |
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
def calculate_starship_trajectory(initial_velocity, fuel_mass, | |
burn_rate, gravity=9.81): | |
THRUST_EFFICIENCY = 0.85 | |
burn_time = fuel_mass / burn_rate | |
delta_v = gravity * burn_time * THRUST_EFFICIENCY | |
# You replace the magic number | |
final_velocity = initial_velocity + delta_v |
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
def calculate_starship_trajectory(initial_velocity, fuel_mass, | |
burn_rate, gravity=9.81): | |
""" | |
See explanation at | |
https://claude.ai/share/5769fdd1-46e3-40f4-b9c6-49efbee93b90 | |
""" | |
# AI suggested this approach | |
burn_time = fuel_mass / burn_rate |
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 class ServiceControlPolicy { | |
private SpannerDatabase spannerDB; | |
private QuotaManager quotaManager; | |
public void applyPolicyChange(PolicyChange change) { | |
if (change == null) { | |
// Assuming it comes from an external API | |
// Beyond your control | |
change = new NullPolicyChange(); | |
} |
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 class ServiceControlPolicy { | |
private SpannerDatabase spannerDB; | |
private QuotaManager quotaManager; | |
public void applyPolicyChange(PolicyChange change) { | |
// NULL POINTER: change can be null | |
Policy policy = spannerDB.getPolicy(change.getPolicyId()); | |
// NULL POINTER: policy can be null from the database | |
String quotaField = policy.getQuotaField(); | |
// NULL POINTER: quotaField can be null (blank field) |
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
def find_minimum_price(products): | |
min_price = float('inf') | |
for product in products: | |
if product.price < min_price: | |
# This is an essential IF, you should not remove it | |
min_price = product.price | |
# No accidental IF here (if min_price is None:) | |
return min_price if min_price != float('inf') else None |
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
def find_minimum_price(products): | |
min_price = None | |
for product in products: | |
if min_price is None: | |
min_price = product.price | |
elif product.price < min_price: | |
min_price = product.price | |
return min_price |
NewerOlder