DEV Community

Wagner Mattei
Wagner Mattei

Posted on

Javascript and the meta-programming hell

Meta-programming can have multiple definitions, it is often defined with "Code Generation" or "Reflection". But I like to define it simply as "Code you didn't write, but still makes your life miserable".

Now, let’s delve into the technical aspects. In programming, we encounter implicit and explicit languages and frameworks, each offering its own advantages and disadvantages. This article aims to explore these approaches in detail, providing insights into their characteristics.

Explicit Code

Explicit code is an approach where the developer’s intent is clear, and the developer is in control of what the code they write is doing. It provides the developer with more flexibility and freedom over variables, data, and flows.

However…

In the vast expanse of freedom lies the weighty mantle of responsibility, for as the boundaries of choice widen, so too must the conscience and accountability of the liberated soul. — Chat GPT

Explicit code is often more verbose and requires the developer to possess a deeper understanding of the language or framework being used, as well as a deeper understanding of general software engineering concepts. This is why explicit languages or frameworks may not appeal to new programmers, as they typically prefer to see quick results with as few lines of code as possible.

Implicit Code

Implicit code is the exact opposite. The developer only needs to focus on the business logic, while most of the complexity is abstracted by the language or framework itself. Typically, languages and frameworks that employ this approach are highly opinionated when it comes to handling data and managing flows. It also results in less code for the developer to maintain, which can be beneficial in many cases. However, there are instances when this approach may not be ideal.

The Spectrum

Explicit and implicit are not binary definitions; they exist along a spectrum. The image below illustrates where certain languages fall on this spectrum, based on their underlying philosophy rather than the specific implementations within each language or framework. In fact, the majority of languages are flexible enough to accommodate both approaches.

The Explicit vs Implicit code spectrum

Meta-programming hell

In the image above, “meta-programming hell” is depicted as a point where the code becomes so implicit that the engineer loses control over the engineering process. At this stage, the engineer’s sole responsibility is to fill in functions or files, hoping that the language will handle the underlying tasks.

The Javascript of 2023

The JavaScript language embodies a more implicit approach due to its characteristics such as dynamic typing, loose syntax, and automatic type coercion. However, the evolving ecosystem in 2023 is pushing the language toward the realm of meta-programming hell.

While this article aims to discuss the ecosystem as a whole, it is important to highlight Vercel’s Next.js framework. Why? Because Next.js is currently garnering significant attention and Vercel plays a crucial role in steering the future of the JavaScript ecosystem.

Next.js has propelled JavaScript to a critical juncture, approaching a point of no return. It has almost transformed into a low-code tool, thereby diminishing the developer’s control and contributing to the implicit nature of the language.

Why is Next.js a meta-programming hell?

Imagine you have written a JavaScript function. As the author, you should have a clear understanding of what the function does. However, the actual execution result of YOUR function can depend on several factors:

  • What is the name of your function?
  • What is the name of the file where your function was written?
  • Does the file name include a "(" or a "[" or even a "…([{" ?
  • What is the name of the folder where the file stays?
  • What version of Next.js are you using?
  • Does the file start with 'use client' or 'use server'?

Even if you believe you are in control of all these factors, what happens when someone new joins your team and needs to fix a bug in the function YOU wrote? They can’t simply interpret the code. First, they have to familiarize themselves with the specific version of Next.js being used.

Furthermore, what if Vercel decides to release a new major version and your team decides to update? The routing system might have undergone significant changes (which it had in the past), requiring your entire team to re-learn Next.js.

The appeal of implicit code stems from the desire to code faster, deliver quick results, and create attractive landing pages in a short time. However, when it comes to engineering real products, we must consider consistency and code readability. When code becomes so complex that nobody understands what’s happening, the community often suggests, “Rewrite your entire codebase in .” But is that really the direction we want the ecosystem to go? It’s important to think about the long-term implications and find a balance between speed and maintainability. We need discussions within the community to ensure that we prioritize both productivity and the quality of our code in the long run.

Conclusion

There isn’t much to conclude from this statement. Meta-programming is indeed a valid approach that can be sensible in certain cases. However, I have a sense that the programming community has not thoroughly questioned the trajectory the ecosystem has taken. Consequently, individuals who profit from offering coding courses, often referred to as “code gurus,” are inadvertently promoting the practice of junior developers writing code without having complete control over its functionality.

It is important to foster a culture of critical thinking and accountability within the programming community. While meta-programming has its merits, it is equally crucial for developers, regardless of their level of experience, to possess a comprehensive understanding of the code they write. By maintaining control over their code and actively seeking comprehension of its behavior, developers can ensure the creation of robust and reliable software solutions.

Just think about it! (and maybe give flutter web a chance (?) IDK).

Top comments (0)