
Common Species Of Code - GotAnyMegadeth
http://www.willa.me/2013/11/the-six-most-common-species-of-code.html?m=1
======
adwf
The startup one is eerily familiar. I sometimes think the most frequent
comment I write is along the lines of "TODO: Should really write a better
version of this, but it works for now..."

I've even started writing those comments before I've written the function :(

~~~
michaelfeathers
ADD - Apology-Driven Development

------
duwease
The Enterprise code brings back awful memories of working with a framework
architected by someone who had obviously read the Design Patterns book and had
the take-away of "Use these as often as they can be wedged in to have a better
system."

God forbid I needed to add a single boolean field to a single screen. By the
time I submitted the DB change request, then changed the abstract factory
interface, then the abstract factory class, then the factory interface that
generated, then the factory class, then the abstract DAO interface that
generated, then the abstract DAO class, then the parent DAO interface, then
the parent DAO class... _pauses to catch breath_ ...then the child DAO
interface, then the child DAO class, then the controller object interface,
then the controller class, then the actual page, then the unit test, it was
4AM and time to go to sleep.

Let this be a cautionary tale to any future architects out there.. remember
that flexibility is a MEANS, with the ends being less time and money spent
coding and maintaining code. It's not an ends to itself, and can even be a
hindrance to the ends.

------
robomartin
Closed-form expression [0], good up to n == 71:

    
    
       def fibonacci(n):
            gr = (1 + (5**0.5)) / 2 
            return int((gr**int(n) - (-gr)**int(-n)) / 5**0.5)
    
    

[0] [http://en.wikipedia.org/wiki/Fibonacci_number#Closed-
form_ex...](http://en.wikipedia.org/wiki/Fibonacci_number#Closed-
form_expression)

~~~
LinaLauneBaer
I wanted to mention this as well. There is actually a closed form (as you
indicated). Also good to know: This is or was a interview question at Google.
You had to know Moivre-Binet's closed formula from the top of your head to
pass.

~~~
speeder
I don't even know what is Moivre-Binet what the fuck.

------
Tehnix
In a similar fashion, "The Evolution of a Haskell Programmer" (I'm sure there
are for other langs also)
[http://www.willamette.edu/~fruehr/haskell/evolution.html](http://www.willamette.edu/~fruehr/haskell/evolution.html)
:)

~~~
wting
Evolution of a Python programmer:

[https://gist.github.com/fmeyer/289467](https://gist.github.com/fmeyer/289467)

------
benvds
A CS 101 student apparently writes the most readable code.

~~~
dsego
Except it is not correct.

~~~
Apocryphon
I like how both the student and the Startup hacker mess up bounds-checking,
except the student doesn't realize it in the initial case, and the hacker
misses it as the codebase gets progressively larger and he or she gets more
tired.

~~~
cheapsteak
I don't get it, what's incorrect about the code?

~~~
dsego
Try calling the function with 0 or a negative number.

------
snorkel
The Large Company version is way too small. It should have at least 20 code
files and is provided to other departments as a hosted service that no one has
access to due to security restrictions, and the only documentation for how to
use it is a powerpoint that is 3 years out of date.

~~~
aaronem
[https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...](https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition)

Serious business.

------
jfasi
Don't forget the tests of each. The startup's tests are all commented out
because they failed at some point or another, the large company's tests are
five times as long as the actual code they test, and all other categories
consist of the stubs provided by the IDE.

------
Fargren
Why do they all(except Hackaton) use an exponential complexity algorithm for a
polynomial time problem? Linear, even.

~~~
marvy
The math phd one is constant time :)

~~~
wging
It's not. Multiplication can't in general be done in constant time (and the
exponentiation algorithm is inefficient as well). You might argue that we're
working with ints here, so yes it can, but in that case all of these are
constant time.

~~~
Fargren
It depends on what you consider an operation, doesn't it? You can consider
multiplication to be an operation, or you can count more basic operations,
such as MOVs and SUMs. I think for Fibonacci, number of additions is a good
measure of complexity.

~~~
dmunoz
> It depends on what you consider an operation, doesn't it?

Exactly. I see far too many people lately who want to point out the
technically correct (a.k.a. best kind of correct) version of algorithmic
complexity where e.g. multiplication is not constant time. Often this is
paired with the contrasting complexity analyses having different meanings for
the N in the big O notation, e.g. bit complexity of input vs. number of
elements input. Note, this is not the case above, but is often what I see
happen. It's very sloppy to directly compare the two as they are making wildly
different assumptions on what is constant time. The model matters. An example
used in a parallel computing class I took was that comparison based sorting on
P parallel processors could be done in log N time (less than the Nlog(N) lower
bound of comparison based sorting) in the PRAM model where memory access
across parallel processors is still O(1).

------
robomartin
I've been watching my son go through MIT 6.00.1x. He's working on the first
midterm this very minute.

One of the things I've noticed is that, yes, code quality is from OK to horrid
sometimes. Rather than stand behind him and correct every little detail I've
let him navigate the problem sets and quizzes mostly on his own. When he gets
stuck I give him a shove in the right direction and see what happens.

I've reflected on this as I've never really looked at student code. By the
time I was a college student taking my first programming course I had already
built a number of microprocessor boards, learned how to program them in
machine language and moved on to Forth and C. I think my code was reasonably
clean by that stage. Still, I know it wasn't professional grade by any
measure.

It's easy to forget where we all started from and, as a result, criticize
student code as naive. Well, in most cases, it is. That's a fact.

What I have now realized from watching my son learn to code as well as
interacting with him through the process is that he is not learning to code.
He is learning to think. He is learning about dissecting problems into small
conceptual units that he can then translate into code. Sure, he is learning
python in the process. However, the problem solving, solution structuring and
problem representation skills that are very much necessary to be a good
software developer are mostly language agnostic.

Realizing this, the fact that he is writing code that isn't the cleanest or
the slickest possible solution to a problem stopped bothering me. I want him
to learn how to think first.

Not to say that I've completely ignored the issue. I let him finish the
assignments on his own and then we sit down and do a code review session where
I point out where and how things could be better. We've had cases of a dozen
lines of code replaced by just a couple. And that's OK. That's how he is going
to learn.

------
msane
Oh man these samples are really well done. Really hilarious.

------
thaumasiotes
I wrote an explicit-formula fibonacci function once. I think you lose
precision before n=100. It was disappointing.

~~~
LearnYouALisp
Yes but the mathematician considers the numbers under 100 to be very small
fraction of the numbers under, 1000, or 10^12 or something. Or, in math
language, a very small portion of the natural numbers.

~~~
hackula1
As some one who rights stats libraries, I can see it now.

"Bug: code does not work with an input of 1"

"1 is of approaching-zero-significance when you consider all of the other test
cases we are meeting. 1 is not the responsibility of this lib. Feel free to
fork. ======= issue closed."

------
tudorconstantin
and the cat writes the most correct code according to most programming best
practices - except for giving meaningful names to constants, variables and
functions

~~~
Roboprog
Many years ago I remember coming across some code to page through a table. One
of the variables was "STARTREK". There were a few moments of "WTF?!?", until I
realized that the variable should have been named "StartRec" (allowing for the
fact that language of the day was case insensitive, and only allowed 10 letter
names)

------
thatthatis
The startup code is the cs101 code with two additional cases handled (and
minus the contrived x==2 state), and a lot of documented thought about what
could be done to improve.

------
alixaxel
I think this pretty much nailed the reality. ^^

