哪些继承的代码给您留下了深刻的印象或启发?

发布于 2024-07-12 08:53:06 字数 176 浏览 7 评论 0原文

多年来,我听到了大量关于我们开发人员必须处理的继承项目的抱怨。 WTF 网站上有大量的代码示例,让我忍不住低声嘀咕“WTF?”

但是,你们中是否有人真正遇到过让您惊叹不已的代码,“天哪,这是经过深思熟虑的!” 或者“哇,我从来没想过这一点!”

您必须使用哪些继承的代码才能让您微笑,为什么?

I've heard a ton of complaining over the years about inherited projects that us developers have to work with. The WTF site has tons of examples of code that make me actually mutter under my breath "WTF?"

But have any of you actually been presented with code that made you go, "Holy crap this was well thought out!" or "Wow, I never thought of that!"

What inherited code have you had to work with that made you smile and why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

场罚期间 2024-07-19 08:53:06

很久以前,我负责Turbo C/C++运行时库。 Tanj Bennett 用 16 位汇编程序编写了原始的 80x87 浮点模拟器。 我没有仔细查看 Tanj 的代码,因为它运行良好并且不需要关注。 但我们正在转向 32 位,而扩展模拟器的任务就落到了我的身上。

如果说编程与艺术有共同点的话那就是了。

Tanj 的核心数学函数设法将 80 位浮点临时结果保存在 5 个 16 位寄存器中,而无需从内存中保存和恢复它们。 X86 汇编程序员将会明白这是一个多么大的成就。 寄存器空间稀缺,在进行复杂数学运算的同时保留五个寄存器作为临时值是一个美丽的网站。

如果这只是一个巧妙的编码问题,就足以将其称为艺术,但它还不止于此。 Tanj 精心挑选了最适合将温度保存在寄存器中的底层数学算法。 结果是一个速度极快的浮点模拟器,这对于我们的许多客户来说是一个重要的卖点。

当 386 出现时,大多数关心浮点性能的人都没有使用模拟器,但我们必须支持 Intel 的 386SX,因此模拟器需要彻底检修。 我重写了指令解码逻辑和异常处理,但核心数学函数完全保持不变。

Long ago, I was responsible for the Turbo C/C++ run-time library. Tanj Bennett wrote the original 80x87 floating point emulator in 16-bit assembler. I hadn't looked closely at Tanj's code since it worked well and didn't require attention. But we were making the move to 32-bits and the task fell to me to stretch the emulator.

If programming could ever be said to have something in common with art this was it.

Tanj's core math functions managed to keep an 80-bit floating point temporary result in five 16-bit registers without having to save and restore them from memory. X86 assembly programmers will understand just what an accomplishment this was. Register space was scarce and keeping five registers as your temp while simultaneously doing complex math was a beautiful site to behold.

If it was only a matter of clever coding that would have been enough to qualify it as art but it was more than that. Tanj had carefully picked the underlying math algorithms that would be most suitable for keeping the temp in registers. The result was a blazing-fast floating point emulator which was an important selling point for many of our customers.

By the time the 386 came along most people who cared about floating-point performance weren't using an emulator but we had to support Intel's 386SX so the emulator needed an overhaul. I rewrote the instruction-decode logic and exception handling but left the core math functions completely untouched.

尛丟丟 2024-07-19 08:53:06

在我的第一份工作中,我惊讶地在代码库(c++)中发现了一个“安全ID”类,它将数字ID包装在一个用空标签类模板化的类中,这确保了如果您尝试例如编译器会抱怨将 UserId 进行比较或将其分配给 OrderId。

我不仅确保在我将使用的所有后续代码库中都有一个等效的 Id 类,而且它实际上让我了解了编译器可以做什么来保证正确性并帮助编写更强大的代码。

In my first job, I was amazed to discover a "safe ID" class in the codebase (c++), which was wrapping numerical IDs in a class templated with an empty tag class, that ensured that the compiler would complain if you tried for example to compare or assign a UserId into an OrderId.

Not only did I made sure that I had an equivalent Id class in all subsequent codebases I would be using, but it actually opened my eyes on what the compiler could do to guarantee correctness and help writing stronger code.

温暖的光 2024-07-19 08:53:06

给我印象最深并且我试图模仿的代码是看起来太简单且易于理解的代码。

写这样的代码实在是太难了。 :-)

The code that impresses me the most, and which I try to emulate - is code that seems too simple and easy to understand.

It is damn difficult to write that kind of code. :-)

青瓷清茶倾城歌 2024-07-19 08:53:06

我在这里有一个有趣的故事要讲。

我正在开发这个 Javaish 应用程序,其中充满了吸气剂和吸气剂。 setter 除了获取或设置和接口以及所有使代码不可读而发明的东西之外什么也不做。 有一天,我偶然发现了一些看起来制作精良的代码——它基本上是一种看起来非常优雅的算法实现=几行可读代码,尽管它尊重项目必须遵守的每一个可能的规则(它是自动检查样式的) 。

我无法弄清楚团队中的谁可以编写这样的代码。 我很想与他讨论并分享想法。 值得庆幸的是,我们几个月前就切换到了 subversion(从 cvs),我很快就运行了 am 'svnblame'。 我懒洋洋地到处闲逛,看到我的名字就在实现旁边。

我听说过人们不记得 6 个月前编写的代码的故事,这些代码维护起来简直是一场噩梦。 我简直不敢相信会发生这样的事情:你怎么会忘记你写的代码? 好吧,现在我确信它会发生。 值得庆幸的是,代码没问题并且易于扩展,所以我只经历了一半的故事。

I have a funny story to tell here.

I was working on this Javaish application, filled with getters & setters that did nothing but get or set and interfaces and everything ever invented to make code unreadable. One day I stumbled upon some code which seemed very well crafted -- it was basically an algorithm implementation that looked very elegant = few lines of readable code, even though it respected every possible rule the project had to adhere to (it was checkstyled automatically).

I couldn't figure out who on the team could have written such code. I was dying to discuss with him and share thoughts. Thankfully, we had switched to subversion (from cvs) a few months earlier and I quickly ran am 'svn blame'. I loled all over the place, seeing my name next to the implementation.

I had heard stories about people not remembering code they wrote 6 months back, code that is a nightmare to maintain. I could not believe such a thing could happen: how can you forget code you wrote? Well, now I'm convinced it can happen. Thankfully the code was alright and easy to extend, so I've only experienced half of the story.

手心的海 2024-07-19 08:53:06

我遇到过我公司另一位程序员编写的一些 VB6 代码,它们很好地处理了错误条件(无论是直接处理它们还是记录它们)。

还有一些相当复杂的代码,并得到了很好的注释。

Some VB6 code by another programmer at my company I came across that handled the error conditions very well (whether it be deal with them directly or log them).

Along with some rather complex code that was well commented.

擦肩而过的背影 2024-07-19 08:53:06

我知道这会带来很多答案,例如

“在介入之前我从未找到过好的代码”和变化。

我认为真正的问题并不是没有优秀的编码人员或优秀的项目,而是存在过多的 NIH 综合症以及没有人喜欢别人的代码这一事实。 后者只是因为你必须付出智力上的努力来理解它,比你需要理解你自己的代码更大的努力,这样你就不喜欢它(毕竟它让你思考和工作)。

就我个人而言,我可以记得(我猜每个人都一样)一些非常糟糕的代码,但我也记得一些有据可查的、优雅的代码。

目前,给我印象最深的项目是一个非常强大的动态工作流引擎,不仅因为它的简单性,而且因为它的编码方式。 我能记得一些非常聪明的片段,以及由我的一些朋友开发的基于完整 IDL 的漂亮元编程库(Aspl.es)

I know this will bring a lot of answers like,

"I've never find good code before I step in" and variations.

I think the real problem there is not that there isn't good coders or excellent projects out there, is that there's an excess of NIH syndrome and the fact that no body likes code from others. The latter is just because you have to make an intellectual effort to understand it, a much bigger effort than you need to understand you own code so that you dislike it (it's making you think and work after all).

Personally I can remember (as everyone I guess) some cases of really bad code but also I remember some pretty well documented, elegant code.

Currently, the project that most impressed me was a very potent, Dynamic Workflow Engine, not only by the simplicity but also for the way it is coded. I can remember some very clever snippets here and there, as well as a beautiful metaprogramming library based on a full IDL developed by some friends of mine (Aspl.es)

只是在用心讲痛 2024-07-19 08:53:06

我继承了一大堆写得很好的代码,我实际上花了 40 美元在网上找到了这个人,我去了他家并向他表示感谢。

I inherited a large bunch of code that was SO well written I actually spent the $40 online to find the guy, I went to his house and thanked him.

虐人心 2024-07-19 08:53:06

我认为 Rocky Lhotka 应该获得荣誉,但我最近不得不接触 CSLA.NET 应用程序(在我的私人实践中),代码的有序性给我留下了深刻的印象。 该应用程序运行得非常好,但客户需要一些扩展。 原作者已经惨死,而新来的人却又不谙世事。 他不理解 CSLA.NET 基于业务对象的方法,他想在现成的 VB.NET 中重新做一遍,而不需要任何花哨的框架。

所以我接到了电话。 查看 WinForm 绑定和 CSLA.NET 的工作示例对于很多事情都非常有启发性。

I think Rocky Lhotka should get the credit, but I had to touch a CSLA.NET application recently {in my private practice on the side} and I was very impressed with the orderliness of the code. The app worked extremely well, but the client needed a few extensions. The original author had died tragically, and the new guy was unsophisticated. He didn't understand CSLA.NET's business object based approach, and he wanted to do it all over again in cut-and-dried VB.NET, without any fancy framework.

So I got the call. Looking at a working example of WinForm binding and CSLA.NET was pretty instructive about a lot of things.

匿名的好友 2024-07-19 08:53:06

Symbian 操作系统 - 无论如何,它的旧核心部分,可以追溯到 Psion 时代,或者直到今天仍然保持这种精神的人。

坐在它旁边和周围的是大型电话公司雇用的出价最低的人创造的所有新垃圾。 令人惊讶的是,你实际上可以从骨子里感觉到代码库的一部分是旧的还是新的。

Symbian OS - the old core bit of it anyway, the bit that dated back to the Psion days or those who even today keep that spirit alive.

And sitting right along side it and all over it is all the new crap created by the lowest bidders hired by the big phone corporations. It was startling, you could actually feel in your bones whether a bit of the code-base was old or new somehow.

阳光①夏 2024-07-19 08:53:06

我记得当我写关于类型推断的学士论文时,我的 Pascal-to-Pascal“编译器”是我的主管编写的解析器(用 Java)的扩展。 据我所知,它有一个非常好的结构,对于从未进行过任何严肃的面向对象编程的我来说,这是一个很大的启示。

I remember when I wrote my bachelor thesis on type inference, my Pascal-to-Pascal 'compiler' was an extension of a Parser my supervisor programmed (in Java). It had a pretty good structure as far as I can remember, and for me who had never done any serious Object-oriented programming, it was quite a revelation.

叫嚣ゝ 2024-07-19 08:53:06

我一直在进行大量 Eclipse 插件开发,并且经常需要调试实际的 Eclipse 源代码。 虽然我没有“继承”它,也就是说我没有继续研究它,但早期核心的设计和质量一直给我留下了深刻的印象。

I've been doing a lot of Eclipse plug-in development and often had to debug into the actual Eclipse source code. While I haven't "inherited" it in the sense that I'm not continuing work on it, I've always been impressed with the design and quality of the early core.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文