Use Short Functions

Keep your functions short and focussed. Avoid deep nesting!

This is good advice for any programming language. Complex or deeply nested functions can quickly become confusing and difficult to manage. Instead of nesting multiple levels of logic within a single function, break the logic into smaller, separate functions. This will:

Example: Writing a Mapping Function

You don’t want to map one ‘node’ to another.

  • It is hard to reuse these mappings. If the PID segment was in a different spot in the message grammar say under a group called “PATIENT” then we have to define all the same mappings again.

  • It results in repetitive long code.

This code is poor practice:

im.webp

A better structure is like this:

  • The MapPID function is modular and consice.

  • The mappings can be re-used from any context where a PID segment needs to be mapped into the patient table.

im2.webp