The reason for putting the provide
at the end rather than the beginning is the same as the reason for including the comment ;;; <library.el> ends here
at the end of the file:
If it's not there, then you know that you don't have the complete file.
The comment is the human-readable version of that, and (provide 'FEATURE)
is the machine-readable version.
Imagine if you had a truncated copy of foo.el
with (provide 'foo)
at the top, and loading it caused errors -- but due to the provide
Emacs believed it was now fully-loaded, and so subsequent (require 'foo)
did nothing to fix the problem in that session, even after you installed a corrected copy of the file.
Conversely, if (provide 'foo)
is the very last form in the file and Emacs processes it, then it is guaranteed that the entire file has been loaded as intended.