javaweb解决编码问题

Most of the tutorials you have read or watched before now usually do one thing, spoon-feeding.

您以前阅读或观看过的大多数教程通常都是一勺子喂。

This is “OK” to learn a new thing, but not good when you need to solve a real task.

学习新事物是“可以的”,但是当您需要解决实际任务时则不好。

A task usually involves reaching a goal by overcoming a problem. This post unveils the most important “tip” for all beginner software engineers.

任务通常涉及通过克服问题来达成目标。 这篇文章揭示了所有初学者软件工程师最重要的“技巧”。

TL; DR (TL;DR)

First, solve the problem. Then, write the code. — John Johnson

首先,解决问题。 然后,编写代码。 约翰·约翰逊

In other words, work the solution out on paper in steps. Then start writing the code for it. Don’t get tangled in the code and software design first.

换句话说,分步解决该问题。 然后开始为其编写代码。 不要首先纠缠于代码和软件设计中。

那么,会发生什么呢? (So, what happens?)

Many times I hear beginners and junior software engineers say: “I could follow the tutorial and thought I understood the concept. But when I tried to do a similar thing on my pet project, I could not do it.”

我多次听到初学者和初级软件工程师说:“我可以按照教程学习,以为自己理解了这个概念。 但是,当我尝试在宠物项目中做类似的事情时,我做不到。”

This happens for two reasons.

发生这种情况有两个原因。

First, you lost your train of thought somewhere and could not establish a chain.

首先,您迷失了思路,无法建立连锁关系。

Second, you were so tangled in the code that the main problem you were trying to solve fell out of focus.

其次,您在代码中纠缠不清,以至于试图解决的主要问题没有引起人们的关注。

This problem also happens for Software Engineers and even Senior Software Engineers.

软件工程师甚至高级软件工程师也会发生此问题。

The good thing is that with experience, you know when to stop or take a break. Then, come back to the problem with a different prescription and find a solution faster.

好消息是,有了经验,您知道何时该停止或休息一下。 然后,以不同的处方返回问题,并更快地找到解决方案。

Many of you can relate to this: You were trying so hard to fix an issue for hours. You took a break or slept over it, and next session the solution was there in minutes.

你们中的许多人都可能与此有关:您一直在努力解决一个小时的问题。 您稍作休息或就寝,接下来的会议只需几分钟即可解决。

This is not magic. This is looking at the problem from another viewpoint.

这不是魔术。 这是从另一个角度看问题。

让我们用一个例子来说明 (Let’s illustrate with an example)

You have to do a task — for example, create a refund with payments.

您必须完成一项任务-例如,创建带有付款的退款。

You are given the database schema. This is a back-end task and you need to create a POST /refunds API that can create the refund and its related payments. The database structure is as below:

您将获得数据库架构。 这是一项后端任务,您需要创建一个POST / refunds API,该API可以创建退款及其相关付款。 数据库结构如下:

A refund always has a reason, such as ‘damaged goods’ or ‘late delivery’.

退款总是有原因的,例如“货物损坏”或“交货延迟”。

You could discuss the API payload with one of the team members. You might agree on the below JSON payload:

您可以与团队成员之一讨论API有效负载。 您可能会同意以下JSON有效负载:

通常情况 (The usual scenario)

What most beginner software engineers will do is start scanning the codebase, if there is one. They will immediately start writing some code. If there is any testing culture in place, maybe they write some automated test code.

大多数初学者软件工程师会做的是开始扫描代码库(如果有的话)。 他们将立即开始编写一些代码。 如果有任何测试环境,也许他们会编写一些自动化测试代码。

This is where most beginner and even some experienced software engineers slip. Don’t write code when you have not solved the problem.

大多数初学者,甚至是一些经验丰富的软件工程师都在这里滑倒。 未解决问题时请勿编写代码。

适当的步骤 (The appropriate step)

The most appropriate step is to sit down and solve the problem on paper in steps.

最合适的步骤是坐下来逐步解决纸上的问题。

So you ask yourself what you need to do. You come up with a plan in steps and tweak it.

所以你问自己自己需要做什么。 您逐步提出了一个计划并对其进行了调整。

If you have someone senior in your team, you can validate your steps and get feedback.

如果您的团队中有资深人士,则可以验证您的步骤并获得反馈。

This will also decrease the code review time. Both of you have already agreed on the modality of the solution.

这也将减少代码检查时间。 你们俩都已经同意解决方案的方式。

那么怎么做 (So how to do it)

The task described earlier is to write a create/POST API where Refunds with payments can be created.

前面描述的任务是编写一个create / POST API,可以在其中创建带付款的退款。

Each refund can have a maximum of two payments. One is of type ‘cash’ and the other is of type ‘credit’. It can also be one refund with only one payment of either cash or credit. This is how I would have written the following steps on paper:

每次退款最多可分两次付款。 一种是“现金”类型,另一种是“信贷”类型。 也可以是一次退款,只用现金或信用卡一次付款即可。 这就是我在纸上写以下步骤的方式:

  1. Create a method to get the data from the controller sent by the user创建一种方法来从用户发送的控制器中获取数据
  2. Validate all the input for values, refund types, and reasons.验证所有输入的值,退款类型和原因。
  3. If all validation passes, generate a random alphanumeric number of length 10 which is not existing in the refund table (recursive check)如果所有验证均通过,则生成一个长度为10的随机字母数字,该数字在退款表中不存在(递归检查)
  4. If validation fails to respond with a proper validation failure message, decide on response structure如果验证未能通过正确的验证失败消息进行响应,请确定响应结构
  5. Start a database transaction开始数据库事务
  6. Insert the refund related values of refund_nr, reason_reason, is_premium_customer to the refund table

    将与退款相关的值refund_nrreason_reasonis_premium_customerrefund表中

  7. On insert success, get the id of the last insert插入成功后,获取上一次插入的ID
  8. With the refund_id, insert payment related values of fk_refund, fk_item, amount, is_cash to the payment table

    使用refunding_id,将与付款相关的值fk_refund,fk_item,金额,is_cash插入payment

  9. If all went well commit the database transaction如果一切顺利,请提交数据库事务
  10. If there was any issue, rollback database transaction如果有任何问题,请回滚数据库事务
  11. Respond with success or failure message depending on the database transaction’s success with proper structure根据数据库事务的成功与否,以适当的结构响应成功或失败消息
  12. Wire up the controller and this method连接控制器并使用此方法

逐步执行计划,现在编写代码 (Follow the plan in steps, now write the code)

After you have a step by step plan you can start writing code. Then, you can go more in-depth on the method names, how to get the database connection and other details.

在制定分步计划之后,您可以开始编写代码。 然后,您可以更深入地了解方法名称,如何获得数据库连接以及其他详细信息。

Depending on the language and framework you can also decide where should the validation code stay.

根据语言和框架,您还可以确定验证代码应保留在哪里。

You could even write tests if the company and culture supports and encourages it.

如果公司和文化支持并鼓励,您甚至可以编写测试。

When your solution is evident in your mind and you have a step-by-step action plan on paper, you can now write code.

当您的解决方案在您的脑海中浮现时,并且在纸上有了逐步的行动计划,您现在就可以编写代码。

You can even break up the parts in ways that will be easier to finish and wire up.

您甚至可以以更容易完成和连接的方式分解零件。

For example, the testing logic can be something that can be written separately and tested on its own. It is thinking about independent parts that can be wired up together to form the solution.

例如,测试逻辑可以是可以单独编写并可以单独测试的东西。 它正在考虑可以连接在一起以形成解决方案的独立零件。

结论 (Conclusion)

When you face your next task, don’t start writing code from the get-go.

当您面对下一个任务时,请不要从一开始就编写代码。

First, get a hold of the problem then devise a solution with steps. This is best done away from a screen on paper.

首先,抓住问题,然后逐步设计解决方案。 最好不要放在纸上屏幕上。

Then, refine your solution and discuss with someone. When you are satisfied, translate that solution to code. This is a bit methodical but very effective.

然后,完善您的解决方案并与某人讨论。 当您满意时,可以将该解决方案转换为代码。 这有点有条理,但非常有效。

Code is always a medium to the solution, not the solution itself.

代码始终是解决方案的媒介,而不是解决方案本身。

You can read more of my blog posts at geshan.com.np.

您可以在geshan.com.np上我的博客文章

翻译自: https://www.freecodecamp.org/news/learning-to-code-first-learn-to-solve-the-problem-128475b91301/

javaweb解决编码问题

javaweb解决编码问题_学习编码? 首先,学会解决问题。相关推荐

  1. 成功的秘诀是什么_学习编码的10个成功秘诀

    成功的秘诀是什么 This post was originally published on Coder-Coder.com. 该帖子最初发布在Coder-Coder.com上 . If you're ...

  2. 深度学习去燥学习编码_学习编码的警示故事。 我自己的。

    深度学习去燥学习编码 I was just a guy in a suit in an office with a vague startup idea. Then I decided to lear ...

  3. 天黑以后 博客_学习编码:天黑了

    天黑以后 博客 by Alexander Kallaway 亚历山大·卡拉威(Alexander Kallaway) 学习编码:天黑了 (Learning to Code: When It Gets ...

  4. tcp选项部分编码_学习编码中最难的部分也是最有趣的部分

    tcp选项部分编码 by Corey Slaven 通过Corey Slaven 学习编码中最难的部分也是最有趣的部分 (The hardest part of learning to code is ...

  5. 动力电池编码追溯系统_学习编码时如何保持动力(10条可行的技巧!)

    动力电池编码追溯系统 This post was originally published on Coder-Coder.com. 该帖子最初发布在Coder-Coder.com上 . Does th ...

  6. 中日文字编码转换_关于编码你必须知道的知识和技巧

    知其然,知其所以然,彻底搞懂编码,搞定乱码 乱码问题是所有运维职业生涯中都会遇到的问题,本篇文章带你探究背后的原理以及解决的技巧 字符编码 我们知道计算机只认识二进制数据,其他格式的数据都需要转换成二 ...

  7. 视觉中国图片编码_学习编码第14天的应用视觉设计第4部分

    视觉中国图片编码 Goooood evening everyone! Yesterday was a short little blog as we came to the end of the se ...

  8. python open函数编码_Python基础学习——编码与读写

    编码与读写 编码,即将人类语言转换为计算机语言,就是[编码]encode():反之,就是[解码]decode().它们的用法如下图所表示: 将人类语言编码后得到的结果,有一个相同之处,就是最前面都有一 ...

  9. python为源文件指定系统默认字符编码是_系统编码、文件编码与python系统编码

    在linux中获取系统编码结果: Windows系统的编码,代码页936表示GBK编码 可以看到linux系统默认使用UTF-8编码,windows默认使用GBK编码.Linux环境下,文件默认使用U ...

最新文章

  1. php将关联数组输出到前台,如何使用foreach从PHP中的关联数组输出特定数据
  2. Angular CDK Overlay 弹出覆盖物
  3. Vue开源项目库汇总
  4. C# 命令行编译器详解
  5. 【Win 10 应用开发】InkToolBar——涂鸦如此简单
  6. 友盟统计--注意事项
  7. 让SignalR客户端回调支持强类型
  8. python choose语句作用_理解闭包是如何与变量作用域相互影响的
  9. hbuilder 个推登记应用
  10. uft自动化测试工具安装步骤_自动化测试灵魂三问:是什么、为什么和做什么
  11. 公有云、私有云、混合云的区别比较
  12. MongoDB更新文档(非常详细,不要错过~)
  13. UVA515 King
  14. 双十一大战收官:荣耀反超苹果,以新思维新模式傲视群雄
  15. openwrt: ipq4019 路由 资料汇总
  16. 车载高德地图显示服务器信息,车载高德一直gps定位中,怎么解决高德地图导航gps信号弱...
  17. IB选课指南及热门专业选课建议
  18. Forwarding Address字段
  19. 使用C语言播放一首音乐
  20. GST: Grouped Spatial-Temporal Aggregation for Efficient Action Recognition 论文阅读

热门文章

  1. 前端开发 简单表格的编写练习 0228
  2. 七牛云与python交互的教程
  3. python-教学管理系统-开发流程 草稿
  4. python项目-每日日考系统-数据结构
  5. Laravel定时任务的每秒执行
  6. redis查询key的数量
  7. mysql执行计划字段解释
  8. javascript--DOM概念
  9. HashMap、TreeMap、Hashtable、HashSet和ConcurrentHashMap区别
  10. MySQL学习足迹记录01--SOURCE,SHOW