Coder's Block

本文探讨了程序员面临的编码障碍现象,分析了其产生的多种原因,包括干扰、任务超载、对失败的恐惧等,并提供了实用建议帮助克服这些障碍。此外,还讨论了解决旧代码扩展性难题的方法。

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

Kode Vicious

Coder's Block

What does it take to clear the blockage?

[article image]
Credit: Sergei Chumakov / Shutterstock

Dear KV,

I am a manager of a small development group and one of my programmers seems to spend his whole day staring at his screen but not actually writing code. He then spends weekends and nights in the office and eventually checks in code that actually works, but whenever I ask him why he is just staring during the day, he replies, "Coder's block," and then continues to stare. It's kind of creepy. Is there any such thing as coder's block?

Not Blocked but Confused

Dear NBC,

Programming is a creative endeavor, and therefore the short answer is yes, there is such a thing as coder's block. Not only is there such a thing, but there are also various types and sources of coder's block, some of which I will cover here. If any of these apply to your programmer, you'll be able to help clear the blockage, since that is what managers are supposed to do.

Perhaps the easiest source of coder's block to see and understand is distraction. Any modern office environment is a hotbed of distractions, including ringing phones, talking coworkers, people who come by your desk to ask questions (many of which they could answer themselves by reading documentation), meetings, and, of course, well-meaning managers who drop by to ask, "How's it going?" All but the most trivial coding tasks require quiet and concentration, and if programmers do not get those, then they are not going to be able to build up the intellectual head of steam they need to solve complex problems. Time free from distraction also has to be sufficient to the task. Ask your programmer how long he gets to sit and think between interruptions, and you will probably find it is less than one hour. While some programs can be designed and finished in an hour, they are few and far between. Giving someone who works for you a few distraction-free hours per day is one way to help prevent coder's block.


One of the best ways to overcome coder's block is to look at another unrelated piece of code.


One piece of advice for all you programmers out there is to touch code first thing when you come into work. Do not read email, open your instant messaging client, or do anything else that can suck you into distractions that are not coding. When you sit down to work, sit down to work. Email, instant messaging, and social networking are anathema to concentrating on hard problems.

Sometimes coder's block is brought on by programmers taking on more work than they can handle. Either the problems are too complex, or they just do not know where to start, or both. I don't know if you have noticed most coders, but they tend to have a large, personal store of hubris that often gets them into trouble, both at and outside of work. If a programmer is staring at a problem for hours on end and making no progress, you can ask if he or she has tried to break down the problem, and perhaps have the person show you how he or she is breaking it down. Do not do this in a nagging way that distracts the programmer (see above). One of the main ways to annoy a coder is to constantly ask, "How's it going?" You are allowed to ask this once per day, and not when the person looks like he or she is actually concentrating. You might want to ask this question at lunch.

Another type of coder's block comes from fear of failure. Most people want to do a good job and be recognized for the good work they do. This is especially true of people who do knowledge work, such as programmers, because the only measures of quality are how cleverly and cleanly they have built something. Since software is nearly infinitely malleable, many coders get stuck trying to come up with the absolute neatest, cleverest way to implement something.

The need for perfection leads to many false starts, writing a page of code and then doing what writers used to do when they had a typewriter writer's block: they crumple up the one page they have finally written and throw it in the trash. When people used paper to write, it was easy to see that they had writer's block, because their trash cans would be overflowing with crumpled pieces of paper. If you picked up a few of these, you would see that none contained a full page of text; the writers probably got only halfway down a page before they tore it out of the typewriter and threw it away. In our modern world you cannot actually see the false starts, because no one in his or her right mind would check them in.

If you find a programmer making a lot of false starts at a piece of code, give that person something else to work on. One of the best ways to overcome coder's block is to look at another unrelated piece of code. You want the coder's mind to remain in a coding mode but to relax its grip on the problem that is causing the angst.


Sometimes when people build systems they expect are going to be extended, they place extra space into a structure for future expansion.


Finally, sometimes coder's block comes from some sort of emotional problem, usually outside the job, although job stress can also lead to emotional imbalances. I find that jobs, in general, lead to emotional imbalance, as does waking up in the morning, commuting, and talking to stupid people. Sometimes you have to just tell someone to take some time off, so that his or her mind will clear and the coder's block will lift. Of course, if you find a programmer is just staring at the screen, you might want to take a surreptitious glance at what he or she has written. If it is anything like, "All work and no play make Jack a dull coder," then it is time to hide the fire axes and call for an intervention.

KV

Dear KV,

I am working on some very old C code that needs to be extended, but there is an annoying complication. This code manipulates an in-memory structure that other programs have to read, but there is a requirement that older binaries still be able to work with the new code. I don't think this is possible, since once I change the structure the older binaries are definitely going to fail. Is there a way around this?

Backwardly Structured

Dear Backward,

There is a small, but nonzero, chance that you may yet be able to pull this off, but it depends on the structure you are working with. Sometimes when people build systems they expect are going to be extended, they place extra space into a structure for future expansion. Of course I say "sometimes" because although all computer science programs sing paeans to extensibility, they often leave out the practical part of just how one makes code extensible.

If you are lucky, then the structure you need to modify has some extra space, usually labeled as padding, which you can use for your new purposes. All you would need to do is subtract some of the padding and add new elements to the structure that are equal in size to the padding you have removed. Make sure to add the new parts of the structure after the preexisting parts, because if you do not, then your older binaries will be reading your new type of data where they expect their old data to be. That might lead to a crash, which is the good case because you will be able to find the bug; but it might simply lead to getting subtly incorrect results, and those types of bugs are incredibly annoying to search out. And make sure you comment your change and be very clear about the change in your commit message. Messing with in-memory structures in this way can lead to hard-to-find bugs, as I mentioned, and the first thing someone who comes across this type of bug will want to do is to try the code without your change, to see if it is the source of the problem.

KV

q stamp of ACM QueueRelated articles
on queue.acm.org External Link

IM, Not IP (Information Pollution)
Jakob Nielsen
http://queue.acm.org/detail.cfm?id=966731 External Link

Coding Smart: People vs. Tools
Donn M. Seeley
http://queue.acm.org/detail.cfm?id=945135 External Link

A Conversation with Joel Spolsky
http://queue.acm.org/detail.cfm?id=1281887 External Link

Back to Top

Author

George V. Neville-Neil (kv@acm.org) is the proprietor of Neville-Neil Consulting and a member of the ACM Queue editorial board. He works on networking and operating systems code for fun and profit, teaches courses on various programming-related subjects, and encourages your comments, quips, and code snips pertaining to his Communications column.

 

from http://cacm.acm.org/magazines/2011/4/106574-coders-block/fulltext

 

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
### 使用 MATLAB S-Function Builder 创建自定义模块 #### 准备工作 为了使用 S-Function Builder 创建自定义模块,需先准备好所需的工具箱和环境设置。确保已安装 Simulink 和 Embedded Coder 工具箱。 #### 打开 S-Function Builder 对话框 启动 MATLAB 后,在命令窗口输入 `simulink` 来打开 Simulink 库浏览器。找到并双击 “User-Defined Functions” 文件夹内的 “S-Function Builder”。这将弹出用于配置 S-Function 的图形化界面[^1]。 #### 配置接口参数 在弹出的对话框中,可以指定输入/输出端口的数量及其数据类型、采样时间以及其他必要的属性。这些设定决定了最终生成的 S-Function 将如何与其他 Simulink 组件交互。 #### 编写算法逻辑 对于核心计算部分,用户可以在编辑区编写C/C++代码来描述期望的行为模式。特别注意的是,当涉及到状态更新或连续动态系统的模拟时,应当分别实现相应的回调函数(如 Outputs, Update 或 Derivatives)。如果需要处理指针操作,则应在特定位置正确声明及初始化指向所需内存区域的指针变量[^4]。 #### 生成 S-Function 源文件 完成上述步骤之后点击“Build”按钮即可触发编译过程,并自动生产 `.c` 和 `_wrapper.c` 这样的源文件。前者包含了主要业务逻辑;后者负责封装调用入口以便更好地适配 Simulink 平台的需求[^2]。 #### 测试验证 最后一步是在新的 Simulink 模型里加入刚刚构建好的 S-Function 块来进行初步的功能性检验。可以通过连接信号发生器和其他测量设备观察实际运行效果是否符合预期。 ```matlab % 示例:创建一个新的 Simulink 模型并将生成的 S-Function 添加进去 new_system('myModel'); add_block('built-in/S-Function','myModel/sFunBlock','-Position',[80 96 120 136]); set_param(gcb,'SFunctionName','s_fun') % 设置为之前生成的名字 open_system('myModel') ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值