This code snippet wasn't exactly "handcrafted," but rather automatically produced by the Script Listener plugin in Photoshop.
Although not all features of the Photoshop API are officially documented within the object model, they can still be accessed with some workarounds. By installing the script listener plugin and executing actions in Photoshop, you can reveal these undocumented functionalities. The code generated by the script listener will mirror the steps you take in Photoshop.
For instance, even though there may not be direct methods or properties for certain objects like Brush, utilizing the script listener allows you to manually adjust settings in Photoshop and receive functional yet somewhat cryptic code snippets. Be cautious with your actions as the script listener captures everything, making it challenging to pinpoint specific methods amidst a flurry of recorded activities.
In my experience, I typically resort to using the script listener as a final option when dealing with hidden functionality in the Photoshop API. Just because a method or property isn't explicitly outlined doesn't mean it's unavailable. Hopefully, this sheds some light on navigating the intricacies of Photoshop scripting.