[程序员英语口语][Clean code]Chapter1-2 Why good names matter

Clean code

chapter1 naming

1.2 Why good names matter

When it comes to naming things, there is one simple overarching rule, and that would be names should be meaningful.

This really is all, this is the core idea whenever you name something no matter if that’s a variable or a function or a class, the name should be meaningful. It’s should transport what’s stored in a variable, or what a function or method does without having to look at the code inside of that function or method, or without exploring the value stored in a variable.

For example consider this code snippet. It’s not a lot of lines, but it’s really no clear at all what’s going on there.

What are we doing there. What does process do and what is the value of login. Is it the function for which existence we check? Is it a boolean value? Is it a string? an error code? We don’t know at all.

And now consider this alternative. It’s the same code, but it’s way clearer, It’s now obvious that we are creating a user

Which we are then saving? maybe to file or to a database, this might not matter to us, but we are saving the user.

And we got isLogin instead of login, making it clear that this very likely holds the result of checking whether that user is logged in or not.

So a boolean value , true or false. This is now very readably, and very easy to understand, even though it’s the same number of lines. The only difference is that now we have meaningful names.

So picking good names in your code really matters, If we have well-named things, variable and so on. In our code, we allow our readers and people reading our code, to understand that code without going through all the details, withoug diving into it in detail. Consider this examples. In all three example.

It’s pretty clear what this code does, even though we don’t know the details. We don’t need to dive into the rest of the code just to understand these snippets.

That’s why naming matters. Now I will emphasize right away, we will not always agree, because, obviously, there is more than one way of naming something. I will explore this rules. We can follow to come up with good names, but ultimately, you will still always have more than one option. But this here is also readable and not necessarily worse. You could definitely find arguments for either of the two names. And it’s up to you how you wanna name something. There are, however, also some names which clearly are bad.

So that by the end of the section, you have a clear understand of what makes up a good name, and then of course, It’s up to you to pick which good name you wanna go with.

Recommend:

1.when it comes to 当说到…时

When it comes to software development, It’s important to know how to write clean code.

2.overarching 首要的,重要的,关键的

overarching goal

3.matter 重要

  • You should pay no matter if you are a child or adult.

  • What does it matter.

  • That’s why it matters.

4.code snippet 代码片段

5.not … at all 根本不

It doesn’t matter at all

6.alternative 替代品,替代的方案

Here is a alternative solution

7.going through all the details/diving into detail 进入到细节

Let’s dive into the detail

8.emphasize 强调

I want to emphasize this part.

  1. explore 展开

Let me explore this rule

10.come up with 想出(方案)

Hope we come up with a better solution

11.option 选择

Is there any other option?

  1. either of 其中一个(单选)

You can just choose either of them.

13.makes up

What make up a computer?

14…you wanna go with 你想选的

You can bring whatever you wanna go with.

Tips:这个单词/短语列表只是一些推荐学习的用词,但是此系列的重点不仅仅在于这些,而在于如何用英文表达一些逻辑,适合积累口语,大家可以仔细品读短文,找到自己喜欢的表达方式。

推荐的学习方法:先听几遍保证能听懂70%,再对照原文进行学习,找到自己喜欢的表达后反复造句让自己加深印象,跟着原文读一遍,然后再自己读一遍。

Source:【整洁代码 Clean Code-哔哩哔哩】 https://b23.tv/skgyGMC

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值