I couldn't give any strict set of partitioning rules.
Such rules are mostly related to the BIOS, the hardware architecture of the computer, the operating systems installed, ...
Therefore, several things can vary with these factors and related changes over the years.
I remind that the msdos-type partition table is just one of the partitioning schemes used in the computing. It was created for the first IBM PC in the late 1970's and still remains largely in use, although the actual computing needs often overcome its possibilities. Other partitioning schemes are used in architectures like Sun, sparc systems, power-pc etc. Furthermore, the newer partitioning scheme GPT is often used in new systems, together with the new UEFI BIOS.
Regarding the "old good" msdos-type partition table:
Maximum of 4 primary partitions.
Maximum of 3 primary partitions, and 1 extended partition.
You are right. There are 4 partition entries. The extended partition type was introduced a few years later, to allow more than 4 partitions on a hard drive. Only one extended partition is allowed in the partition table (or not at all). You can have the extended partition in any one of the 4 positions, although it is usual to have a system or boot partition in the first places.
(This is often needed in systems with very old BIOS (before mid-1990s), because at the time the BIOS couldn't perhaps boot from a partition after the cylinder 1000 (or something like this). However this problem doesn't exist since the introduction of LBA in the BIOS. GParted doesn't work on such old 386 or 486 systems, because it needs at least Pentium 2 class processor).
Can you leave unallocated space
--in front of the first primary ?
--between primaries ?
--between the last primary and the Extended ?
You can leave unallocated space in front or after any partition. This doesn't create problem. I've heard that such space could be used by malware, but I have no precise info on such questions. I think that malware can work everywhere in a badly protected system.
Do all primaries have to be at the front, and all logicals after them ?
Or could you put a primary at the end some how, after the Extended partition.
See before. Each one of the 4 partitions is defined as it self, not in relation to the others.
Nevertheless, there are issues concerning the logical partitions (as follows).
Can you leave unallocated space
--at the beginning of the Extended partition ?
--between logicals ?
Yes, you can. BUT you can't freely use these unallocated spaces to create new logical partitions.
Better said: you can perhaps but I wouldn't recommend it.
In detail: It is better and safer to have all logical partitions in the disk order within the extended partition, i.e. /dev/sda5, /dev/sda6, ...
Avoid to have sequences out of order, like /dev/sda6, /dev/sda7, /dev/sda5 ...
Some partitioning tools allow these out-of-order logical partitions, but some other tools (including parted and GParted) don't support it.
If you want to create a new logical partition, it is better to have the space after the last existing logical one. So, I think it is easier to not leave unallocated between logical partitions, unless you want to grow some of them in a later time.
This is related to the specificity of the extended partition structure: each logical partition contains a link to the next logical. Out of order logical partitions often cause parted to find an error for the entire partition table and show the entire hard drive wrongly unallocated. It isn't easy to fix this problem.
Anything else I haven't thought of that comes to mind ?
Older systems (including win xp and same generation's linux distributions) use the cylinder alignment for the partitions. This comes from the legacy BIOS and hard drive firmware, that simulate the cylinder model of the early 1980's hard drives.
Late systems (including recent linux distributions and win7) usually default to the MiB model. This alignment is better for SSD drives and the latest generation of rotating drives ("advanced format" from western digital and similar formats from other manufacturers).
To work on an existing system, it is usually recommended to respect the existing alignment (to be verified from the fdisk -lu command output).
*** It is highly recommended to backup any important files before doing resize/move operations. ***