Can [I] include small chunks of code (say 10 or 20 lines) from other sources [without respecting the license] if there is really not a better way to write it?
The simple answer is No. If you copy code and that code is protectable by copyright, you must adhere to its license. There is no specific amount of code as a number of lines that would say whether a piece of code is copyrightable or not. As an example, suppose the program you copied looked like this:
printf("Hello, world!\n");
printf("Hello, world!\n");
printf("Hello, world!\n");
printf("Hello, world!\n");
printf("Hello, world!\n");
printf("Hello, world!\n");
printf("Hello, world!\n");
printf("Hello, world!\n");
printf("Hello, world!\n");
printf("Hello, world!\n");
Suppose you copied these 10 lines, and then decided it is better to express this repetition using a for loop and a variable i to keep track of the iteration number:
for (int i = 0; i < 10; i++) {
printf("Hello, world!\n");
}
If the 10 lines were copyrightable, you've still copied the 10 lines and produced a derivative work. Rewriting it as a for loop, and the fact that it is now 3 lines long, does not change this. However, for this example it's not likely that the example is copyrightable. It is not original and there are only a few ways to print the string "Hello, world!" ten times.
But suppose the ten lines were this:
printf("It was the best of times,\n");
printf("it was the worst of times,\n");
printf("it was the age of wisdom,\n");
printf("it was the age of foolishness,\n");
printf("it was the epoch of belief,\n");
printf("it was the epoch of incredulity,\n");
printf("it was the season of Light,\n");
printf("it was the season of Darkness,\n");
printf("it was the spring of hope,\n");
printf("it was the winter of despair,\n");
Is it copyrightable? It appears to be an original expression and creative. You may recognize the words as a copy of a portion of a work by Charles Dickens. The fact that I wrote it as C programming statements does not change that I took it directly from the famous work, even if I have memorized these 10 lines and recited them from memory. In this case, the work is now in the public domain so no copyright infringement is possible. Even if it were still protected by copyright, you could make an argument that I am using it as a fair use or fair dealing if applicable. But that would depend on the reason for copying, the effect on the market by my copying and so on.
Can I copy the general concepts being used as to how the windows are laid out?
Concepts are not copyrightable. They may be patentable though. Algorithms are generally not copyrightable, but a specific implementation of an algorithm is. Here is a famous one:
def gcd(A, B):
if B == 0:
return A
else:
return gcd(B, A % B)
It is an implementation of Euclid's algorithm for computing the greatest common divisor written in Python syntax. As an example, if you write your own implementation of Euclid's algorithm in another language, or if you write your own implementation in Python and it happens to be exactly the same as mine, you have almost certainly not infringed my copyright on this implementation. How many ways really exist to write Euclid's algorithm? You could write it recursively as it was done here, you could write it iteratively, you could change the names or syntax and so on. Ultimately there are very few ways, so this is an example of something that you could use without worrying about copyright. But if you consider all the computer source code that exists, the vast majority is probably not like this, so you have to assume it is protectable unless you have a reason to believe otherwise.
Can I use the same or similar name for my variables?
Names are not copyrightable. That said, if your idea is to copy code and change all the names of variables, don't do that, as it won't work.
If I obfuscate someone else's source code, can I avoid copyright infringement?
If you copy a work and change all the names, you've still made a copy (a derivative work). Look at the above gcd example. If you decide to name 'gcd' something else, or name the variables something other than 'A' or 'B', you've still made a derivative work. Of course, in that example, it doesn't matter. But for a larger example, simply changing all the names to try to pretend that you aren't copying someone else's work will probably become fairly obvious if someone looks closely.