Skip to content

Instantly share code, notes, and snippets.

@benj2240
benj2240 / OneHundredPlusTips.md
Last active December 3, 2021 20:23
100+ tips from Clean Code, as summarized by Tyler Hawkins, with snarky commentary from Ben.

This list of tips taken from Tyler Hawkins' post on dev.to, which took them from Robert C Martin's Clean Code.

My thoughts are in italics after each tip.

  1. The total cost of owning a mess compounds over time. Agree!
  2. It’s very difficult to rebuild a legacy system from the ground up. Refactoring and incremental improvements are often the better path to take. Agree, for large systems. For smaller systems (eg a single page, or even a single application), a big-bang rewrite is often the simpler, cheaper approach.
  3. In messy codebases it can take days or weeks to accomplish tasks that should only take hours. Agree!
  4. Take the time to go fast. What does this mean, Bob?
  5. Clean code does one thing well. Bad code tries to do too much. Can simple code doing two things be "Clean" ( eg: { SetDefaults(ref foo); Save(foo); })? Can complex code for one simple task be "Bad"?
  6. Clean code is well-tested.
@benj2240
benj2240 / Scrummary.md
Created August 25, 2021 21:09
An unofficial summary of the 2020 Scrum Guide

The 2020 Scrummary

The Scrum Guide

The Scrum Guide was first published in 2010. It defines core Scrum: "Scrum and X" is still Scrum, but "Scrum without X" is not, and may limit or even remove the benefits of Scrum.

Scrum Definition

Scrum is a process that tries to make work predictable and safe. It reveals inefficiencies and problems, so you can adjust.

I don't need Inversion of Control

Example: Web API

In my experience, discussions on this topic can easily get out of hand with abstract language and technical jargon. So I will anchor this discussion with an example webservice.

Let's say I have an API with CRUD endpoints, that saves objects down to a database. If this API is simple enough, I might not bother with fancy designs or tests at all... so let's say that there's some business logic on the update, where if an object is updated in a certain way, we'll reject the update and email an administrator.

Then, the core / only interesting part of this service is this function:

@benj2240
benj2240 / StopIt.md
Last active September 14, 2022 22:07

Stop writing code that way.

Stop putting comment headers in code files.

  • They don't help.
    • I already know what the file is named. I'm looking at it.
    • I already know where the file is stored. I'm looking at it.
    • If I need to know who wrote it originally, I can look that up.
    • If I need to know who has changed it, I can look that up.
  • They can hurt.

Don't write reusable code

Disclaimer: If you are the author of a language, or a library with thousands of happy developers using your code to build cool stuff, then this advice does not apply to you. If you are a line-of business programmer, working at a company whose primary product is not its own technology, then it definitely does.

Why not write reusable code?

Why shouldn't you write reusable code? Because you're not good at it. Or, more

@benj2240
benj2240 / Option A
Created October 27, 2014 15:31
Weekend Dodging
SELECT ProjectedDate = DATEADD( DAY
,CASE(DATEPART(WEEKDAY, DATEADD(DAY, Margin, BaseDate)))
WHEN 7 THEN -1 -- Go back 1 day from Saturday
WHEN 1 THEN 1 -- Go forward 1 day from Sunday
ELSE 0 -- Weekdays stay as-is
END
,DATEADD(DAY, Margin, BaseDate)
)
FROM BaseDates
JOIN ProjectionMargins
@benj2240
benj2240 / Labyrinth_clean.rb
Created August 17, 2014 20:23
Labyrinth solutions
require 'set'
# Extending the nifty SortedSet class
# (which isapparently implemented as a red-black tree)
# I want to be able to treat it as a priority queue,
# and shift elements off the front
class SortedSet
def shift
return nil if self.empty?
element = self.first
File.open(ARGV[0]).each_line do |line|
# expression to pull positive or negative ints out of the input line
# expects "(x, y) (a, b)"
regex = /\((?<x>\-?\d+), (?<y>\-?\d+)\) \((?<a>\-?\d+), (?<b>\-?\d+)\)/
input = regex.match(line.strip)
# pull variables out of match data; cast them from string to int
x,y,a,b = ["x","y","a","b"].map{|var| input[var].to_i}
# print integer distance