捍卫Matlab代码
In Defense of Matlab Code

原始链接: https://runmat.org/blog/in-defense-of-matlab-whiteboard-style-code

尽管MATLAB存在历史久远和许可及封闭生态系统等问题,但它在航空航天和汽车等行业的研发中仍然至关重要,因为它与数学符号的语法高度相似——作者称之为“白板风格代码”。这意味着方程可以直接转换为代码,具有高密度、视觉相似性和最少的额外元素,从而减少了从数学概念到可执行逻辑的“转换损失”。 这种直接性不仅仅是出于便利,更是一种安全特性。资深工程师在验证复杂计算时,可以轻松地将代码与原始推导进行比较,当代码*看起来*像数学公式时,更容易发现错误。此外,这种清晰的语法还有助于编译器优化。 核心问题不在于语言本身,而是MATLAB过时的运行时环境和商业模式。一个名为RunMat的新项目旨在通过为MATLAB风格的语法提供现代、开源的运行时环境来解决这个问题,从而提供可移植性、硬件加速和云集成——在拥抱现代软件基础设施的同时,保留工程师们宝贵的“白板代码”体验。最终,无论技术如何发展,对能够反映数学复杂性的工具的需求将持续存在。

## RunMat:对MATLAB遗产的新解读 这次Hacker News讨论围绕一篇为MATLAB代码辩护并介绍RunMat的博文展开,RunMat是一个新的开源运行时,旨在复制MATLAB的优势,同时解决其弱点。尽管MATLAB在数值计算领域仍然很受欢迎,尤其是在Simulink等工程领域,但其成本、闭源性质和许可问题是显著的缺点。 RunMat旨在提供一种快速、开源的替代方案,专注于用Rust构建的现代运行时,具有激进的融合和CPU/GPU执行能力。 许多评论员强调Julia是一个强大的竞争对手,提供相似的性能并解决MATLAB的局限性。 另一些人指出Octave是一个现有的开源选项,但RunMat开发者认为其架构阻碍了性能优化。 主要争议点包括MATLAB的矩阵为中心的方法、有时笨拙的语法以及将其集成到现代CI/CD管道中的困难。 虽然有些人为MATLAB全面的工具箱和既定工作流程辩护,但许多人对它的许可和核心算法缺乏透明度表示沮丧。 RunMat希望提供MATLAB数学语法的便利性,以及现代运行时的速度和开放性。
相关文章

原文

The issue was never the syntax—it was the runtime. Why readable math still matters in a world aided by LLM-assisted code generation

The enduring relevance of MATLAB in modern engineering

If you look at the most preferred language list on any Stack Overflow developer survey, you will usually find MATLAB hovering near the bottom. It sits there alongside VBA and COBOL, often dismissed by modern software engineers as a dinosaur. You have probably seen the memes: complaints about license manager errors, the massive install size, or the feeling that it is a language strictly for "old-school academics.”

The world has moved toward open source, containerization, and agile cloud deployments. In that context, a closed ecosystem feels restrictive.

But if you walk into the R&D departments of top aerospace, automotive, or medical device companies, MATLAB is still everywhere. It isn't there because these engineers don't know better. It is there because, for a specific type of work—linear algebra, signal processing, and control theory—MATLAB did one thing better than almost anyone else:

It made the code look exactly like the math on the whiteboard.

We need to separate the language syntax (which is excellent) from the runtime and business model (which are dated).

What is "whiteboard-style code"?

Engineer copying matrix equations from a whiteboard into MATLAB-style code on a laptop.

When I say "whiteboard-style code," I am referring to a specific level of abstraction. In engineering, the "truth" is derived on a whiteboard or a notepad. That is where the physics is worked out. You draw matrices, you transpose vectors, and you define relationships ($F = ma$, $V = IR$, $Y = Hx$). The goal of engineering software is to translate that whiteboard truth into executable logic with as little "translation loss" as possible. "Whiteboard-style code" means:

  1. High Density: One line of math equals one line of code.
  2. Visual Similarity: The code visually resembles the equation.
  3. Low Boilerplate: No memory allocation logic, no type declarations, and minimal imports. For vectors, matrices, and arrays, MATLAB’s syntax is often the shortest distance between the board and the running code

The translation test: board vs. code

Let’s look at a concrete example. Imagine you are sketching a simple linear algebra operation during a lecture or a design review.

In MATLAB: The code is almost a direct transcription of the board:

X = [1, 2, 3];
Y = [1, 2, 3; ...
     4, 5, 6; ...
     7, 8, 9];

Z = Y * X';      
W = [Z, Z];      

In Python (NumPy): Python is an incredible language, and NumPy is a powerhouse. But notice the cognitive load required to handle the shapes explicitly:

import numpy as np

X = np.array([1, 2, 3])
Y = np.array([[1, 2, 3],
              [4, 5, 6],
              [7, 8, 9]])



Z = Y @ X.reshape(3, 1)


W = np.concatenate([Z, Z], axis=1)

The math is identical. But in the Python version, the engineer is thinking about computer science concepts: imports, methods, tuples, and axes. In the MATLAB version, the engineer is thinking about linear algebra: rows, columns, and multiplication.

Why readable math is a safety feature

Why does this subtle difference matter?

In mission-critical fields, code review is safety review.

Senior engineers and Principal Investigators perform these reviews. These are brilliant people who understand the physics deeply, but they may not be experts in modern software design patterns. They don't want to parse decorators or understand the nuances of an object-oriented class hierarchy.

When they review code, they are holding their derivation notes in one hand and looking at the screen with the other. They want to verify that step A leads to step B.

  • "Here is the rotation matrix."
  • "Here we apply the filter."
  • "Here we calculate the error."

MATLAB’s syntax allows them to verify the math without getting bogged down in the implementation. When the code looks like the math, bugs have fewer places to hide. The syntax itself reduces the cognitive load, allowing the reviewer to focus on the physics rather than the programming.

MATLAB code review

It's not just for humans (compilers love it too)

There is a misconception that "simple syntax" means "slow interpretation." Actually, high-level array syntax gives runtimes and compilers excellent signals for optimization.

When you write C = A * B in a vectorized language, you are giving the runtime a very high-level instruction: "Perform a matrix multiplication on these two objects."

Because the language constraints are strict (matrices have defined shapes, types are usually consistent), a modern runtime can:

  • Immediately infer the shapes of the result.
  • Fuse multiple element-wise operations into a single pass through memory.
  • Offload the entire chunk of work to a GPU without the user writing a single line of CUDA kernel code.

The structure that makes it readable for humans also makes it predictable for machines.

The honest truth: why the hate exists

If the syntax is so good, why is the sentiment so mixed?

To be fair, the backlash against MATLAB is largely justified. The frustration usually stems from three areas, none of which have to do with the math syntax itself:

  1. The "Black Box" Runtime: The engine is closed source. You cannot see how fft or ode45 are implemented under the hood. For high-stakes engineering, not being able to audit your tools is a risk.
  2. Licensing Pain: Everyone has a story about a simulation crashing because the license server timed out, or not being able to run a script because a colleague "checked out" the toolbox token.
  3. The Cloud Gap: Modern engineering happens in CI/CD pipelines, Docker containers, and cloud clusters. Integrating a heavy, licensed desktop application into these lightweight, automated workflows is painful.

This friction pushed a generation of engineers toward Python, not because they preferred writing np.concatenate, but because they needed tools that played nice with the modern stack.

MATLAB meme

A vision for a modern "whiteboard" runtime

The solution isn't to abandon the syntax that engineers love. The solution is to build a new, modern engine to run it.

We need a runtime that preserves the dense, array-oriented notation but operates like a modern piece of software infrastructure. It should be:

  • Open and inspectable: No black boxes.
  • Hardware agnostic: It should run on CPUs or GPUs without changing the code.
  • Portable: It should run in a Docker container or a web browser.

We should keep the language surface that mimics the whiteboard, but swap out the engine for something designed for the era of cloud computing and massive datasets.

Keeping the math, changing the engine

This is exactly why we are building RunMat.

Our team realized that the problem wasn't the .m files—it was how they were being executed. RunMat is a new, high-performance runtime designed to execute MATLAB-style syntax. It targets modern hardware (CPUs and GPUs) and integrates seamlessly into cloud and CI workflows, all without the traditional licensing headaches.

It allows teams to keep their "whiteboard code" while gaining the performance and portability of a modern software stack.

Conclusion

Technology trends come and go, but the laws of physics and mathematics don't change.

Engineers working on the next generation of renewable energy grids, autonomous vehicles, and medical robotics need tools that respect the complexity of their math. They need code that can be written, read, and verified by experts who care more about differential equations than software dependencies.

The future doesn't need to copy the business models of the past. But it should absolutely keep the best part of the legacy: code that looks like the math on the board.

Enjoyed this post? Join the newsletter

Monthly updates on RunMat, Rust internals, and performance tips.

Ready to try RunMat?

Get started with the modern MATLAB runtime today.

联系我们 contact @ memedata.com