Are there any tips that can help me create clean code when I'm working with something poorly documented and completely new to me?
It is easy to write a clean code when we are writing something for the second time. However usually problems we are approaching are new to us.
Let's say we're working with a poorly documented library: we have created our first, well-designed implementation, but after compiling it appears it doesn't work. We find some quick fix on the forum and paste it. It still doesn't work, so we are quickly searching for another code snippet to paste. Some time after our clean code is full of quick solutions taken from the Internet.
In the end, our program starts working. We look again at our code and it looks obnoxious - one big procedure full of "temporary" solutions we applied while trying to make it work. We've got two choices: rewrite everything from the scratch hoping that refactored code will work, or leave it as it is since it is working. In most companies, the second approach is taken, at least until more tutorials for the library are released.
Sometimes we don't have a possibility to debug every single line we're adding. Also when we are working with the badly documented library, usually we need to guess which part of code made our program work. I'm having the biggest problems when providing engineering solutions when debugging is really time-consuming, since you need to launch the program on a real device.