Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I always liked to ask myself "what's the first principle(s) of this?" after I learned the basic stuff of something (e.g. programming). It's an inspiring question, IMO, that can force you to think about the most important principle(s) behind something, especially a skill such as programming.

So, what do you think is the first principle(s) of programming? I'll give my answer below a little later.

share
show 1 more comment

locked by maple_shaft May 15 '13 at 16:40

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

93 Answers

No infinite loops.

share
show 8 more comments

KISS (keep it simple, stupid).

It does indeed beg the question "How do you define simple?" And also "When is something too simple for the task at hand?" This is why you cannot become a good programmer just by knowing the first principle of programming.

share
3  
and if you're stupid, how would you know if it was simple? –  Steven A. Lowe Oct 1 '08 at 19:07
1  
"This is why you cannot become a good programmer just by knowing the first principle of programming" - love it. –  yuval Jul 31 '09 at 18:33
1  
@Dima: you're right, I mean that quality and simplicity (in this case at least) are both undefinable, yet we know it when we see it, if our eyes are trained. –  Adriano Varoli Piazza Aug 1 '09 at 21:48
show 5 more comments

Write code like if it was you that would have to maintain that code.

share
19  
Write code as if an axe-wielding psycopath will have to maintain it. FTFY. –  Forgotten Semicolon Oct 1 '08 at 19:08
10  
...and the axe-wielding psychopath knows where you live. –  CAD bloke Oct 8 '08 at 20:24
2  
..,and he has just sharpened his axe... –  Roalt Mar 9 '09 at 9:56
1  
... and he is working by your side. –  Y3L1NNa Jul 31 '09 at 18:33
show 3 more comments

Sequence, Choice, Repetition

share
show 2 more comments
  1. KISS - Keep It Simple Stupid
  2. DRY - Don't Repeat Yourself
  3. YAGNI - You ain't gonna need it
share
8  
I think KISS should be "Keep It Simple, Stupid!" –  Dennis Cheung Dec 9 '08 at 16:33
10  
I would also add YAGNI. –  Daniel Straight Mar 9 '09 at 12:29
3  
@Programmin Tool - I don't think "stupid" is superfluous. I think it conveys that we have a tendency to want to be "smart" and this manifests as unneeded complexity. As I see it, the "stupid" tries to remind us of this tendency by helping us remember what we initially think is "smart" is usually not. –  codekaizen Jul 31 '09 at 19:01
3  
OR if you combine them all: "KISS my DRY YAGNI" :P –  Darknight Jul 10 '11 at 14:15
show 9 more comments

Do not overuse Interface.

share
1  
This one is too language-specific –  finnw Oct 2 '08 at 1:07
show 1 more comment

Be as lazy as possible.

share
2  
Again, too general, IMO. This begs the question "How lazy is the appropriate amount of laziness, really?", because obviously "sloppy" is something you don't want to be either. –  pongba Oct 1 '08 at 19:10
2  
Too general. By that analogy all variables and functions would be 1 letter because I was 'too lazy' to type out something meaningful. Assuming I had to maintain it also however, then perhaps you are correct, because I would make it as easily maintainable as possible. –  Kyle B. Jan 8 '09 at 21:21
3  
@Kyle: Yeah, that's the point. "True laziness" is making things easiest for yourself now as well as in the future. Which turns out to be the same as doing things properly. If you do less work now but more work later, you're not being "as lazy as possible" :) –  Adam Bellaire Jan 12 '09 at 12:58
show 5 more comments

Do not reinvent the wheel.

share
5  
Some "wheels" need to be reinvented. –  CrashCodes Oct 1 '08 at 19:45
3  
How about: Only reinvent the wheel if the benefits will be worth the costs –  e.James Dec 9 '08 at 16:19
show 2 more comments

Program with an audience in mind. By that, don't assume that anything you write will not be read and maintained by you or someone else.

A corollary to that: Prove that you understand the problem you are trying to solve by naming your variables and functions and classes well!

share
add comment

Sequencing, what do I do and When do I do it.

share
add comment

Refactor before it's too late.

share
show 2 more comments

Any problem can be solved with another layer of indirection.

share
show 3 more comments
  1. Don't do it.
  2. If not doing it isn't possible, get someone else to do it.
share
add comment

The Binary System

0 + 1 = 1
1 + 1 = 10
10 + 1 = 11
11 + 1 = 100
100 + 1 = 101
101 + 1 = 110

Get it?

share
1  
Can't vote down right now. But will do :D –  pongba Oct 1 '08 at 19:19
show 7 more comments

Know your tools.

share
add comment

In general: Problem solving.

That is what it all boils down to.

share
show 4 more comments

I got into programming by way of studying digital electronics, so I guess for me the basic logic gates (not, and, or, xor, implies) were the first principles of programming.

share
add comment

This is a good question.

  • Know your requirements
  • Know your user
  • Know your limits
  • Always assume you don't know everything
  • Always understand the code you're using/writing
  • Never reach conclusions without evidence
share
show 1 more comment

Think as if you don't know any particular programming languages (so that you don't fall into the trap of "thinking in XXX". Code to realize that thinking using the proper language.

share
show 1 more comment

Knowing when not to program.

share
1  
What he means is that many programming problems can be solved cheaper and more timely by purchasing off the shelf applications, components, or libraries. –  Gordon Bell Oct 3 '08 at 5:08
show 6 more comments

When refactoring unnecessarily complex code, I often repeat the mantra:

The computer wants to do the right thing, you just need to get out of the way.

share
show 2 more comments

Principle: Software is Knowledge Capture.

Consequences: Many techniques for knowledge representation, all founded on Abstraction. Gives us layers, tiers, encapsulation, separation of concerns.

Many techniques for procedure representation, all founded on Sequence, Choice, Repetition.

share
add comment

While keeping it simple (KISS) and not duplicating code (DRY):

  • Make it work right
  • Make it work fast
share
show 1 more comment

Progamming is not for the lonely geek.

share
add comment

Programming is a means not an end. Or perhaps, "Can does not mean should."

share
add comment

Never completely believe what you are told about how the program will be used.

share
show 2 more comments

Coffee in, code out.

share
3  
Tea in in my case =) –  Clox Aug 3 '09 at 16:36
show 1 more comment

It's all about the user.

share
add comment

Zen, part I: Programming is only the road, not the way.

Programming is only the technique to teach a computer what it's gotta do. To be successful in creating fast, reliable software means to know your algorithms, best-practices and all the other stuff not necessarily connected to your Programming (language).

Zen, part II: If you are in a hurry, stroll along slowly. If you really are in a hurry, make a detour.

Sounds silly, but do not let yourself get into compromises that (really) may trouble you afterwards. I got a rule: If you are at the core of a program, try to be as precise and good as possible. If you are using methods from the core that are deep in your software, try to be faster in coding. If you are coding above these two, you can even get a little bit more sloppy.

Design errors are the hardest to find and/or fix, next step are programming errors in parts everyone relies on, then the "real showing-off software parts". If you need to fix a design error at the end of a project, ummm, that's not good... ;-)

Zen, part III: Know your path, Neo.

Know your environment, tools and the stuff you rely on on a daily basis and get it sorted so that it works for you. Best if you use your programming "environment" so natural that you do not even have to think of it. If you have to get a job done do not introduce "fancy new stuff" but do your work. This stuff can be introduced in a new project, namely then when you have time to prepare and use it.

share
show 3 more comments

In practice, and very unfortunately, good testing turns out to be more important than good programming. Testing increases the value of ugly code. If you can't write beautiful code, you should at least make it testable.

share
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.