Define constants/code per device (or device family) - like resources do support

I want to be able to define some constants (and eventually even code) for special devices. Can this be done?

E.g. you can define resources inside folders like "resources-round-280x280" and similar.

My code may need a constant for a calculation based on the device or even a custom function - can any of this be done? Of course I can pass in the device name and/or the device size to my function but I wonder if there is something better?