1

This is not about explicit code, so apologies if it should have been posted elsewhere. It is, however, solidly within the domain of testing, which I assume you guys to be right at home in.

I'm reading the provocatively titled paper "Why Most Unit Testing is Waste" (21 pages) and came across this passage:

The third tests to throw away the tautological ones. [...] Testing for this being non-null on entry to a method is, by the way, not a tautological test — and can be very informative [...]

This really piqued my curiosity -- why would this ever be null on purpose? How would you even write such code?

Edit: Thank you Daniel! I don't know much C(/++/#) but my initial (Java-centric) thought was that no, it's not possible, and I seem to be right, with reference to your 2nd comment that "If you're using this, then you're in the instance so this [can't be] null."

Mike Stockdale
  • 5,256
  • 3
  • 29
  • 33
KlaymenDK
  • 714
  • 9
  • 31
  • [Checking if this is NULL in C++](http://stackoverflow.com/questions/1844005/checking-if-this-is-null) – Daniel Daranas Sep 01 '16 at 13:24
  • 1
    [Can "this" ever be null in Java?](http://stackoverflow.com/questions/3789528/can-this-ever-be-null-in-java) – Daniel Daranas Sep 01 '16 at 13:24
  • 1
    [Can "this" ever be null in JavaScript?](http://stackoverflow.com/questions/9739806/can-this-ever-be-null-in-javascript) – Daniel Daranas Sep 01 '16 at 13:25
  • [Can this be null in Scala?](http://stackoverflow.com/questions/10072645/can-this-be-null-in-scala) – Daniel Daranas Sep 01 '16 at 13:25
  • [Within a C# instance method, can 'this' ever be null?](http://stackoverflow.com/questions/5055068/within-a-c-sharp-instance-method-can-this-ever-be-null) / [Why check this != null?](http://stackoverflow.com/questions/3143498/why-check-this-null) – Daniel Daranas Sep 01 '16 at 13:26
  • 1
    @DanielDaranas, thank you so much! I'd accept your answers if you'd let me. – KlaymenDK Sep 01 '16 at 13:29
  • 1
    I didn't post the links to related questions as an answer because they would not constitute an answer. I didn't vote your question as duplicate, either, because your question does not specify a language and so it does not seem an exact duplicate of any of the related questions. I did post them, though, as comments, because I thought they could be of interest. – Daniel Daranas Sep 01 '16 at 13:31
  • 1
    You could easily compile all those comments into table-form (with "yes" "no" flags) which would make a very good generic answer. – KlaymenDK Sep 01 '16 at 13:41

1 Answers1

0

Credit goes to @DanielDaranas.

KlaymenDK
  • 714
  • 9
  • 31
  • Javascript: [*Yes, it can,*](http://bcgavel.com/wp-content/uploads/2015/04/tumblr_md3p0xrgqy1r0z99do1_500.jpg) in strict mode… – deceze Oct 21 '16 at 08:43