vsc 搜索特定代码

by Rina Artstain

通过丽娜·阿斯特斯坦

特定问题的通用解决方案:何时编写代码以及何时编写代码 (Generic solutions to specific problems: when to write some code and when to just do it)

There is a traditional story that tells of a rabbi who comes upon a guy sitting next to a fork in the road. The rabbi asks the guy which way is best to get to the city, and the guy answers: That one is a short road which is long, and the other is a long road which is short. The rabbi chooses the short road, but soon arrives at a field full of thorns which he can’t get through, and must turn back and take the other road, which actually leads him to the city.

有一个传统的故事,讲述一个拉比碰到一个坐在路边叉子旁边的家伙。 拉比问那家伙哪条路最好去城市,那家伙回答:那一条是一条很长的短路,另一条是一条很短的长路。 拉比选择了一条短路,但很快到达一个布满荆棘的田野,他无法穿越,必须回头走另一条路,这实际上将他引向了城市。

The moral of the story, other than wondering if this guy was the first troll in history, is that sometimes trying to take a short cut will end up being longer than just doing it the long way.

除了想知道这个家伙是否是历史上第一个巨魔之外,这个故事的寓意在于,有时尝试捷径最终会比长途跋涉更长。

编码很长的路(很短) (Coding the Long Way (which is Short))

If you’re specifically writing an API or a library for internal or external use, you know that it should be as generic as possible. You want it to be clear, concise and easy to use, while still giving your users a lot of flexibility. There are trade-offs between those goals, but you’ll figure them out.

如果您专门编写供内部或外部使用的API或库,那么您应该知道它应该尽可能通用。 您希望它清晰,简洁且易于使用,同时仍为您的用户提供很大的灵活性。 在这些目标之间需要权衡取舍,但是您会找到答案。

But what happens when you’re given a specific task to complete, and you can either just do it, or write some infrastructure which will make just doing it easier in the future?

但是,当您被赋予要完成的特定任务,而您既可以做到这一点,又可以编写一些基础架构来简化将来的工作时,会发生什么?

Should you get the task done as quickly as possible or spend the time to build some infrastructure which will make future tasks easier to complete?

您应该尽快完成任务还是花时间建立一些基础设施,使将来的任务更容易完成?

Should you choose the short road which might turn out to be long, or the long road which will actually help you hit your target sooner?

您应该选择一条可能会很长的短路,还是选择一条实际上会帮助您更快地达到目标的长路?

一个例子(基于真实的故事) (An example (based on a true story))

(Some of the details have been changed or omitted for simplicity, and, well, better story telling. Reality is much too messy.)

(为简单起见,其中一些细节已更改或省略,并且更好的讲故事。现实实在太混乱了。)

One day, my boss comes up to me and asks me to quickly get some data from the DB and send it to him as an excel sheet. It wasn’t too complicated, so I did it right away.

有一天,我的老板来找我,要求我快速从数据库中获取一些数据,并将其作为excel表发送给他。 它并不太复杂,所以我马上就做到了。

The next day he asks for the same data again, with different dates. He thinks for a bit and says, well — maybe you should just put this report up on the web. I’d like to be able to access this data any time and choose the dates myself.

第二天,他再次要求提供相同的数据,但日期不同。 他思考了一会儿,然后说,很好–也许您应该将这份报告发布到网络上。 我希望能够随时访问此数据并自己选择日期。

No problem! Here you go, some front-end, some back-end, deploy. Wait. Wait. Wait. Deployment done, and the report is online.

没问题! 在这里,您可以进行一些前端,某些后端的部署。 等待。 等待。 等待。 部署完成,报告处于联机状态。

A couple of days go by, and I’m asked for another quick report, and “do it with that nice interface and date filters you gave us last time”. OK, sure. No problem. Front-end, back-end, deploy, wait, online.

过了几天,我被要求提供另一份快速报告,并“使用您上次给我们的漂亮界面和日期过滤器进行操作”。 是当然。 没问题。 前端,后端,部署,等待,在线。

Next time I got a similar request I said: “Look, it will take me half a day to write this report, but if you give me two days, I can build some infrastructure which will allow me to define a query in the DB, add some configuration, and your report will be live without having to wait for deployment”. My request was approved.

下次收到类似的请求时,我说:“看,我将花半天时间编写这份报告,但是如果您给我两天的时间,我可以构建一些基础结构,使我可以在数据库中定义查询,添加一些配置,您的报告将立即生效,而无需等待部署。” 我的请求被批准。

这是我过去两天的工作: (Here’s what I did with my two days:)

I defined a convention for a “report” stored procedure, which expected to get the following parameters:

我为“报告”存储过程定义了一个约定,该约定应获取以下参数:

  • From Date从日期
  • To Date至今
  • Start At Index (for paging)从索引开始(用于分页)

Each procedure returned a result set for the query, and the Total Result Count (for paging).

每个过程都返回查询的结果集和总结果计数(用于分页)。

In addition, I added a Reports table which held:

另外,我添加了一个Reports表,其中包含:

  • Stored Procedure Name (to execute)存储过程名称(执行)
  • Title (of the report)(报告的)标题
  • Description (to be displayed on the report page)说明(将显示在报告页面上)

I also added an endpoint on the server, UI, and some logic to:

我还在服务器,UI和一些逻辑上添加了一个端点:

  • Check the DB for reports and add them to the site navigation.检查数据库中的报告,并将其添加到站点导航中。
  • When a report was accessed, execute the matching stored procedure and return the result to the UI.访问报告后,执行匹配的存储过程并将结果返回到UI。
  • Display two date pickers for selecting From Date and End Date and executing the query.显示两个日期选择器,以选择“从日期”和“结束日期”并执行查询。
  • A generic table to display the results formatted according to the data type of each column. (I already had a generic UI component for paging, yay me!)通用表,用于显示根据每一列的数据类型格式化的结果。 (我已经有一个通用的UI组件用于分页,是的!)

When I was done, I could add a stored procedure and an entry in the DB and the report would automagically appear on our site.

完成后,我可以在数据库中添加一个存储过程和一个条目,该报告将自动显示在我们的站点上。

唯一不变的是变化 (The Only Constant is Change)

Everyone was happy and super excited about my time saving report feature, but… What about sorting? And could we have the first column link to the customer’s profile? And could we maybe add filtering by the sales rep responsible for that customer?

每个人都对我的省时报告功能感到高兴和兴奋,但是……排序又如何呢? 我们能否将第一列链接到客户的个人资料? 我们是否可以添加负责该客户的销售代表进行过滤的功能?

Yeah! Sure. That makes a lot of sense. So I added:

是的 当然。 这很有意义。 所以我补充说:

  • Optional Sort By and Sort Direction parameters to the Stored Procedures.存储过程的可选“排序依据”和“排序方向”参数。
  • A flag for specifying if the first column should link to the customer’s profile.用于指定第一列是否应链接到客户的个人资料的标志。
  • Another flag for specifying if the query included filtering by sales rep.用于指定查询是否包括按销售代表过滤的另一个标志。
  • And a few UI/logic changes to support displaying/executing these new requirements.以及一些UI /逻辑更改,以支持显示/执行这些新要求。

Happy happy, joy joy. But… How about grouping the results? And when you click the row could you have an email sent to a group of predefined users? And when a sales rep enters the report, could you have the report displayed in their favorite color? (OK, I made that last one up)

快乐快乐,快乐快乐。 但是……如何将结果分组? 当您单击该行时,是否可以将电子邮件发送给一组预定义的用户? 当销售代表输入报告时,可以用他们喜欢的颜色显示报告吗? (好的,我把最后一个弄了)

稍安毋躁 (Hold your Horses)

At this point, I had to stop and think which features should be implemented as part of my generic solution, and which should be developed as a stand-alone solution.

在这一点上,我不得不停下来想一想,哪些功能应作为通用解决方案的一部分实施,哪些功能应作为独立的解决方案开发。

It was obvious to me that specific custom actions which don’t depend on the actual data returned from the query (like sending an email to certain predefined users) was out of the question.

对我来说很明显,不依赖于查询返回的实际数据的特定自定义操作(例如向某些预定义的用户发送电子邮件)是不可能的。

I also thought that uncommon actions which depend on the data returned by the query shouldn’t be added to the generic report infrastructure. So, filter by sales rep — sure, why not. Link to customer — OK, common scenario. But other actions which are very specific to a single report — nope.

我还认为,不应将依赖于查询返回的数据的不常见操作添加到通用报表基础结构中。 因此,按销售代表过滤-当然,为什么不呢? 链接到客户-好的,常见的情况。 但是其他针对单个报告的特定操作-不。

The grouping requirement posed more of a challenge: Grouping is a common and extremely useful scenario. Should I add it to my infrastructure or not?

分组要求带来了更大的挑战:分组是一种常见且极为有用的方案。 是否应该将其添加到我的基础架构中?

Well, what would grouping the results require?

那么,将结果分组需要什么?

  • Adding a Group By flag to the report’s DB entry, to let the logic know to expect two distinct result sets — group header and group details.在报表的DB条目中添加一个Group By标志,以使逻辑知道期望两个不同的结果集-组标题和组详细信息。
  • The logic would also have to know how to match the group to the details, and it would have to be done by convention. Extremely risky business.逻辑还必须知道如何使组与细节匹配,并且必须按照惯例完成。 极具风险的业务。
  • Figuring out how to generically sort results with a group header. I can’t even.弄清楚如何使用组头对结果进行一般排序。 我什至不能
  • And probably some other issues I haven’t thought of.可能还有其他我没想到的问题。

代码未写 (The Code Not Written)

I didn’t add grouping.

我没有添加分组。

In retrospect, putting about a week of effort total into this reports feature saved me hundreds of hours developing reports later on. I also managed to avoid the pitfall of trying to be too generic and supporting too much extraneous stuff, which would have hurt the system’s stability in the long run.

回顾一下,在此报告功能中投入了大约一周的时间,使我以后节省了数百小时的报告开发时间。 我还设法避免了过于通用和支持过多无关内容的陷阱这从长远来看会损害系统的稳定性。

But really, I shouldn’t have written a single line of code. I should have looked into a reporting tool.

但实际上,我不应该编写任何代码。 我应该研究一下报告工具。

However, there are other generic helper systems which I wrote which were a good investment and should have been written. For example, a library of helpers which create HTML elements with predictable ids and classes tailored to our data models and UI requirements.

但是,我编写了其他通用帮助程序系统,这是不错的投资, 应该编写。 例如,一个帮助程序库可创建HTML元素,这些HTML元素具有针对我们的数据模型和UI要求量身定制的可预测ID和类。

怎么办? (Now What?)

So how should you decide whether to write some infrastructure or just do it? Here’s how I decide:

那么,您应该如何决定是编写某些基础架构还是仅仅是编写基础架构? 这是我的决定方式:

  • Is it a rote task? If it’s boring and recurring, if you find yourself copy-pasting a whole lot of code often — check if you can generalize what you’re doing and build some code to do it for you.死记硬背吗? 如果这很无聊且经常发生,如果您发现自己经常复制粘贴很多代码,请检查您是否可以概括您正在做的事情并构建一些代码来帮助您。
  • How long will building the infrastructure take? If you can build the infrastructure in 5 minutes and each task would have taken you 5 days, it’s an easy answer. If building the infrastructure would take a year and each task would take 5 minutes — don’t build it. But it’s usually not that clear cut. Try to estimate as best you can, try to keep it simple, and be prepared to cut your losses if it takes too long.基础设施建设需要多长时间? 如果您可以在5分钟内构建基础架构,而每个任务将花费您5天的时间,这是一个简单的答案。 如果构建基础架构需要花费一年,而每个任务都需要5分钟-那就不要构建它。 但这通常不是那么明确。 尽力估计尽可能多,尽量简化,如果准备时间太长,准备减少损失。
  • Do not add specific implementations to your generic solution. If it doesn’t fit, don’t try to force it. You’ll end up ruining your infrastructure and getting a mediocre result for the task you were actually trying to complete.不要将特定的实现添加到您的通用解决方案。 如果不合适,请不要强行使用。 您最终将破坏基础架构,并为您实际上要完成的任务获得平庸的结果。
  • But first, please check if there is ready made solution to your problem.

    但是首先, 检查是否有针对您问题的现成解决方案。

Like what you read? Share the love by clapping. Have a question or comment? Let me know in the comments section.

喜欢你读的书吗? 通过鼓掌分享爱。 有问题或意见吗? 让我知道在评论部分。

翻译自: https://www.freecodecamp.org/news/generic-solutions-to-specific-problems-2562fbd37a5a/

vsc 搜索特定代码

vsc 搜索特定代码_特定问题的通用解决方案:何时编写代码以及何时编写代码...相关推荐

  1. lstm代码_贼好理解,这个项目教你如何用百行代码搞定各类NLP模型

    机器之心报道 参与:思源.贾伟 NLP 的研究,从词嵌入到 CNN,再到 RNN,再到 Attention,以及现在正红火的 Transformer,模型已有很多,代码库也成千上万.对于初学者如何把握 ...

  2. java好的代码_做java软件工程师,怎样才能写出好的代码?

    原标题:做java软件工程师,怎样才能写出好的代码? Java代码之于java程序员而言就是左膀右臂,java代码写的好的java程序员明显更是企业的欢迎,一个优秀的java程序员的考核标准之一也是看 ...

  3. python分析人口出生率代码_身份证号码各位数字的含义以及计算校验位的python代码...

    公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成.排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码. 其中前六位是地址码,通过百度百科我们很容易就 ...

  4. y空间兑换代码_进行图像增广的15+种功能总结和Python代码实现

    python代码可以自己扩充图像数据集. ​ 无论我们喜欢Keras还是Pytorch,我们都可以使用丰富的资料库来有效地增广我们的图像. 但是如果遇到特殊情况: 我们的数据集结构复杂(例如3个输入图 ...

  5. python画美女代码_教你用python爬取网站美女图(附代码及教程)

    我前几篇文章都是说一些python爬虫库的用法,还没有说怎样利用好这些知识玩一些好玩的东西.那我今天带大家玩好玩又刺激的,嘻嘻!对了,requests库和正则表达式很重要的,一定要学会!一定要学会!! ...

  6. 一键分享手机代码_通过广告路由器指定手机浏览器自动认证WIFI上网 附代码

    说说应用过程,下面用手机QQ浏览器为例.在路由器搭建免费WIFI,用户连接免费WIFI后,使用手机QQ浏览器点击打开任意网页即可自动通过认证并上网,有的手机会自动打开认证网页,如果使用其他手机浏览器则 ...

  7. 查看exe代码_【安全风险通告】Windows Type 1字体解析远程代码执行漏洞安全风险通告...

    微软官方今天发布了编号为ADV200006的安全通告,其中包含两枚Adobe字体管理库相关的严重远程代码执行漏洞,其中一枚漏洞为奇安信代码安全实验室提交,公告中指出这两枚漏洞已遭在野利用. 鉴于漏洞危 ...

  8. lsd 特征点匹配代码_线特征LSD and 描述子LBD(一)(示例代码)

    最近在看有关特征提取的线特征,暑期就看了相关的论文:<基于点线综合特征的双目视觉SLAM方法_谢晓佳>,最近呢,把里面有关线特征提取LSD和描述子LBD的代码跑了一遍,记录如下: [1]L ...

  9. 离散数学 逻辑判断系统 代码_入学派位查询系统现异常,北京西城区:网站代码逻辑错误,不影响派位结果...

    图源:图虫创意 ♪ 作者|芥末堆 李婷 ♪ 编辑|芥末堆看教育 芥末堆讯 6月10日下午,北京市西城区教育考试中心就6月9日寄宿.九年一贯制和民办学校入学派位查询系统出现异常情况进行通告,称" ...

最新文章

  1. FAST:基于FPGA的SDN交换机开源项目
  2. 正则表达式之?、(?:pattern)、(?!pattern)、(?=pattern)理解及应用
  3. PowerDesigner12 逆向工程DataBase SQl2005: unable to list the tables 信息
  4. 探索交通治理新思路,广州黄埔智能交通治“堵”
  5. azure机器学习_Azure机器学习中的数据清理
  6. Ubuntu 16.04 安装opencv3及其扩展模块
  7. c# 两行代码合并pdf文件
  8. GIS开发进阶之路(十三) Activator和new的区别、GP工具输入参数问题、写入JObject到json文件、ArcGIS Server REST API、动态规划、贪心算法
  9. Android如何关闭硬件加速
  10. python中encode函数_python中文处理之encode/decode函数
  11. FFmpeg 直播黑屏问题分析解决
  12. 学习新体验-itron
  13. 2019亚洲蓝牙大会成果盘点
  14. 解决linux有时候不能粘贴
  15. 个人支付收款方案-PayJS
  16. 支付宝原型设计-低保真Axure9支付宝界面设计
  17. RFID标签基本常识
  18. 【VPX302】基于3U VPX总线架构的高性能数据预处理平台/XCKU115
  19. Sun java证书
  20. [电路]6-电阻的星形连接和角形连接等效变换(星角变换)

热门文章

  1. 资深Android开发带你入门Framework,再不刷题就晚了!
  2. jquery如何阻止子元素继承父元素的事件(又称事件冒泡)
  3. Python程序互斥体
  4. python ==字符串
  5. Linux 查看磁盘或文件夹及文件大小
  6. Andrew Ng机器学习之一 导论
  7. 别人7天乐,运维还苦逼值班?
  8. 关于Linux的总结(三)
  9. Java面试常见算法
  10. Ireport制作过程