我给新手程序员的实用建议
程序员 新手
![](/data/attachment/album/202208/21/161450vm33z0ex30w4073z.jpg)



> 
> 做一个高效的、充满好奇心的问题解决者吧！这会帮助你成为一名成功的程序员。
> 
> 
> 


你是否曾经遇到过这样一种情况：你想解决一个问题，并且你在 YouTube 或 Google 中找到了相关的教程。嗯，你觉得看会了，可真做起来，却止步不前，大脑一片空白。你感觉自己每一行代码都看懂了，可一旦离开了那个教程，就步履维艰。如果你在 HackerRank 或 LeetCode 上看过别人的解题过程，你就能体会到，一个有追求的程序员第一次看到这些挑战时，他会是何种感受。举例来说，假设你正在学习一门新语言，在你刚开始理解这门语言的基础知识的时候，你看了一个教程，摩拳擦掌，结果发现自己无法独立应用学到的知识，这反过来可能会导致你怀疑自己的知识和能力。


### 把教程付诸于实践


你应该从头开始吗？如果你这么做，你可能很快就会发现自己重复学习了很多次相同的知识点。虽然从头开始并不一定是种浪费，但是，你该如何变得更高效呢？


死记硬背在编程中完全是行不通的。话虽如此，但你也不能够忽视熟悉语法的重要性。因为，死记硬背和养成习惯之间是有明显区别的。习惯是很难打破的。要养成多使用编程语言的常规语法、函数、方法、模式、范式和构造的习惯，这样你才能掌握它。掌握一门编程语言需要大量的创造力和练习。练习语法是非常必要的，直到它们能在你的脑海中自然地浮现，就像血液在血管里流动一样。


### “问题解决”的工作原理


那么，你该采取什么样的方案呢？这实际上取决于许多因素。这些因素可以是任何东西，下至技术限制，上至用户需要。世界上有无数的问题，每个问题都有许多解决方式。如何选择一个最好的？这就需要<ruby> “问题解决” <rt>  problem-solving </rt> <ruby>  的技巧了。 </ruby></ruby>


下面是一个简单的例子。你需要把两个数**相加**，让它们等于 **6**。显然，你有多种方式可供选择：


**3 + 3 = 6** 或 **4 + 2 = 6** 或 **5 + 1 = 6**


同理，如果你需要让两个数字，经过一次减法、乘法或除法运算后，得到的结果为 **6**。你仍然有很多选项，包括：


**8 - 2 = 6** 或 **12 / 2 = 6** 或 **3 \* 2 = 6**


每种方案都有它固有的限制，且各不相同。当你在现实生活中尝试做出一个高效的方案时，你必须要考虑到所有的限制。这个方案可行吗？有什么障碍吗？有可操作性吗？是否可扩展呢？而如何最小化约束，并做出一个最优方案，就取决于问题类型和业务需要。


### 练习很重要


编程的目标不仅仅是解决问题。因此，从工程视角理解代码**如何**工作始终是一个优势。这就是代码审查在企业级开发中发挥作用的地方。编程的最低要求是具备基本的编码知识，包括语言的语法、函数和方法。归根结底，“写代码”是需要你去**写**的，所以练习总是有助于提高你的技能。流畅的写作和复杂方案的开发都来自于持续的学习和训练。


### 学习编码


我撰写和分享这篇文章，是为了鼓励新程序员去探寻自己的内心，寻找那个“优秀的问题解决者”。请不要停止相信自己。


要成功编码，你需要培养许多习惯。下面是我在学习编码时保持高效的方法：


1. 一个包含语法、方法和函数 [速查手册](https://opensource.com/downloads/cheat-sheets) 总能应付不时之需。
2. 将问题分解成更小的部分，便于追踪。
3. 尝试理解代码运行的核心概念。
4. 构思解决方案时，大可发挥你的创造力 —— 但刚开始还是要注重基础。
5. 在练习时，创建尽可能多的应用和组件。
6. 永远不要从 Stack Overflow/Exchange 等开放平台上复制/粘贴代码，特别是在不了解上下文的情况下。
7. 跟着教程做了一遍后，尝试从头开始构建所有内容。即使你只能独立完成一半，那也仍然是一个成就。


祝我们所有人好运！




---


via: <https://opensource.com/article/22/8/coding-advice-new-programmers>


作者：[Sachin Samal](https://opensource.com/users/sacsam005) 选题：[lkxed](https://github.com/lkxed) 译者：[lkxed](https://github.com/lkxed) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Have you ever been stuck or gone blank trying to solve a problem related to something that you just learned from YouTube or Google tutorials? You seem to understand every line of the code, but without the tutorial, you find yourself in a difficult position. If you have looked at problem-solving in HackerRank or LeetCode, you can relate to how an aspiring programmer feels seeing those challenges for the first time. Everything seems out of the box! Being unable to apply what you learned from a tutorial might make you doubt your knowledge and abilities as you begin to understand the basics of the programming language you're learning.

## Putting programming tutorials into practice

Should you start back at the beginning? If you do that, you may soon find that you've covered those topics more than enough times. Starting from scratch is not necessarily a waste, but how can you be more efficient?

Memorization is simply not the solution in programming. Having said that, you cannot neglect the importance of getting used to syntaxes. There is a significant difference between memorizing and making a habit. The latter is difficult to break. Make a habit of playing around with the programming language's regular syntaxes, functions, methods, patterns, paradigms, and constructs to ace it. Acing a programming language involves a lot of creativity and practice. It is essential to practice syntaxes until they flow as smoothly in your brain as the blood runs through your veins.

## How problem-solving works

How you approach solutions depends on many factors. These factors could be anything from technical constraints to user needs. The world has innumerable problems and there are many ways of solving each. Deciding on the best way involves extensive problem-solving skills.

Here is a simple example. You need to achieve a result of **6** by *adding* two numbers. You can accomplish this several ways:

**3+3=6** or **4+2=6** or **5+1=6**

Similarly, say you need to achieve a result of **6** by using two numbers and either subtraction, division, or multiplication. You have many options, including:

**8-2=6** or **12/2=6** or **3*2=6**

Each solution may have a different constraint. You must consider all of these when developing effective real-world solutions. Is the solution feasible? Accessible? Interoperable? Scalable? Minimizing the constraint and developing an optimal solution depends on the business need and type of problem.


## Practice matters

The goal of programming is much more than problem-solving. Understanding *how* the code functions from an engineering perspective is always an advantage. That's where code reviews come into play at an enterprise level. The bare minimum requirement in programming is to have basic coding knowledge, including the language's syntaxes, functions, and methods. At the end of the day, coding is what you *do*, so practicing always helps improve your skills. Fluency in writing and developing complex solutions comes with consistent practice and learning.

## Learning to code

My goal for writing and sharing this article is to encourage new programmers to seek the great problem solver in themselves. Please don't stop believing in yourself.

There are many habits to nurture for successful coding. Here are my ways of staying effective while learning to code:

- A
[cheat sheet](https://opensource.com/downloads/cheat-sheets)of syntaxes, methods, and functions can come in handy. - Break problems into smaller parts to make them easier to follow.
- Try to understand the core concept of how code functions.
- Try to improvise with your solutions but always stick to the basics in the beginning.
- Create as many applications and components as possible while practicing.
- Never copy/paste code from open platforms like stack overflow/exchange, especially without understanding the context.
- After following the tutorial, try to build everything from scratch. If you manage to accomplish half of it by yourself, that's still an achievement.

Good luck to all of us.

## 5 Comments