Comparing work in thermodynamics with work done in mechanics Let us the consider a gas as our system enclosed in a cylinder with piston.
1st case(Expansion of gas):
Here force on the piston is exerted by the gas in upward direction and during expansion piston moves up. So, the work done here is positive(force and displacement in same direction). Also the relation W=PΔV (with their usual meanings) also satisfies the "positive" sense of work, since the volume increases during expansion.
2nd case(Compression of gas):
Here, the surrounding exerts the force on the piston and compresses the gas. Since, the direction of force by surrounding on the system and displacement of piston(both downwards) are in same direction, should not the work done by the surrounding on the system should be positive?
But, W=PΔV gives -ve work, since volume decreases during compression. Why does the mechanical  concept of work and W=PΔV does not give same result?
(In Physics)We are usually told that work done by the system is positive and work done by the surrounding on the system is negative.
 
But 
 2nd picture shows exactly what I am confused with. During compression, it is the gas that does negative work not the surrounding does the work in the gas?
1st picture is screenshot of book University Physics.
2nd picture is from here.
 A: First you must notice that sign of work depends upon whom you consider as the work doer (energy converter).  When the force transfers energy to the object(i.e., the object gains some energy) a positive work is done and when it transfers from an object (i.e., the object losses some energy) a negative work is done (imagine the work done by friction). Now in thermodynamics work doer is the surrounding (i.e.  you have to consider the work done by the surrounding on the system) and hence you have to consider the energy changes of the respective system (on which the work is done). So when the system gains some energy a positive work is done and when the system losses some energy a negative work is done. 
A: Normally both results are the same for work but it is defined in another way as you wrote: $dw = -pdV$ so the work you can get by integration.
A: In mechanics as well as in thermodynamics, the work done by the system on the surroundings is equal to the force vector the system exerts on the surroundings dotted with the displacement vector.  If the force vector exerted by the system on its surroundings is in the same direction as the displacement (as, for example, when the mechanical system is decelerating), the work done by the system on its surroundings has a positive sign (and the work done by the surroundings on the system has a negative sign).  If the force vector exerted by the system on its surroundings is in the opposite direction of the displacement (as, for example, when the mechanical system is accelerating), the work done by the system on its surroundings has a negative sign (and the work done by the surroundings on the system has a positive sign).
