Thread: Do programmers emphasize testing enough?

  1. #1
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665

    Do programmers emphasize testing enough?

    It seems like such a foreign concept to some...

    What do you guys think?

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,508
    Your question is kind of vague. Which programmers? Are you referring to the students who make up a bulk of the questions posted here? The teachers who guide students in their learning? Teams whose projects you've worked on or used? Professionals you've worked with in the field? On what are you basing your opinion?

    While I'm not sure exactly where you're coming from, I am inclined to understand your general point. But from my observations, it's not a problem exclusive to the programming community - any field that relies on the application of science should ensure certain criteria are met during development. But in reality, this is not always the case.

    Perhaps because, for many people, after sufficient knowledge is acquired, the resulting day-to-day work becomes merely a "job" over time and no longer a burning passion. We are just humans, and our chaotic minds and ever-shifting whims can easily take our attention away from the task at hand, when it is no longer engaging to our mind. There's also the fact that some people just never have the desire to go very far in their field.

    Like everything in this life, though, it's a double-edged sword. On one hand, it sucks when people do not do their jobs properly. On the other, if you excel, it gives you a chance to rise and succeed.

    I'm not sure if you were expecting such a philosophical response, but that's what I came up with after reading your question.

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Your question is kind of vague. Which programmers? Are you referring to the students who make up a bulk of the questions posted here? The teachers who guide students in their learning? Teams whose projects you've worked on or used? Professionals you've worked with in the field?
    I'm going to respond to this series of questions with, "yes", by which I mean, yes to all your questions.

    The students here, no doubt. It doesn't seem to me like testing makes up any non-trivial part of the education but that's kind of okay though. It's mostly just undergrads and let's be honest, undergrads just don't know anything. And yes, I do say that with myself included. My undergrad self was an idiot. It's amazing anything stuck at all. So I cut students the most slack.

    By that logic, I can't really blame the teachers then. Okay, I can. I know this is not an absolute and something like unit testing can only go so far but for most early education, it'd help students the most to teach them how to write small and compose-able functions that they can pull out and test in isolation. "Write a function that returns a free-standing node of a linked list containing a copy of the data passed into it. Write tests that prove correctness and error handling." Something like that. Code is far less complex when you have "physical" proof that your functions are doing what they're supposed to and not doing what they're not supposed to.

    As for teams, that's what's made me a test-writing lunatic. I've found a really good lead programmer. Their skills of abstraction are pretty great and it's influenced me in a large way. My latest revelation is testing frameworks. I've seen first-hand why testing frameworks are far and above the most amazing thing for software projects. You have like 1/10th the fear you do when you refactor or add new code to the base. It's super nice just running your code through a test suite so you can tell yourself, "Sweet, I didn't break anything!" That's fundamentally the goal, don't break your code. Having a rich and in-depth testing framework does nothing but good things.

    And now for your last question, this is why I made this topic in the first place. Basically, I wound up getting into an online chat war because some person didn't see the value of testing. They even went so far as to say that, "I write code that can't be tested" to which I immediately scoffed, "Maybe you're writing your code wrong...". I'm, of course, paraphrasing but it bothered me nevertheless.

    The code in question was some low-level stuff in C/C++ where they were, I think, live-injecting instructions to a DLL or the stack or something, I can't remember but it was something like that. Basically, it was amazingly easy to hash out a testing suite for the code even though I barely understood the problem. Write a function that generates a set of instructions. Test that. Write a function that injects a set of instructions. Test that. Ridiculous.

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    And now for your last question, this is why I made this topic in the first place. Basically, I wound up getting into an online chat war because some person didn't see the value of testing. They even went so far as to say that, "I write code that can't be tested" to which I immediately scoffed, "Maybe you're writing your code wrong...". I'm, of course, paraphrasing but it bothered me nevertheless.

    The code in question was some low-level stuff in C/C++ where they were, I think, live-injecting instructions to a DLL or the stack or something, I can't remember but it was something like that. Basically, it was amazingly easy to hash out a testing suite for the code even though I barely understood the problem. Write a function that generates a set of instructions. Test that. Write a function that injects a set of instructions. Test that. Ridiculous.
    The Linux kernel does not have a test suite.
    So, a patch that looks okay, builds and results in a bootable kernel is accepted.
    That seems terrible, but I doubt there is a better solution.
    It is indeed very difficult to test code which, for example, depends on the availability of specific hardware.

    Another example would be UI code, for which some forms of testing are possible, but not really anything comprehensive.
    Last edited by manasij7479; 02-27-2016 at 12:04 AM.

  5. #5
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by manasij7479 View Post
    The Linux kernel does not have a test suite.
    So, a patch that looks okay, builds and results in a bootable kernel is accepted.
    Dude, Linux is absolutely tested before each and every release. It's not '98 anymore.

  6. #6
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Did not know about this, thanks.

  7. #7
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Yarin View Post
    Dude, Linux is absolutely tested before each and every release. It's not '98 anymore.
    Phew. I was gonna say...

    Anyway, I'm sure I came off as a jerk in that situation. I was triggered though. They started badmouthing Node.js because they messed up their callback's function signature/method of invocation. This is true of almost all languages but they literally only do what you tell them to do. I couldn't imagine not taking the blame in that case. It's not JavaScript's fault that someone can't spell or remember how to call a function... Granted, it is definitely a point in the favor of compiled languages that they would've caught it for you.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,092
    Quote Originally Posted by MutantJohn
    They started badmouthing Node.js because they messed up their callback's function signature/method of invocation. This is true of almost all languages but they literally only do what you tell them to do. I couldn't imagine not taking the blame in that case. It's not JavaScript's fault that someone can't spell or remember how to call a function... Granted, it is definitely a point in the favor of compiled languages that they would've caught it for you.
    However, that makes it even more important for code that is interpreted at run time to be covered by automated tests and to be checked with static analysis tools.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by laserlight View Post
    However, that makes it even more important for code that is interpreted at run time to be covered by automated tests and to be checked with static analysis tools.
    Yes! Exactly.

    Though I must admit that the compiler is an amazingly powerful tool. But compilers do not catch everything, unfortunately. I definitely have lots of runtime errors too.

  10. #10
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by MutantJohn View Post
    It seems like such a foreign concept to some...

    What do you guys think?
    Is there still ........ty/buggy software out there? The answer to that question is yes, so the answer to your question is no, testing is not emphasized enough.

  11. #11
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Unit testing shouldn't be concerned only with errors. A bug is also a failure of the program to perform according to the programmer desire. Unit testing is a particularly important tool in catching a failure to meet software specifications. In the case of TDD techniques, they can even help define software specifications.

    As for the person you were talking to, unit testing isn't new. It's older than dirt, as old as software development. But only recently it did get mainstream attention. The problem isn't with him, or students, or teachers, or developers in general. The lack of comprehension of the value of unit testing is mostly the fault of its advocates who like to push the concept as in those afternoon infomercials that are guaranteed to save your life, make you happy and live healthier. The popularist and dishonest push towards Agile development, which is guaranteed to not be an ideal solution in every case, has muddled the waters and created the confusion in many people's heads that the *very* old practice of unit testing cannot be dissociated from such practices as Agile development or even TDD. Which is not the case.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #12
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Oh my God... I am the problem...

    So... What's a good way to convey to someone who doesn't see the value of testing that there is value in testing? The lesson was only really instilled in me because it was basically forced on me.

  13. #13
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by MutantJohn View Post
    Oh my God... I am the problem...
    Seriously, you are not. You were advocating a time-honored best practice in computer programming and with equivalent counterparts in every engineering field.

    Again, it is important to distinguish unit tests from test-driven development (TDD) practices like Agile, Extreme or Scrum development. Unit tests form the backbone of TDD, but they don't need to be used in that context. TDD is a younger concept than unit tests and, depending on the development environment, unit tests can be used outside any sort of TDD technique. Most often that is exactly how they are used (outside of TDD).

    Quote Originally Posted by MutantJohn View Post
    So... What's a good way to convey to someone who doesn't see the value of testing that there is value in testing? The lesson was only really instilled in me because it was basically forced on me.
    I would probably tell them, outside of TDD:

    - Testing increases the time spent writing code and decreases the time spent debugging. Since the latter accounts for the the most time spent while developing, there is a net gain once a programmer masters the concepts of unit testing.
    - Unit tests are a standard industry practice. Might as well get used to them if they want to work in this field.
    - Unit tests do not necessarily need to achieve 100% code coverage. Not even 50%. Ideally they should, but common sense will dictate what parts of the code should be covered. Common sense is acquired with practice.
    - Unit tests are the best known safety mechanism for code refactoring, with the potential to greatly reduce application maintenance costs.
    - Unit tests represent a code framework that facilitate code documentation, help discipline the programmer by enforcing a divide and conquer strategy to programming, and even greatly increase the effectiveness of code source control by more easily referencing regressions, merges and forks.
    - Unit tests are of very little use in small code footprint projects, without many logical parts and with a focused behavior, that can be generally understood in its entirety by a single person in an afternoon.
    - With the above in mind, do not use unit tests if you don't want to. Use them if you do.
    Last edited by Mario F.; 03-01-2016 at 10:31 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  14. #14
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    How long is a piece of string?

    You know what though? No. Programmers don't emphasize testing enough. I think as a general statement that's fairly safe.

    EDIT: Oh... but as far as code coverage by the unit tests... hitting 100% should be the goal, really. If you can't figure out how to get code to execute with a unit test, rework the code until you can. I find this forces the architecture in good directions.
    Last edited by brewbuck; 03-07-2016 at 11:59 PM.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing 123
    By rogster001 in forum C++ Programming
    Replies: 1
    Last Post: 10-14-2010, 03:50 AM
  2. 64 bit testing
    By DrSnuggles in forum C++ Programming
    Replies: 7
    Last Post: 11-20-2007, 03:20 AM
  3. Testing Testing 123.. Oh yeah and...
    By minime6696 in forum Windows Programming
    Replies: 0
    Last Post: 08-13-2001, 09:07 AM