In my early physics courses we learned about how work is a state function (path independent) when a conservative force (such as gravity) is acting upon the system and a path function (path dependent) when a non-conservative force (such as friction) is acting upon the system instead.
A nonconservative force is called such because mechanical energy (kinetic and potential energy) is not conserved between the initial and final states of the system because the energy was lost as "heat." Unlike mechanical energy, heat is not a "reversible" form of energy.
Now in thermodynamics, we were told that $P_{ext}\Delta V$ work is path dependent. I don't understand why that is true. For example, let's say I put a weight onto a piston at equilibrium. The force of gravity will now act on the system. Why is the force (gravity I think) of a piston slowly compressing an ideal gas not conservative? The "potential energy" of the weight should be being transferred into the gas molecules somehow because the internal energy (I think) of the system went up because we see that the pressure of the gas has gone up.
Does it matter if the process is reversible or irreversible?
Note: Some of the potential energy also turned into kinetic energy of the weight as it moved. But perhaps we can assume that the weight moves so slowly that it gains an infinitesimal in kinetic energy.