A Message to the Future

本文通过一个教授与其学生的对话,强调了编写易于理解且维护的代码的重要性。教授通过假设学生编写的代码将由他的弟弟(一个初学者程序员)来维护的情景,引导学生思考如何让代码更加优雅和清晰。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A Message to the Future

Linda Rising

MAYBE iT’S BECAUSE MOST OF THEM ARE SMART PEOPLE, but in all the years I’ve taught and worked side by side with programmers, it seems that most of them thought that since the problems they were struggling with were difficult, the solutions should be just as difficult for everyone (maybe even for themselves a few months after the code was written) to understand and maintain.
I remember one incident with Joe, a student in my data structures class, who had to come in to show me what he’d written. “Betcha can’t guess what it does!” he crowed.
“You’re right,” I agreed, without spending too much time on his example and wondering how to get an important message across. “I’m sure you’ve been working hard on this. I wonder, though, if you haven’t forgotten something important. Say, Joe, don’t you have a younger brother?”
“Yep. Sure do! Phil! He’s in your Intro class. He’s learning to program, too!” Joe announced proudly.
“That’s great,” I replied. “I wonder if he could read this code.”
“No way!” said Joe. “This is hard stuff!”
“Just suppose,” I suggested, “that this was real, working code, and that in a few years, Phil was hired to make a maintenance update. What have you done for him?” Joe just stared at me, blinking. “We know that Phil is really smart, right?”
116 97 Things Every Programmer Should Know

Joe nodded. “And I hate to say it, but I’m pretty smart, too!” Joe grinned. “So if I can’t easily understand what you’ve done here and your very smart younger brother will likely puzzle over this, what does that mean about what you’ve written?” Joe looked at his code a little differently, it seemed to me. “How about this,” I suggested in my best “I’m your friendly mentor” voice, “Think of every line of code you write as a message for someone in the future—someone who might be your younger brother. Pretend you’re explaining to this smart person how to solve this tough problem.
“Is this what you’d like to imagine? That the smart programmer in the future would see your code and say, ‘Wow! This is great! I can understand perfectly what’s been done here and I’m amazed at what an elegant—no, wait—what a beautiful piece of code this is. I’m going to show the other folks on my team. This is a masterpiece!’
“Joe, do you think you can write code that solves this difficult problem but will be so beautiful it will sing? Yes, just like a haunting melody. I think that anyone who can come up with the very difficult solution you have here could also write something beautiful. Hmm…I wonder if I should start grading on beauty? What do you think, Joe?”
Joe picked up his work and looked at me, a little smile creeping across his face. “I got it, prof, I’m off to make the world better for Phil. Thanks.”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值