Comments have their purpose, but can be redundant or even harmful. For example, if you put intrinsic knowledge about the code into the comments, then change the code, the comments become irrelevant at best and harmful at worst.

Agile is anything that is inline with the values listed here - http://agilemanifesto.org/

The const qualifier prevents code inside the function from modifying the parameter itself. When a function is larger than trivial size, such an assurance helps you to quickly read and understand a function. If you know that the value of side won't change, then you don't have to worry about keeping track of its value over time as you read. Under some circumstances, this might even help the compiler generate better code.

That's ridiculous. TDD forces code to pass tests and forces all code to have some tests around it. It doesn't prevent your consumers from incorrectly calling code, nor does it magically prevent programmers missing test cases.

So, since we do software testing, we should quit placing assert statements in production code, right? Let me count the ways in which this is wrong:

TDD and defensive programming go hand and hand. Using both is not redundant, but in fact complementary. When you have a function you want to make sure that the function works as described and write tests for it, if you do not cover what happens when in a fail case of a bad input, bad return, bad state, ect then your aren't writing your tests ridge enough and your code will be fragile even if all your tests are passing.

I believe most answers are missing a critical distinction: It depends on how your code is going to be used.

The bounds checking you describe as part of defensive programming will catch mistakes during the use of the code.

I disagree that precondition checks require more unit-tests. If you decide you dont need to test some forms of invalid input, then it shouldn't matter if the function contains precondition checks or not. Remember tests should verify behavior, not implementation details.

The solution is not to use a real database most of the time

TDD drives defensive programming, if the tests are comprehensive.

You have two options for the type of s:

Then create an array of this struct in your VC:

I'm going to play devil's advocate and say, Yes. TDD and Agile are the same thing, just at different scales.

Assertions are an excellent documentation tool. No comment ever was, or will ever be, as unambiguous as a piece of code asserting the same thing. Also, documentation tends to become outdated as the code evolves, and it is not in any way enforceable by the compiler.

A new artificial magnetic material has been developed by researchers, …

Is it true that TDD is able to replace defensive programming? Is parameter validation (and I don't mean user input) unnecessary as a consequence? Or do the two techniques complement each other?

The tests of TDD will catch mistakes during the development of the code.

What if the mock object doesn't behave like the real object ? You can reduce this strategy by having a set of tests for the Mock Object that can also be applied to the real object when it becomes available.

I am a newbie in Swift. I was ale to get 2 markers on Google Maps:

Yes, you should be updating the tests at the same time you update the code. You should also be updating (or removing) comments at the same time you update the code. But we all know these things don't always happen, and that mistakes are made.

Yes TDD tests behavior. Validation is a behavior. TDD should be making you throw every exception you can throw.

I do not dispute any of the disadvantages for centaurs …

Today I had an interesting discussion with a colleague.

PS. FWIW, the code is GPLv3+, on github in file gui.c on commit 58feb1d9473c34aca.. of the expjs branch. More details & motivation about that software project on this & that questions.

Your colleague is right about one thing: You should test your validations, but this isn't "unnecessary work". It is the same as testing any other code, you want to make sure all usages, even invalid ones, have an expected outcome.

Does TDD make defensive programming redundant

Assertions are optional, so if you don't like them, just run your system with assertions disabled.

There are factors that facilitate the formation of putatively toxic …

At least one other test is going to pass a valid argument, of course--or loop through a big array and pass umpteen valid arguments--and confirm that the resulting state is appropriate.

TDD does absolutely not replace defensive programming. Instead, you can use TDD to make sure all defences are in place and work as expected.

In information security, this is called Defense In Depth. Having multiple layers of defense ensures that if one fails, there's still others to catch it.

Is Agile really different from TDD ? If so what are the main differences ?

I am a defensive programmer. I believe that the rule "a class must ensure that its objects have a valid state when interacted with from outside the class" must always be adhered to. The reason for this rule is that the class does not know who its users are and that it should predictably fail when it is interacted with in an illegal manner.

I was reading my C++ book (Deitel) when I came across a function to calculate the volume of a cube. The code is the following:

TDD will develop the tests. Implementing parameter validation will make them pass.

Agile methodologies usually emphasise communication, conversation and lightweight documentation. TDD can be used as a form of documentation, too, especially if you make the test-names into meaningful sentences and use the same language that the business use together with realistic examples. This can also encourage communication and conversation.

Arrays are initialised similarly (you've actually already initialised an array, namely s, with a string):

Agile methodologies encourage reflection and learning from the past. TDD has this lovely red bar which can help you to do that very quickly.

What's the best way to create the object I need?

Especially if that other system's programmers didn't code defensively.