I think there may be less of a difference between the two domains than you think. Copying and pasting entire blocks of code is one way that cargo cult programming happens, but it’s not the only way. Consider the following example from C:
void main() is (or was, at least) a fairly common construction. It compiles, it executes. Many, many people learned it from their comp sci textbooks or teachers as such a basic part of How To Write C Programs™ that they don’t even think of it as something that they copied from somewhere. But they have no idea why it could be bad, because it’s something they do without understanding why. This is classic cargo cult programming.
But you’re quite right that it’s not trivial to just stop making errors of this sort. I do think it’s one of those things where just being aware of it helps. I don’t have any concrete advice beyond “think more closely about the things you say and write”, but that’s neither original nor specific to this case.
Yes, C99 specifies that main() should be of type int, and most modern compilers will flag void main() as an error. This wasn’t always the case, and some compilers may still let you get away with it.
I think there may be less of a difference between the two domains than you think. Copying and pasting entire blocks of code is one way that cargo cult programming happens, but it’s not the only way. Consider the following example from C:
void main() is (or was, at least) a fairly common construction. It compiles, it executes. Many, many people learned it from their comp sci textbooks or teachers as such a basic part of How To Write C Programs™ that they don’t even think of it as something that they copied from somewhere. But they have no idea why it could be bad, because it’s something they do without understanding why. This is classic cargo cult programming.
But you’re quite right that it’s not trivial to just stop making errors of this sort. I do think it’s one of those things where just being aware of it helps. I don’t have any concrete advice beyond “think more closely about the things you say and write”, but that’s neither original nor specific to this case.
I once had a compiler that threw up an error at “void main()” and forced me to use “int main()” instead...
Yes, C99 specifies that main() should be of type int, and most modern compilers will flag void main() as an error. This wasn’t always the case, and some compilers may still let you get away with it.