The Skeptical Methodologist

Software, Rants and Management

Stop with the Big O Problems : You are not a Leet Coder

Big O (sometimes called Big Oh notation) is a mathematical analysis of algorithmic performance as the size of the dataset increases. It’s taught in undergrad Computer Science courses usually while comparing the performance of different sorting algorithms or different tree like data structures.

It’s also commonly used as the underlying ‘test’ in many company’s code challenges. The excuse used to focus on the nature of Big O performance is that these companies believe they write high performance code, and that the foundation of high performance code is Big O notation, ergo, they need to test all of their candidates for it.

We Want the Best Coders

The real reason companies test for Big O notation, however, is two fold. One, they have no idea what to hire for, and they’ve found that segmenting out their candidates based on how well they know Big O notation seems as good as a way to segment as anything else, and they also like saying they’ll hire anyone but secretly only hiring college grads.

If an algorithmic challenge is part of your hiring process, you’re almost certainly biasing your results to college grads, and let me remind you, having a college degree is NOT PREDICTIVE ON PROGRAMMING ABILITY OR SKILL.

So, you’re wasting effort applying a segmentation to your candidate stream that provides NO PREDICTIVE VALUE. Why would you do all that work? Why are you asking your candidates to do all that work – as these challenges are often hard?

Well, that’s kind of the second thing you’re selecting for. How hard did they study for the challenge? The unspoken rule with any algorithmic challenge is that they can be trained and ‘grinded’ for using tools like HackerRank and Leetcoder. There you can both get the challenges themselves, attempt your answer, and see others ‘right’ answers so you can memorize them.

But We Get the People Most Willing to Mindlessly Grind Without Complaint

This makes any hiring process that uses these kinds of candidate challenges implicit “how much do you want it?” sorts of affairs. Candidate selection is far less about coding ability and far more “how much did you grind”? Unfortunately, by only allowing candidates that were ‘hungry’ to get in past your hiring process, all you’ve hired is a bunch of folks who think you’re the best place to work before they’ve even got in.

Note, generally, you want to be the best place to work because of your culture, practices, and compensation. But yeah, you can totally cheat and only hire people who’ve already showed they were willing to work for free just to get in your doors for weeks and weeks doing arbitrary ‘programming-like’ exercises.

So you may think you’ve set out to get good coders – not only that, good coders who know about performance, because you’ve told yourself and anyone who will listen that at your company you solve “hard problems” that are very “performance intensive”. But what you’ve actually found is just a bunch of sycophants who aren’t going to challenge anything your company says or does. In fact, you may be one of those sycophants.

This is going to seriously undermine any attempts at innovation at your company.

What Real Performance Looks Like

I work in the programmatic advertising industry, often compared to high frequency trading. Do we use Big O notation to write highly performant code?

Yes. Once. In the last five years.

Anyone who actually works in the high performance computing space knows that Big O as concept isn’t something you’re going to need every day as a developer. This is for two reasons.

One, most algorithms have already been written using these best practices. Std::sort has already taken into account the best sorting algorithm for the general case, so eschewing std::sort and using something else is often a fool’s errand. Just use the built in tools that you have – in fact, the more you use built in and reusable tools, the more likely it is you’re already using many of the ‘best algorithms’ for the job in a Big O sense.

Second, and more importantly – Big O necessarily leaves out the constants. This means that the only thing Big O worries about is asymptotic performance over large data sets as it scales based on the size of that data set. This is only one factor of performance, and in many cases, the constants that you hit so widely wipe out any gains you get by using an algorithm that better scales with the size of the data set.

High performance computing cares about cache locality, pipelining and branch mis-predictions as much as it cares about Big O performance. It often is far more sensitive to sneaky system calls than anything else – meaning your fancy algorithm is shot because you accidentally did something that allocated memory.

What data structure should I use for my problem? A std::vector in 99% of cases. “But wouldn’t a tree be more performant for my use case?” No. Measure it. Seriously. Trees don’t outperform vectors until the hundreds of thousands of data entries because vectors have been so incredibly heavily optimized for cache locality and other factors.

So Never use Big O?

No, of course not. Big O is important. It’s just not important in most cases. What is the size of the data you are dealing with? If its not that large, its better to just build your algorithm off of off the shelf reusable parts since those parts are heavily tested and optimized to work pretty well in any general use case.

All performance questions don’t start with a mathematical proof of asymptotic performance, they start with the profiler.

Find your bottle necks. In most cases, your bottle necks are places in the code where very simple restructurings will work wonders. You may even find outright bugs where you’re sorting the same list again and again on accident.

Once you’ve done that so much that you’re genuinely hitting algorithms as your bottle neck, your next step is to see if there’s any off the shelf open source algorithms that do better than std::sort for your problem.

If you’ve exhausted that, and that’s going to happen very rarely, then and only then are you going to start parsing through white papers looking for better asymptotic performance.

Notice, I didn’t say you’re going to replace your vector with a tree, or anything else so basic. All those easy Big O optimizations have already been done for you. Only when you’ve reached the end of what you can easily find in the open source world are you going to really start looking at the most recent research and possibly implementing something from scratch.

And then you’re going to profile and measure again, just as you do after every single optimization you make because you can never guess well enough if the constants are going to eat your shiny new Big O algorithm’s lunch. In our case, it was a wash – the fancy algorithm wasn’t measurably faster than what we had. And since we were going to have to maintain the fancy algorithm, we dropped it and put the older, simpler algorithm back in.

We have one of the fastest systems on the planet in terms of what we do, and if we haven’t had to pay attention to Big O to write it, neither will most people.

I guarantee you, most algorithms written with Big O in mind have a print statement somewhere in there for “logging, you know, just in case” that end up either hitting the screen or the disk and shooting your performance in the foot. If you don’t understand how a single huge constant can dwarf whatever your asymptotic performance is – like writing to a database too frequently, reading or writing to a disk, or basically any IO or memory calls – then you’re not writing highly performant code. You’re just doing coding riddles and filling yourself with an unearned sense of entitlement that you are a ‘leet coder’.

September 29, 2020 Posted by | Uncategorized | Leave a comment

The Drafting Technique

This is a combination of a few techniques largely centered on actual coding, rather than more abstract design. The design may be better benefitted by an “Outlining” technique which I may discuss later.

Drafting combines pseudocode, acceptance test-driven development, automated refactoring, debugging-REPL and design by contract into a single system. While it can be thought of as a step by step system, once you get the hang of it, it really is about choosing what next technique makes sense given the problem you’re trying to solve.

Write a one-liner test

First, we’ll be writing all within a single file. This is if you’re maintaining a legacy system or doing something green field. We’re going to try to put as much in our single file as possible.

This may mean integrating your solution into legacy code comes later, but you’ll be integrating fleshed out modules and packages at that point that are all well tested.

You’re going to write a single line, it’s going to start with test_ something, and you’re going to have it print hello world.

Set up your IDE to run this test, that’s going to be our debugging target.

Keep your linter on and as hot as possible. Fix linting errors as they appear. Commit often and consider a WIP branch for folks to review as you go.

Then Pseudocode

You’re going to want to basically state your problem and your idealized solution in English, all within the comments of this test. You can use docstrings if you want, but comments may be better as these comments are going to get spread out.

Putting a single docstring at the top of your test that describes your overall goal your feature is smart if you can pull off a way to do it succinctly.

It’s best to learn the hotkey to commit to your branch and commit as often as possible, certainly at the end of a pseudocoding session is a good time, but if you need to take breaks as you try to capture as much of your design doc in the code, that’s fine too.

While some of these comments may be deleted in time, this commit will serve as a lighthouse you can later return to see the entire thought at once, and others can use to find your thinking when you put code together.

Rather than merely describing your solution, you’ll want to describe the entire problem and solution, because when we do the next step, we’ll need to know how to start putting together test data to represent your problem. Additionally, any time you think anything ought to be true – really, almost after any line – put a note in your comments. It may be as simple as

 

# Sort list
# assert list is sorted
...
​

Spin up the Debugger

Put a breakpoint on the first line – add a hello world if you need a line to execute, and spin up a debugger that can break into a REPL.

Now, you need to – in the REPL – do whatever the first logical line says needs to be done. Since we described our problem, it may be dedicated to putting together some canned data to drive the test forward.

Since we’re already in the REPL, it’s pretty easy to interact with our libraries and otherwise generate some canned data. We can use copy-paste to get this data into the file.

You may want to restart your REPL debugger multiple times to clear out local variables and smoke test what you’ve been writing so far to capture that first logical line.

When you’re done with the first line, move on to the next line by moving the breakpoint. The really nice thing about this debugging-REPL technique is you’ll get ALL of the state you have in your script at the point you run the REPL, so you don’t have to remember everything you’ve already instantiated or have done any complicated set up in your own REPL sessions to try something out.

REPL sessions are one of the best ways to explore APIs and try multiple things to get a line right, all with far faster cycle time than rerunning tests. Additionally, as you add tests, the debugger-REPL will execute them as well, and only get to your breakpoint if all the tests currently pass.

Ideally, use a debugging-REPL with code completion, like IPython’s or Jetbrain’s.

Refactor as you Go

When it makes sense to make something a method, make it a method. But don’t try to organize code until you start to see the solution emerge – the premature organization is going to slow you down. You actually want rough code coming out – the ‘simplest thing that can possibly work’ in your debugging-REPL sessions.

You may even want to keep the code rough for a while longer than that – so long as it works – as you go back into pseudocode to flesh out some extended behavior or off-nominal paths.

But as things emerge that seem elegant, extract methods and add them to classes and whatnot as you go. You don’t need to do this upfront, you want your solution to guide to as to what the code ought to look like.

When and where to refactor is largely something driven by experience – at the same time, so is the design you use to solve your problem. But I would not refactor too early, as you want to be able to see your entire solution in one go, as then and only then will certain patterns emerge.

Test and Contract as you go

While you’re putting in statements, one line at a time, there are all kinds of things you can assert at any time. Go nuts, think of as many assertions as you can. A stickler may be able to add one or more assertions per line of behavior actually written.

Are these tests? Are they contracts?

You can decide. Right now, in this primordial ooze, contracts and tests are going to look the same. Contracts may, in fact, be easier, since getting canned data may require a copy and paste, contracts may come easier as you’re able to simply assert that data is in a certain relation to other data.

If it’s a contract-like assertion, then that’s going to live inside a method in the future. If it is a test-like assertion, then we’re going to be refactoring that out into a test in the future.

Don’t get too far ahead of yourself

This technique will feel so fast at times that you’ll just want to keep coding – you’ll want to keep adding behavior and going back. Try, though, to be disciplined about when to branch things off.

If two features truly are independent, it may be better to get your Branch under peer review, spin up another branch, and go on with the new feature. Otherwise, it will become harder and hard to ‘keep it rough’ but also keep it all in your head.

This will be especially apparent when you want to ‘run past the end’, and add more behavior based on the results of your acceptance test, like you would anywhere else in the code using this method.

Try to avoid this, instead, start a brand new file with a brand new test that imports the code from the old file – run the behavior, get the output, and THEN start adding new assertions and behavior.

Technique: Grab Tests Data Using the Debugger

What you’re initially writing is an acceptance test – its a complete walk through the new feature using some expected canned inputs, ensuring you get expected outputs.

Pulling unit tests out of this is relatively easy using the REPL though since you can step through the code at any time, inspect a few variables, and copy and paste their state into the code as an assertion. These ‘assertions on the way’ on the state are good refactoring targets to turn into unit tests. And these refactoring targets also help you determine when and where your method boundaries ought to be as you try to break things up.

Technique: Use ‘Extract Method’ to pull unit tests out of your integration test

Using extract method twice – once on the behavior you want in a method, and second, on an assertion on the results of that method will allow the automated refactor to figure out all the dependencies on a certain line of code.

Setting a breakpoint at the top of that ‘test’ when its called allows you to use the copy-paste technique to remove these dependencies and rely on canned data.

Extracting an inline test is easy. Simply extract the method, the immediately call it right after.

This makes the generation of unit tests really easy once you already have an acceptance test. Once unit tests are easy to generate, it’s easy to more quickly run certain tests, as well as copy tests while changing certain defaults to test off-nominal behavior.

Technique: Todo’s embedded in the Code, and Groom in the Code

Brand new features or directions can be captured as Todos. We want to stay within the file as much as possible, keeping all of our notes there and at our fingers, all within context too.

As you go, it may make sense to ‘groom’ this implied backlog – while deciding what to do next, try to add more information to a TODO each time you see it. What approach might you take, how can the TODO be broken down, what questions need to be thought about?

This way as you groom, the easier TODOs get knocked out, while the harder ones get easier and easier, with a fresh mind in-between visits.

TODOs that aren’t worth doing at the time can later be removed into an actual task or story management backlog, but by now, you’ll have enough context for that to be worthwhile.

Always try to write as much of your thinking in a TODO you make as possible. You won’t be reviewing these things for some time, and simple todos like ‘fix this’ aren’t going to help your future self. In the TODO, describe what’s wrong, and possible ideas of how to fix it, if possible.

Discussion: Line length issues Before Move refactors?

If you try to keep everything in a single test, and your linter has line length expectations, you’re going to get a lot of red flags.

You can either use this as an excuse to move certain embedded functions and such out of the code, basically using the linter as a siren on too much complexity. Or you can turn that check off for now, and turn it back in when you decide to move things out.

Stretch: Live coding or video record the session

I have not tried this technique, but I think it’d be a way to both improve your own thinking as well as improve the design and peer reviews. But consider each session a live coding session – try to narrate what you’re doing as you do it, as a way to catch easy issues by having the video be a rubber duck.

The sessions can serve as async pair programming sessions for others, and can also be archived, again, into pseudo-perfect documentation of exactly what went into each commit and why.

Pull everything apart

The final step, when the code works and you’ve got it well structured, is to start pulling it apart. Now is the time to decide where everything lives, and package all this code into clean modules and packages that interrelate in obvious ways.

What will come out of this is code that looks like it was obvious how to do things, even though going in, it won’t have seemed obvious at all. Code who’s behavior who seems obvious is very readable, and its what we strive to have when we’re done.

So many reasons code is unreadable is we try to put in place abstractions at the beginning that ends up not being good fits. But because the refactoring overhead is so large for these abstractions, we end up shoehorning things in anyways.

This makes the code hard to read, as the abstractions aren’t helpful.

Using the drafting method, many abstractions that emerge are ones you wish you knew of going in. Because we don’t prematurely abstract or organize, but instead solve our problem, one line at a time, and let our complexity be kept in check by an enormous number of assertions and comments, we’re able to refactor with the complete solution in mind.

April 11, 2020 Posted by | Uncategorized | Leave a comment

Re: Re: Software Disenchantment

Would you buy a car that was slightly less blue than it could be? When you knew there was a car that was painted a color blue that was 99.9% 470 nm in wavelength from all angles?

Why not!? Shouldn’t the point be to be as blue as possible? We should definitely spend all of our efforts, time and money into making something as MUCH of X as we can since clearly there are no tradeoffs to make ever. Anyone who fails to make something as blue as possible – because clearly I value the color blue and you should too – is lazy and has lost the art and value of the ‘good old days’ when things just, you know, seemed bluer back then.

Even Bob Ross could paint bluer things than some of the cars I see today!

Oh, what’s that you say?

Because you don’t want something to be blue?

Psh. Fine. Jack ass.

September 18, 2018 Posted by | Uncategorized | Leave a comment

Six Facets of Programming

(This is based loosely on the book The H Factor of Personality)

I love systems. I’m kind of a builder or a speculator from a philosophical sense. I tend to wonder ‘what if’ and build hypothesis. Most hypotheses are wrong. And that’s okay.

I’ve recently done some reading on personality traits, drawn primarily from a model that assumes there are six traits (similar to the “big 5”) traits that themselves tend to be uncorrelated. While thinking about these traits, I’ve also thought about how they express themselves in programming talent.

These traits are uncorrelated. You can be high in all six of them, or low in all six of them. But it simplifies things a bit to think about what you’re dominant in, and how that may affect how you approach your work.

How do you solve problems?

The Hunter

A person who has a high level of “openness” and who uses that trait to solve problems is what I’d call a ‘hunter’. They’re always looking for something new, some new untamed land.

New tools, new techniques. They want to find clever solutions to their problems, and they get a kick out of it when they do. They’re never afraid of new technologies, instead, they tend to see new things as potentially solving their problems.

Hunters may also get a kick out of firefighting since every new bug is something to chase down and bring to heel.

The Farmer

Farmers have a high level of “conscientiousness”. To me, conscientiousness is either an ability to tolerate “toil”, or even more so, an ability to take pleasure from “toil”. Depending on how high you are in “C”, you either don’t mind hard work as much as others, or you even can enjoy it.

Farmers will take standard, well worn and tested solutions and apply them again and again and again. They know how to solve the problem and get a great joy out of seeing it solved. They take value in quality.

Farmers will take their bag of tricks and use them reliably on problem after problem in a reasonably predictable manner.

The Trader

Traders have a high level of “eXtraversion”. They solve problems through their network of people. They tend to be “central connectors” in the organization, and plug people in with each other and spread information.

Traders are going to approach problems particularly collaboratively. You’re going to find them in peer reviews, design reviews, and pairing. They’re going to be absorbing information from others as well as passing on what they’ve learned and what they know.

In a team of hunters and farmers, traders are there to share lessons learned and balance skills, allowing people to specialize in what they do best.

Secondary Characteristics

Of course, as I said, you can be high in multiple of these traits. You may have all three, but its more likely you may have one or two dominant ways of approaching problems.

Hunter-Farmers

Hunter-Farmers are those types of people who are both high in O and C. They enjoy the adventure as well as toil.

What’s interesting that I’ve noted about hunter-farmers is that since toil isn’t uncomfortable for them, for most assigned work, that’s their default method of execution. They know it will work, there’s no risk, and they don’t mind doing it. They even enjoy it.

But unlike other farmers, hunter-farmers have a natural drive to also explore. These are the type of folks who will do very dependable work in the office and take home stretch projects. So they’re growing as individuals, they’re trying new things, but usually not with their main tasks. They’ll be working hard on adding one more percent of code coverage to the code base (and not complain at such toil) while ensuring their landing page website uses proper monads in Phoenix at night.

Hunter-Traders

Hunter traders have both very dominant O traits and X traits. They’re going to be your war storytellers. They’ll be up late at night fighting fires, and telling the stories to new folks years later about what to look for, how to find things, and how to solve problems.

Hunter-Traders are great teachers, as they tend to bring more to the table than pure traders. They have a lot of experience they’ve sought out individually, and aren’t afraid to share it.

Hunter-Antifarmers

What if you’re high in O and low in C as a developer? In many cases, having fewer arrows in the quiver just kind of “sucks to be you” sort of thing. But, in the particular case of the high O and low C developer, you get a unique combination that gets you the “work smart, not hard” developer.

Antifarming developers in particular hate toil. Their high O traits help them always be on the look out for solutions that make their lives easier. Sufficiently high O developers may be among the most productive, but you would never be able to tell by the hours they put in. They will continue to always look for a better way to avoid as much toil as possible, and over the years, develop a very rich set of ideas, methods, tools, and technologies.

How do you work in Teams?

The Rockstar and the Drummer

“Rockstars” and “Ninja” developers tend to work alone. They also tend to believe programming talent is just something “you have or you don’t”. They are low in “Honesty/Humility”.

They’re a bit prone to sexism, tend to be young, white men, and tend to be people you should probably keep off the team.

Programming ability is something you can train, hone and make better with time. Rockstars think they need to be the center of attention and that programming is ultimately a competition to see who is better than the other. Depending on how much of a diva they are, they may simply pull long hours to outdo someone else (a benign rockstar) or outright work to undercut them.

Who do you want instead? You want drummers. Drummers also play in bands but know that they’re a part of something larger. They know that they need to follow the common social rules of the team to get to where they want to go. They know that the music sounds way better when we all work together.

Drummers also insist on practice. The band must practice to get better. Drummer’s believe people can grow and get better with time. Teams of drummers all get better with time.

The Empath and the Stoic

Empaths literally have a higher tendency to feel what others are feeling. This is a blessing and a curse.

Empaths, or those with high “Emotionality/Neuroticism” are going to feel negative emotions a bit louder than other folks. The team’s anxiety, anger, and depression from doing work that is hard. They’re like canaries in the coal mine and are an early warning siren that something is broken on the team.

They’ll feel it stronger themselves, which makes life a bit hard for them. But on the flip side, they’ll also feel it much stronger from their ‘kin’ or in-group. That means they may get angry for other people who can’t quite understand their own anger. They’ll have a tendency to understand and think in emotions sooner than their stoic counterparts.

Stoics are also good to have on the team at times. Their ability to not feel negative emotions means they’ll push harder than others through their own pain. They are going to have trouble, though, identifying with others and understanding when others are in pain.

In particular, stoicism pairs well with farmers. These people can pull double time on toil, moving from enjoying it to simply withstanding it a bit longer than others.

If most of your developers were slightly more empath than stoic, with a healthy mix of stoic-farmers and pure empaths in there, you’d have a team that really worked to understand each other.

Prosecutors and Defense Lawyers

Prosecutors are low on “Agreeableness”. If something is wrong, you’re going to hear about it. If you did something wrong, they’re going to tell you. Even if you didn’t do anything wrong, they may be looking for something anyway.

Prosecutors don’t care if the truth hurts, and they’re out to ensure that folks know what that truth is.

Defense lawyers are the opposite. They’re listeners, they want to hear you out, they want to ‘get it’. They want to understand both sides. And at the end of the day, they really just want us all to get along.

Defense lawyers know mistakes are made on accident all the time. Prosecutors don’t care if its an accident or on purpose – they want it fixed.

Generally speaking, having teams tend to dominate on one side or the other here is good. If you have a large company, consider getting all the prosecutors on one team, and all the defense lawyers on another.

Both types of person want whats best. The issue is that defense lawyers tend to get walked all over by overly zealous prosecutors. If you’ve got a pair, and one developer is a farmer-prosecutor and the other is a hunter-defense lawyer, then you’ve actually got two farmers. Prosecutors will push for their way to be the way. You need other prosecutors to fight back.

Pairs of defense attorneys will tend to just work things out.

Secondary Characteristics

Empath-Drummers

Empath drummers are going to have a tendency to want everyone to work together, and get really fucking upset when they don’t. They’re going to feel other’s pain at the injustice of folks taking advantage of other folks, and it may cause them to sound the alarm.

Since teams of strong drummers often work best, having an empath-drummer, in particular, can serve as an organizational justice early warning system, incredibly sensitive to the slightest unfairness.

These folks can also tire themselves out, though, and may be screaming at problems that have no easy solutions.

Where are all the others?

In many cases, I was trying to draw from my own experience of folks I’ve worked with and what seemed to dominate their problem solving and teamwork approaches. I haven’t met all the hybrid types yet, at least in a way that I’ve noticed.

Of course, its also just a dumb system. It’s probably all wrong. But it was fun to create 🙂

September 2, 2018 Posted by | Uncategorized | Leave a comment

No, You Don’t Need to F*cking Rewrite

I slummed it in /r/programming today and found this incredibly disheartening series of comments.

It was disheartening as it was just my birthday a few days ago, and I realized with this comment that I am now older than the average programmer.

Programming is a perpetually young industry, primarily because it’s still growing so fast. The need for more programmers means more and more folks are entering, keeping the average age low.

This is one of the reasons so many programming methodologies move in cycles – these kids have to re-learn everything the older folks learned.

Case in point: No, you don’t need to do a fucking rewrite.

The Rewrite Cycle

What everyone who thinks a rewrite is a good idea has failed to experience is when their own code gets rewritten. Let me give an example, here’s how kids seem to think the rewrite would work:

  1. The code is awful, full of TODOs and hard to understand. It got this way because “big, scary, bad management” made it that way. I hate “big, scary, bad management”!
  2. We should rewrite it rather than maintain it, this will save us in the long run.
  3. Woohoo! Now the code is clean, elegant and maintainable! Success!

But here’s how it actually fucking works, and why it upsets me every time this is suggested:

  1. The code is awful, full of TODOs and hard to understand. It got this way because humans are bad at coding.
  2. We should rewrite it rather than maintain it, this will save us in the long run.
  3. 6 Months Pass By
  4. Go to 1

It’s a cycle, not a process. And the reason code sucks, dear Brutus, is not with our management, but with ourselves.

What is Bad Code?

A lot of folks say bad code is code that’s ‘unreadable’ or ‘unmaintainable’ but that’s just a redefinition. What’s the real definition of bad/unreadable/unmaintainable code?

Bad code is code that you didn’t write.

Code only seems ‘elegant’ and ‘clean’ on a rewrite because you just rewrote it, and you had to wrap your head around the fucking problem such that now it all seems easy. You have inadvertently obtained the curse of knowledge. You saw something complex – at the heart of it was the fact that you didn’t understand the problem you were trying to solve. You mistakenly believed it had instead to do with the author’s choice of tabs or spaces, rather than realizing that you were just fucking dumb.

So you convinced some poor manager to do a rewrite, who had no idea how bad of an idea it was or didn’t know how to say no, or was afraid of you, and now you’re on the other side and the system you wrote seems ‘elegant’ and ‘simple’. But really, elegant is code for “I wrote this”.

What makes me so frustrated with this is that each generation of programmers has to learn this and watch idly by as the next generation, which is somehow so much smarter and better than the rest, makes the same goddamn mistake.

What to Do Instead?

Refactor, don’t rewrite.

“But this code is shit! I don’t want to do it! It’s complicated and it makes me feel stupid!”

How the code makes you feel is not a concern of mine. I feel stupid all the time, and I’ve come to realize that feeling stupid is the first step towards learning something. I’m not going to back your plan to rewrite a critical piece of our system because you can’t admit you don’t feel smart when you read it.

Code that’s been delivered has some of the roughest, best forms of testing there is – soak testing. Code that’s been delivered has some of the roughest, best forms of peer review there is – a bunch of really angry maintainers. Code that’s been around awhile has a lot of value.

Is it ugly? Sure, but that’s because everything of more complexity than a “Hello World” is ugly. It’s our responsibility as engineers to try and polish that turd as well as we can, and to do that we refactor, we increase test coverage, we run tools, and we do peer reviews. We dedicate some of our time to learning new design techniques and applying them judiciously.

“But shouldn’t we just ‘start from scratch’ and do all of it ‘right’ from the beginning?”

No! Goddamnit, No! That’s what the last person said. And the one before that. And it will be what the next 23-year-old, fresh out of a CS degree, says about your code.

Stop the cycle.

Refactor, don’t rewrite.

 

April 26, 2018 Posted by | Uncategorized | Leave a comment

Create your own website, free on WordPress.com.Create your own website.
Start free