Clean code
chapter1 naming
1.4 Casing conventions & programming languages
Now, before we dive into the concrete examples and the different variations and so on… we also have to stop at the important topic of casing.
In programming, we got four main ways of writing our names, four main casing, and that would be snake_case, camelCase, PascalCase, kebap-case.
Now snake_case looks like this: is_valid
, send_response
, where multiple words are separated with an underscore and everything is lowercase, for example, you use snake_case a lot in python, there, you use it for variable names, for function names and for method names, and that’s what you saw in the initial examples in the first course section already.
Now python uses snake_case, many other programming languages like jave and javascript use camelCase, which looks like this, isValid, sendResponse.
The same name, but now not with an underscore between words, but instead there is no separation between words, except for the starting character of the next word in line. The first character in the name is always a lowercase one, like the i
in theisValid
, and the s
in the sendResponse
, but then every word in that phrase starts with an uppercase charater, like the uppercase v
in Valid
and the uppercase R
in the Response
, again, this CamelCase notation is used by many other programming languages, but it’s used for the same things as python uses snake_case, and that would be (for) variables , function and methods.
Now another notation which we know is PascalCase, It looks like this:IsValid
, SendResponse
, and this is used by many programming languages. For example, by python, java and javascript for class name. Class names are typically written in PascalCase. And when it comes to kabob-case, it looks like this, and we, for example, know this from HTML, where HTML elements we might be building.
Now these are the four main ways of writting things, and mostly it comes down to conventions. When to use which notation, I outlined the most important conventions here. For example, for python, we use snake_case for variables, function and methods. And style guides for your favorite programming languages typically tell you which notation to use for what.
I wanna emphasize, of course, that no matter which casing you used, the name in the end, is always the same, just the way you write it is different, and therefore again, which programming language you choose does not really have an impact on how to write clean code, This is just an extra convention you should keep in mind, because, of course, following languages-specific conventions is also a part of writting clean code.
- dive into 深入地
Let’s dive into the detail of this code snippet
- variations 变体
This Class have five variations.
- stop at 停在
I want to stop at this function and dive into the detail.
- kebap-case 烤肉串体
You should use kebap-case in HTML
-
underscore 下划线
-
lowercase 小写 uppercase 大写
-
use … a lot 使用得很多
This command is used a lot in our daily development
-
separation 分隔
-
character 字符
This is a character array
-
notation表示法
-
comes down 归纳为
When it comes down to a simple rule.
- keep in mind 记住
We should keep in mind this important convention.
- languages-specific 语言特定的 (specific特定的)
I will talk about this specific type of class later.
Tips:这个单词/短语列表只是一些推荐学习的用词,但是此系列的重点不仅仅在于这些,而在于如何用英文表达一些逻辑,适合积累口语,大家可以仔细品读短文,找到自己喜欢的表达方式。
推荐的学习方法:先听几遍保证能听懂70%,再对照原文进行学习,找到自己喜欢的表达后反复造句让自己加深印象,跟着原文读一遍,然后再自己读一遍。
Source:【整洁代码 Clean Code-哔哩哔哩】 https://b23.tv/skgyGMC