Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the good code that every programmer should learn

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "what is the excellent code that every programmer should learn". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what excellent code every programmer should learn.

A few years ago, when I was looking at the Python code, I suddenly found some source files written in C and checked the implementation of the GNU C compiler collection. I found that this advanced C language compiler was written in C. Learning the internal structure of things and in-depth understanding can subvert our cognition and learn a wealth of knowledge. Developers in the past have created a peaceful world for modern developers through their own hard work. As modern developers, we should thank them for their excellent work.

When I browse the Github code base, I notice that developers everywhere have completed the following masterpieces.

Apollo 11 Navigation computer (AGC)

Apollo 11 successfully landed man on the moon for the first time. Only the Apollo Navigation computer (AGC) with 4KB physical memory completed the control of the spacecraft. AGC's software is written in AGC assembly language and stored in a special read-only memory called magnetic core memory (ropememory). Someone previously uploaded a scanned copy of the source code to Internet. These modules are then converted into text files and uploaded to the Github code base.

Code snippet in the AGC moon landing module, screenshot by the author

The Apollo engineering team made a great effort to write a lot of assembly code to achieve such amazing results. Programming was much more difficult in the 1960s than it is now. Because at that time, programming languages were mostly low-level languages, requiring direct operation of the hardware. Therefore, programmers must write carefully optimized code to improve the efficiency of hardware use.

Hammer of Thor III Arena

The III-- Arena of Thunder Hammer is a first-person shooter developed by id Software. It was developed in the 1990s, when the 3D game industry began to rise with the advent of game engine technologies such as id Tech4. Unlike now, hardware resources were very limited at that time. Therefore, game developers must write carefully optimized code to achieve the rendering of graphic elements. Many game programming need to achieve vector normalization, which puts forward the need for square root reciprocal operation. As mentioned earlier, developers must choose the most efficient algorithms for these tasks related to graphical computing. As a result, the Raytheon Hammer III-- Arena development team uses a very clever method for reciprocal square roots, such as the following bit level calculation.

Fast algorithm of square root reciprocal in Raytheon Hammer III Arena, screenshot by the author

The level of optimization of this code and the fact that such excellent computer games were developed in the 1990s are really surprising. Today, game developers usually do not need to deal with this level of computation because physical functions are already implemented by the game engine.

GNU compiler code set

C language is the ancestor of high-level programming language because it is very close to hardware and provides good readability. As a compiler of the C language, GNU is self-booting. In other words, it is a C language program that applies the concept of compiler boot. This file in the GNU compiler code base on Github is the longest C source file I've ever seen (there may be longer C source files than this, but I haven't seen it).

The source file of the parser in the GNU C compiler has more than 20,000 lines of code. The author takes a screenshot

Chromium

Many popular Web browsers (such as Google Chrome,Microsoft Edge and Opera) are based on Chromium open source projects, which have two main dependencies: 1) the Blink rendering engine. It is a branch of the WebCore library, which is developed by the Webkit team based on KHTML/KJS; 2) the v8 JavaScript engine. The engine was developed by the Chromium team. There is no doubt that the Chromium code base is very large and relies on many third-party modules, such as gRPC and Skia. However, the Chromium team organizes all the components in a very elegant structure. They wisely separate the user interface from the internal functions to improve the maintainability of the entire project.

The directory structure of the well-divided abstraction layer of ChromiumUI components, screenshot by the author

In addition, this code base also contains the source code of Chromium Android and iOS mobile applications. The division of a large-scale cross-platform application directory structure can be a bit complex. However, Chromium does a great job of dividing the code directory structure of different platforms for Linux,Windows and Mac.

Gitk

Today, almost every software development team uses Git for code history and version management. Git was originally developed by LinusTorvalds, the founder of the Linux kernel. Indeed, Gitk's source file is a magical module in the Git code. Gitk is a GUI application that allows us to visually browse historical submission records. We can use the following CLI command to compare the difference between the two commits.

$git diff

However, with the visual presentation of Gitk, we can more quickly understand the differences between different submissions. There is only one file for the entire source code of Gitk. It is written in the Tcl scripting language using the Tk UI toolkit (an extension to Tcl). It implements the entire GUI application through only one source file, and chooses a dynamic programming language to greatly speed up the development of GUI applications.

Gitk is implemented by a single source file of about 12,000 lines of code

At this point, I believe you have a deeper understanding of "what excellent code every programmer should learn". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report