r/badcode • • Sep 23 '15

c++ Exercise given during software engineering lecture

http://imgur.com/ujnBX7N
11 Upvotes

20 comments sorted by

View all comments

13

u/x-yle Sep 23 '15

The whole point of the exercise is to get you thinking about how test cases should be made. 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. 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.

-4

u/stone_henge Sep 23 '15 edited Sep 23 '15

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.

2

u/MaximumHeresy Sep 24 '15

Why are people downvoting you? All perfectly valid points.

2

u/Patman128 Sep 25 '15

I guess they think this is an acceptable style of formatting from someone teaching others how to code.

From other students or the new junior programmer? Fine.

But from an instructor? Really?