Assuming a comment won't fit (or can't go) on the line it applies to, should one write the comment before the code or after?

Well, wherever future readers will best understand the comment's scope. In other words, wherever most programmers/scripters put such comments.

So where do most programmers/scripters put a comment: before or after its code?

If your answer applies only to specific languages, please indicate which.

And if you can cite an accepted spec or guide that supports your answer, so much the better.


Question: Programming on Raspberry Pi device?
Answer: This is largely a matter of opinion; these are two different languages with their own strengths and weaknesses.

That said, the rpi community seems very partial to python, and so you have various python libraries for doing pi (or: linux based GPIO dev board) specific things.  If you are interested in connecting I2C devices from retailers like adafruit, there is often python helper code and corresponding tutorials.

However, you don't actually need python to do any of that.  The I2C interface is a native C API (and very very simple), so if you know C, you could incorporate than into Java via the JNI, which someone else has already done (so if you don't know C, you should be able to use that).

As explained here the GPIO interface uses file nodes and is therefore in fact language agnostic: other than basic I/O, you don't need any additional libraries at all.

So there's nothing you can do in python in the pi that you can't do in java as well.  My personal suggestion, if you don't already know one of the big 3 "dynamically typed object oriented" languages -- python, perl, and ruby1 -- is to try one.   Java is great, but dynamic typing is a very interesting contrast and knowing one of those (my own preference is perl) is definitely worthwhile.

1 To be fair PHP should round that out to four, since it can be used in a general purpose way and not just for web-dev.  Javascript fits in with these too, but still isn't used much as a general purpose language and the possibilities for such are more limited.