When I first learned thermodynamics, I encountered new concepts such as state variables (e.g., energy), non-state variables (e.g., work and heat), and perfect versus imperfect differentials. This really confused me. Is there a deeper rationale, and what is the underlying mathematical logic? And how is this related to electrostatic potentials and conservative electric fields? I think there is a simple way to explain this.