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.

Last time I heard about "offensive programming/coding". I am not sure what it exactly mean. Why it is better, from defensive programming?

Can someone give me some examples or answers?

share|improve this question

migrated from stackoverflow.com Sep 29 '11 at 7:47

This question came from our site for professional and enthusiast programmers.

closed as off topic by Mark Trapp Sep 29 '11 at 8:03

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

Funny term - I can think of a few lines I've read in the comments section. Not sure if it relates to defensive programming. –  Gishu Sep 29 '11 at 7:11
c2.com/cgi/wiki?OffensiveProgramming –  stivlo Sep 29 '11 at 7:12
@stivlo - first hit on google :) Read it too. Never knew it was called "offensive programming". I usually just call it "fail fast". –  pap Sep 29 '11 at 7:13
@pap I never knew too, just googled :) –  stivlo Sep 29 '11 at 7:14
Hi Sebastian, I'm sorry your question was migrated here, but basic terminology questions aren't on-topic here, especially when the first hit on Google for "offensive programming" is the page stivlo linked, which wholly explains the concept. –  user8 Sep 29 '11 at 8:06

1 Answer 1

up vote 4 down vote accepted

Well, maybe. Quite often, DefensiveProgramming has the effect of ExceptionHiding? instead of making the bugs obvious. In a production system, this might be a good thing, in a development system, it is hardly ever. This is also referred to as FailFast.


If you force a developer to notice a bug (fail first) they will/need to fix it. If you instead hide the problem, the developer will may not even notice the bug, and even if they notice it, they will often not fix it.

This is the reason why FailFast is sometimes better than DefensiveProgramming.

share|improve this answer

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