I work in a company where OOP is... well, not fobidden, but at least frowned upon as "too complex". My coworkers write lots of 100+ lines functions and they are usually all in a "funcs.inc.php" or "something.inc.php", if they use any functions at all, often they don't since copy-paste is faster.

I would love to start using TDD at least for the code i write but as i have to interface with their code i can't see how to begin.

It's not legacy code as they are actively developing it and i don't want to modify their code as i don't want to provoke conflicts.

Which approach would you suggest, except for changing the company?

Comments

IMO, if you don't want to modify the code, it's legacy code.

Written by Arne Sostack

Can you modularise your code well enough to TDD it and still somehow fit in with the rest of the code? Also, I'd treat "OOP is too complex" as a very large red warning flag. Programming in general is a complex activity and shunning a well known and well understood powerful technique (which isn't that complex if done right) is not a good sign.

Written by Timo Geusch

Sadly i learned the "OOP is too complex"-rule after i signed the contract and moved to this city, otherwise i would have looked for another employer. I agree that OOP is not very complex if done right and i sneak it in sometimes, hoping that the others don't complain loud enough for my superior to hear it.

Written by dbemerlin

I'd say this is a place where you are never going to be happy in the corporate culture and where your current skills might even deteriorate. I'd start looking if I were you.

Written by HLGEM

@Arne Sostack totally agree, if nobody wants to change it it is legacy. I like Martin Fowlers definition of legacy code "code without tests"

flee in terror at the earliest opportunity

Written by Steven A. Lowe

If OOP is deemed too complex, writing testable code so you can pass in mock objects might blow their minds too?

Written by Greg K

Accepted Answer

I've been in that position, both in an out of actual TDD. What I normally do is write tests for other people's interfaces, whenever possible. I then know before I run my code if they did one of the many common things that people do:

  1. Broke an API by re-naming or completely doing away with something
  2. Broke an API with subtle type changes that did not get noticed
  3. Pushed a toxic revision without testing it
  4. Sprung memory leaks (my test suite is Valgrind aware)
  5. Block where they never blocked before

Any of those failing would usually result in me saying "Hey, can you check on (module), I think it broke in the last revision"

This got ugly only one time. Someone else got really upset that I was writing tests for their code and insisted that I was out for their job. I could not make the person understand that I was just out to make my job easier.

It's never a good idea to come right out and say "Look, I'm spending more time debugging your code than working on my own", unless you absolutely have to (i.e. your boss is asking about your performance). Most of the time, if you just send people the tests, they're happy to have them. If you're already meeting resistance with the idea, just try to not offend anyone or seem condescending.

Mock functions / stubs are ok, but what remains is the program as a whole is still likely to break if real tests aren't run. At least, when that happens, you can quickly rule out your stuff and (likely) point right at the problem.

Written by Tim Post
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki