← 返回综合新闻
Engadget 综合新闻 2026-11-15 03:30

许多键盘上“1”左边的键对于程序员来说实际上至关重要

That key left of '1' on many keyboards is actually crucial for programmers

位于“1”键左侧的简陋波形符 (~) 符号有一些值得注意的用途。它可以表示近似值,这在数学和统计学中很有用,并且在西班牙语和葡萄牙语等语言中用作字母的重音。当拼写“mañana”之类的内容时,您可能花了一些时间在键盘上寻找它。然而,它在计算机键盘上的主要用途是作为 C、C++ 和 Java 等编程语言的工具。

这实际上是一把方便的小钥匙,可以追溯到几十年前。它最早出现在计算机键盘上可以追溯到 1965 年,当时是大型机的时代。从那时起,它已成为现代键盘的中流砥柱。符号的含义完全取决于编程语言,甚至游戏开发人员也发现了它的多种用途。让我们了解一下程序员使用波浪号的用途。

这可能是编程时波浪号最常见的用法,因为这种方法在 Javascript、C、C++、Python 和其他几种计算语言中都是相同的。按位 NOT 运算符(是的,就是这样拼写的)反转二进制数的所有位。这意味着所有零都变成一,所有一都变成零。例如,“0010”将变为“1101”。

这在优化系统时是一个福音,并且在生成老式视频游戏图形时实际上被大量使用。这是一种快速但肮脏的自动反转颜色的方法。它还用于索引文件并查找字符串中丢失的元素。编码人员可以通过多种方式依赖此工具,具体取决于特定的编程语言。它甚至可以用于将数字(例如“5”)翻转为其等价的二进制数字。

甚至还有一种称为双按位 NOT 运算符的东西,它用两个并排的波形符表示。这通常用于截断小数。

使用 C++ 或 C# 的程序员倾向于依赖称为类析构函数的东西。这是一个特殊函数,在删除对象时运行。它主要用于清理资源,这有助于释放分配的内存。一般来说,这是通过在要删除的对象或类的名称之前弹出一个波形符来完成的。

当对象退出玩家的视野时,视频游戏程序员倾向于使用类析构函数来释放内存。这包括敌人、射弹甚至用户界面窗口等内容。析构函数消除纹理缓冲区、物理引擎以及与已删除对象相关的任何其他内容。

可以想象,如果没有这个工具,大型开放世界游戏将会陷入困境。当玩家在世界各地移动时,对象会不断被删除。如果没有类析构函数,大量的游戏内资产将继续占用内存,即使它们没有出现在屏幕上。这会让一切运行得像糖蜜一样慢。

CSS 程序员经常使用称为通用同级选择器的东西,它是由波浪号引发的。简而言之,这个过程会自动选择波浪号后面的所有匹配元素。这使得人们可以针对代码的特定部分,即使它们并不直接相邻,从而允许批量更改。这与相邻同级选择器不同,相邻同级选择器仅选择紧接在“+”符号之后的元素。

通用同级选择器有多种用例场景,其中大多数涉及更改用户界面、网站或 Web 应用程序的视觉元素。它在传统视频游戏开发中并不流行,因为大多数引擎不使用 CSS 来进行核心游戏逻辑或渲染,但它经常出现在基于 Web 的游戏中。程序员在游戏启动器、商店页面和设置菜单方面也发现它很方便。同样,这是因为它用于快速改变视觉风格。

原文(English)

The humble tilde (~) symbol, which is located left of the "1" key, has a few notable uses. It can represent approximations, which is useful in mathematics and statistics, and is found as an accent over letters in languages like Spanish and Portuguese. You've probably spent some time hunting for it on a keyboard when spelling stuff like "mañana." However, its primary use on a computer keyboard is as a tool in programming languages C, C++ and Java, among many others.

This has actually been a handy little key going back decades. It first appeared on computer keyboards all the way back in 1965, back in the days of massive mainframes. It has since become a mainstay of modern keyboards. The meaning of the symbol depends entirely on the programming language, and even game developers find a variety of uses for it. Let's get into what coders are using the tilde for.

This is likely the most common use of the tilde symbol when it comes to programming, as this method is the same in Javascript, C, C++, Python and several other computing languages. The bitwise NOT operator (yes it's spelled that way) inverts all the bits of a binary number. This means that all zeroes become ones and all ones become zeroes. For instance, "0010" would become "1101."

This is a boon when optimizing systems and was actually used a lot when generating old-school video game graphics. It was a quick and dirty way to automatically invert colors. It's also used to index files and find missing elements in strings. There are many ways in which coders rely on this tool, depending on the specific programming language. It can even be used to flip a numerical digit, like "5", to its binary equivalent.

There's even something called a double bitwise NOT operator, which is represented with two tildes standing side by side. This is typically used to truncate decimals.

Programmers using C++ or C# tend to rely on something called a class destructor. This is a special function that runs when an object has been deleted. It's primarily used to clean up resources, which help free allocated memory. Generally speaking, this is done by popping a tilde before the name of the object, or class, that will be deleted.

Video game programmers tend to use class destructors to free up memory when an object exits a player's field of view. This includes stuff like enemies, projectiles and even user interface windows. The destructor eliminates texture buffers, physics engines and anything else connected to the deleted object.

As you can imagine, large-scale open-world games would struggle without this tool. Objects are constantly deleted as a player moves throughout the world. Without class destructors, massive in-game assets would continue to hog the memory even when they aren't present on the screen. That would make everything run as slow as molasses.

Programmers in CSS often use something called a general sibling selector, which is instigated with a tilde symbol. Simply put, this process automatically selects all matching elements that follow the tilde. This lets people target specific parts of the code even if they aren't directly next to each other, which allows for batch changes. This differs from the adjacent sibling selector, which only selects the element that comes immediately after the "+" symbol.

There are several use case scenarios for a general sibling selector, most of which involve changing the visual elements of a user interface, website, or web app. It's not popular in traditional video game development, because most engines don't use CSS for core game logic or rendering, but it is often found in web-based games. Programmers also find it handy when it comes to game launchers, store pages and settings menus. Again, that's because it's used to quickly change up the visual style.

本文为自动翻译,可能存在偏差,请以原文为准。发布于 2026-11-15 03:30

阅读原文 ↗https://www.engadget.com/2309616/that-key-left-of-1-on-many-