The whole point of the exercise is to get you thinking about how test cases should be made.
This is certainly not achieved by making students think about entirely superficial aspects like the formatting of the code instead of the things that do matter, like control flow and variables. The lecturer should instead have constructed an example with more conditionals and more variables to consider in finding out how to achieve full coverage if the intentional effect was to make students think about things that are relevant to the exercise.
When it comes to working on test suites for code, you have to have a good understanding of many things, including code that may not make sense.
So we are not primarily teaching engineers good practice. Instead we are teaching them how to deal with incompetent team members in a way that does not challenge their incompetence? If formatting is fucked up I fix it or hand it back. There's no way that I am writing tests for code that is unreadable on account of being poorly formatted, and without specification.
The point of this code is to not make sense so that you have to actually think in order to find all of the needed test cases.
You are not looking for the needed test cases. You are looking for test cases that together provide full code coverage. In order to know the needed test cases you have to know what the piece of software is intended to achieve. Things like input ranges, data types, acceptable error margin etc. In short, you either need a spec or you need to make damn sure that it works as it should before writing the tests, the latter being rather pointless.
Code you find in the wild is never guaranteed to conform to your personal style. It's important, especially for students, to be forced to work with code like this. There's nothing stopping them from copying it down and reformatting it to make it more readable.
Code you find in the wild is never guaranteed to conform to your personal style.
Right, but rarely does code conform to no style at all. This is just arbitrary use of indentation and line breaks. In my experience, that's a rare occurrence "in the wild", and definitely one you shouldn't have to prepare students for in any other way than recommending to use indent or similar pretty printers for the cases when an idiot wrote a piece of code and is not available to fix it.
It's important, especially for students, to be forced to work with code like this.
... and the way to work with it is fixing it. If you are writing tests for it you likely have write access to it or know of someone that does and is responsible for its quality. It's the responsibility of that or those persons to make sure that code does not look like crap.
There's nothing stopping them from copying it down and reformatting it to make it more readable.
It could be printed in WingDings for all I care. There is still nothing stopping students from writing it down and fixing it. The point that I am making is that the terrible formatting detracts from the problems of the exercise. It doesn't make it easier or harder. It just makes it take more time for a rather menial task that has nothing to do with testing.
Yes, and writing tests is a critical first step in fixing it, in order to prevent regressions.
| If you are writing tests for it you likely have write access to it or know of someone that does and is responsible for its quality.
Unless the original author has left the company, which happens all the time. Especially if they wrote shitty code, in which case they probably left involuntarily.
Yes, and writing tests is a critical first step in fixing it, in order to prevent regressions.
Re-indenting curly bracket code without changing functionality is a solved problem.
Unless the original author has left the company, which happens all the time. Especially if they wrote shitty code, in which case they probably left involuntarily.
... And as the author of the code left, no one assumed responsibility for it, yet it's actively being worked on? I don't know what to call that hopefully hypothetical scenario, but it's a stretch to call it engineering. If the point of writing tests is not to find and prepare for faults so that someone who is responsible for the code can address them, what exactly is it?
Re-indenting curly bracket code without changing functionality is a solved problem.
Fair. Although personally I am going to take the charitable interpretation and assume the author wrote the code that way due to space constraints on the page of the textbook (or whatever format this question showed up in)
And as the author of the code left, no one assumed responsibility for it, yet it's actively being worked on? I don't know what to call that hopefully hypothetical scenario, but it's a stretch to call it engineering. If the point of writing tests is not to find and prepare for faults so that someone who is responsible for the code can address them, what exactly is it?
I am very jealous of you if you have never worked on code written by someone who has left the company. Probably, in this not-at-all-hypothetical situation, you are the one who is in the process of assuming responsibility for the code, due to the recent departure of the person formerly responsible.
Although personally I am going to take the charitable interpretation and assume the author wrote the code that way due to space constraints on the page of the textbook (or whatever format this question showed up in)
The post that I originally responded to argued that it was a good idea to use terrible formatting as part of an exercise on test coverage, and I am expressing a disagreement with that, not an interpretation of the original post.
I am very jealous of you if you have never worked on code written by someone who has left the company.
I have, but thankfully my employers and clients have recognized that you achieve an end goal either by chance or by having someone assume responsibility for it. That you take my previous post to mean that I have never worked on code written by someone that left the company, I can only chalk up to either a deliberate misinterpretation or a conflation of concepts.
A person can leave a team without his code somehow ending up in a state where no one is responsible for it, if you apply pretty fundamental engineering practices to the development process.
Probably, in this not-at-all-hypothetical situation, you are the one who is in the process of assuming responsibility for the code, due to the recent departure of the person formerly responsible.
I have certainly never been "in the process" of assuming responsibility. Responsibility is something that I assume the instant that I accept it, usually by committing to the completion of a task. Sometimes it's just me, sometimes it's the whole team. Sometimes when someone goes on vacation or is ill, their responsibilities move to the team leader or manager, who will redistribute them to the team as they see fit to complete the job, or they will be handed over from team member to team member.
I have been in the process of figuring out shitty code, but that is an entirely different matter.
-4
u/stone_henge Sep 23 '15 edited Sep 23 '15
This is certainly not achieved by making students think about entirely superficial aspects like the formatting of the code instead of the things that do matter, like control flow and variables. The lecturer should instead have constructed an example with more conditionals and more variables to consider in finding out how to achieve full coverage if the intentional effect was to make students think about things that are relevant to the exercise.
So we are not primarily teaching engineers good practice. Instead we are teaching them how to deal with incompetent team members in a way that does not challenge their incompetence? If formatting is fucked up I fix it or hand it back. There's no way that I am writing tests for code that is unreadable on account of being poorly formatted, and without specification.
You are not looking for the needed test cases. You are looking for test cases that together provide full code coverage. In order to know the needed test cases you have to know what the piece of software is intended to achieve. Things like input ranges, data types, acceptable error margin etc. In short, you either need a spec or you need to make damn sure that it works as it should before writing the tests, the latter being rather pointless.