What does shorting the diodes pins do? And wont that be dangerous ?
No, it sounds dangerous unless you understand what the purpose is. The way that a high voltage potential will damage a laser diode is by disrupting the ion distribution within the region of the PN junction. This requires a potential difference ACROSS the junction. If the entire diode or even the entire can is at a potential difference from its surroundings that does not matter. So, by shorting or in gentler terms, contacting the leads of the laser to each other, you prevent this potential difference from existing across the sensitive PN junction within the laser.