@MaximeV
I'm not sure why you're asking this question from a software perspective as it is really a hardware issue.
You want to protect the pins from ESD spikes (when somebody ungrounded is handling the board) as well as make sure you don't get unexpected voltages on the pins that leads to extra current draws.
Personally, for all the pins that can be turned into GPIOs, I configure them as digitial inputs and tie them to Vss (GND) through a 100k resistor to provide a ground path. For analog pins that can't be configured as digital inputs, I tie them to Vss through a 100k resistor. The remaining pins which can't be made into inputs or are not analog pins I generally leave floating or look to the datasheet for manufacturer specified connections.
I'll be interested in hearing other people's comments on this. I know some people who set pins to digital outputs at a set value (high or low) with no 100k ground path resistor.
An important reason for putting a 100k resistor on every pin is a practical one; when you want to or need to experiment the PCB and you need more IO pins, you have a convenient pad on the unused pin that you can solder a fly wire to. So, even if you don't plan on using the resistor, still put in part and DNP it.