Choosing a Connector, and Living With It
M12 is not one thing. Coding, contact plating, mating cycles and whether the operator can feel the thread in the dark all decide whether the connector is a detail or the reason the line stopped.

Ask three engineers what connector a sensor should use and two will say M12 and the third will ask which one. The third is right. M12 describes a thread size. Everything that matters about the connection — how many pins, what they carry, whether it will mate with the cable someone brings, how many times it can be unplugged before the contacts degrade — is decided by choices made underneath that name.
Coding comes first, and it exists to stop people plugging the wrong thing together. A-coded is the general-purpose sensor connector. B-coded carries fieldbus. D-coded is Ethernet at 100 Mbit, X-coded is Ethernet at gigabit and above, and there are S, T and K codings for power at various voltages. The keying is mechanical, so a D-coded plug will not go into an X-coded socket, and that is the whole point. It also means a stores cupboard full of "M12 cables" is not a stores cupboard full of anything useful until someone reads the codes.
Mating cycles is the specification that gets ignored until it bites. A typical industrial circular connector is rated somewhere between one hundred and several hundred insertions. That sounds generous for a sensor cable that gets plugged in once. It is not generous at all for a tool changer, a quick-change fixture, a test rig or any position where an operator disconnects something every shift. Gold plating buys more cycles than tin and costs more; tin is fine for a connection made once and left alone, and it is the wrong choice where someone is going to handle it daily. Worse, a worn contact does not fail cleanly. It goes high-resistance, which on a 4-20 mA loop shifts the reading and on a digital line produces exactly the intermittent nobody can find.
IP ratings on connectors carry a condition people forget: the rating applies when mated and correctly tightened. An M12 done up finger-tight is not IP67, and an unmated socket without a cap is not anything at all. On a washdown line this is the single most common source of water ingress, and it is the reason protective caps on spare ports are not optional hardware even though they always seem to be missing.
Then the human factors, which decide whether the connector survives contact with a plant. Can it be mated by someone wearing gloves, in the dark, at arm's length behind a machine, without cross-threading? Screw-locking connectors are secure and slow and easy to cross-thread; push-pull connectors are fast and less tolerant of side load. Is the marking still readable after two years of coolant? Is there room to get a hand in, or does mating require the guard to come off? These questions sound trivial in a design review and they are the ones that determine whether a maintenance technician at two in the morning gets the machine running or damages something trying.
A few practical rules that repay themselves. Standardise on as few variants as the application allows, because every extra type is another line in the spares list and another chance of a wrong cable arriving on a Friday. Buy pre-made moulded cordsets for anything exposed to liquid rather than field-assembling connectors, since a moulded assembly is watertight by construction and a field-assembled one is watertight by the care of whoever assembled it. Where a connection genuinely must be field-assembled, budget for the right tool and the training to use it.
And label both ends. It costs nothing, and it is the difference between a five-minute reconnection and an hour of continuity testing when a panel has been opened by someone who did not build it.