In a sentence: It sucks.
In more sentences: If anybody has ever done some automation in any other DCC package such as Nuke, Houdini or even Maya, the bitter taste of contempt forms when looking at photoshop's options to build workflows. Advice to the general management at Adobe: Please send the Photoshop devs on a paid vacation until they're old and just acquire another company and start over. Sorry, rant done. feeling better now.

ScriptListener

For anything remotely sophisticated you will need the ScriptingListener plugin (see here). Drop it in your PS Plug-ins folder and cat ~/Desktop/ScriptingListenerJS.log (yes, it really saves the log there by default) - then do something and hope it outputs some stuff there. Gone are object-oriented methods, as most of the stuff (like referencing layers) must be done by name (string).

JS

In HTML, you could organize your functions in different files - in pure JS there are no includes. So if you want to share work, you have to bang together that functionality with evil eval.

poor man's include in JS:

function include(filename){
    var b = new File(filename);
	b.open('r');
	var filecontent = "";
	while(!b.eof)
	filecontent += b.readln();
	b.close();
    eval(filecontent);
}

include('myfile.jsx');

Store settings

You can abuse the app.activeDocument.info storage to save values to the document and retrieve them later. I'm sure there's a better way, but hey.

app.activeDocument.info.author = "some value";

For more advanced stuff, have a look here.