229. Where a judge convicts a defendant of an offence, he shall impose upon him a sentence within the limits prescribed by law, taking into account in particular the special circumstances relating to the offence or to the defendant and any period of detention served by the defendant in respect of the offence.