"Things interact with the other things to receive things."
Semantics are an important next step into learning how to structure code. They can clarify why something is in a specific place and the purpose it serves. Code semantics benefit both developers and end users. We will cover how it benefits the developer (you!) today, as inclusive design with semantics for content accessibility is a broad topic on its own.
For developers, code semantics are incredibly useful for building implicit structure. Names of functions, variables, and files are a prominent part of code semantics. Naming schemes can and should accurately describe what a function’s purpose is, where it sits in the entire codebase, and potentially even how it should be used, so any developer will quickly get a good idea of what is going on.
AnimateForms (cross promo!) is an example of code that uses naming semantics to its advantage. It must expose different animations, easings, and helpers for developers to use. In this library, these functions are split into the Animate, Easings, and Helpers classes respectively. All Animate functions are named with the precise action they do and take similar arguments to all other animate functions. All Easings functions start with the easing type, then “in” and/or “out”, resulting in an easing like “QuadInOut.” Consistency and shared attributes like names and parameters in AnimateForms make it easy to understand and work with. Once you know how one thing works, you know how the rest of it works.
Because of this defined and consistent naming scheme (sometimes called a “pattern” in development), it is also incredibly easy to make additions to this library. Not only do the code semantics help the users of the library, they also help the author of the original code maintain it without creating messes of unclear documentation and comments.
This is not to say that well-structured and semantically correct code is a replacement for comments and documentation. It is simply a supplement; Documenting and commenting complex code only helps further understanding of what a certain piece of code does and what role it plays and is essential for best coding practices (especially in team environments).
Learning proper code semantics can seem like a waste of time to new developers coding solo and for small projects. However, it is an essential best practice and aspect of the overall code structure by helping keep code maintainable, extensible, and usable to you and other developers, so it is a habit worth developing early.