Simplicity Comes from Reduction

Simplicity Comes from Reduction

Paul W. Homer

“DO IT AGAIN…,” my boss told me as his finger pressed hard on the Delete key. I watched the computer screen with an all-too-familiar sinking feeling, as my code—line after line—disappeared into oblivion.

My boss, Stefan, wasn’t always the most vocal of people, but he knew bad code when he saw it. And he knew exactly what to do with it.

I had arrived in my present position as a student programmer with lots of energy and plenty of enthusiasm but absolutely no idea how to code. I had this horrible tendency to think that the solution to every problem was to add in another variable some place. Or throw in another line. On a bad day, instead of the logic getting better with each revision, my code gradually got larger, more complex, and further away from working consistently.

It’s natural, particularly when you’re in a rush, to just want to make the most minimal changes to an existing block of code, even if it is awful. Most pro- grammers will preserve bad code, fearing that starting anew will require sig- nificantly more effort than just going back to the beginning. That can be true for code that is close to working, but there is just some code that is beyond all help.

??150 97 Things Every Programmer Should Know

?

???????????????More time gets wasted in trying to salvage bad work than it should. Once something becomes a resource sink, it needs to be discarded. Quickly.

Not that one should easily toss away all of that typing, naming, and formatting. My boss’s reaction was extreme, but it did force me to rethink the code on the second (or occasionally third) attempt. Still, the best approach to fixing bad code is to flip into a mode where the code is mercilessly refactored, shifted around, or deleted.

The code should be simple. There should be a minimal number of variables, functions, declarations, and other syntactic language necessities. Extra lines, extra variables…extra anything, really, should be purged immediately. What’s there, what’s left, should be just enough to get the job done, completing the algorithm or performing the calculations. Anything and everything else is just extra, unwanted noise, introduced accidentally, obscuring the flow, and hiding the important stuff.

Of course, if that doesn’t do it, then just delete it all and type it in over again. Drawing from one’s memory in that way can often help cut through a lot of unnecessarily clutter.

时间: 2024-08-11 07:36:06

Simplicity Comes from Reduction的相关文章

Cache memory power reduction techniques

Methods and apparatus to provide for power consumption reduction in memories (such as cache memories) are described. In one embodiment, a virtual tag is used to determine whether to access a cache way. The virtual tag access and comparison may be per

4.2 Reduction优化

首先添加上Heterogeneous Parallel Programming class 中 lab: Reduction的代码: myReduction.c // MP Reduction // Given a list (lst) of length n // Output its sum = lst[0] + lst[1] + ... + lst[n-1]; #include <wb.h> #define BLOCK_SIZE 512 //@@ You can change this

dimensionality reduction动机---data compression

data compression可以使数据占用更少的空间,并且能使算法提速 什么是dimensionality reduction(维数约简)    例1:比如说我们有一些数据,它有很多很多的features,取其中的两个features,如上图所示,一个为物体的长度用cm来度量的,一个也是物体的长度是用inches来度量的,显然这两上features是相关的,画到上图中,近似于一条直线,之所以点不在一条直线上,是因为我们在对物体测量长度是会取整(对cm进行取整,对inches进行取整),这样的

The Improvement of Reduction Summation on GPU Using CUDA

We can never be satisfied with the program just only running correctly.The reduction summation program described in previous blog post needs to be optimized. 1.make the best use of  hardware and do not forget CPUs! During the second part in the reduc

Householder Reduction Matlab Version

function [T, P] = householder(A) % Formations: RA = T, where A is original matrix % The implementation of Householder Reduction % R is constructed as a product of elementary reflector % T is upper triangular matrix % Author: Zhenlin Du(Johnsondu) % E

Machine Learning - XIV. Dimensionality Reduction降维

http://blog.csdn.net/pipisorry/article/details/44705051 机器学习Machine Learning - Andrew NG courses学习笔记 Dimensionality Reduction降维 Motivation Data Compression数据压缩 Motivation Visualization可视化 Principal Component Analysis Problem Formulation主成分分析问题的构想 Pri

OpenMp之reduction求和

// OpenMP1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include"omp.h" #include<Windows.h> #include<time.h> #include<iostream> using namespace std; #define NUM_THREADS 4 int _tmain(int argc, _TCHAR* argv[]) { omp_set_

Poj 2707 Copier Reduction

1.Link: http://poj.org/problem?id=2707 2.Content: Copier Reduction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8315   Accepted: 4389 Description What do you do if you need to copy a 560x400mm image onto a standard sheet of US letter-

Code Simplicity&ndash;The Science of Software Development 书摘

Chapter1 Introduction That is the art and talent involved in programming-reducing complexity to simplicity. A "bad programmer" is just somebody who fails to reduce the complexity. So, a "good programmer" should do everything in his pow