当前位置:网站首页>Logic is a good thing
Logic is a good thing
2022-07-01 13:49:00 【Big data V】

Reading guide : Necessary knowledge of programming , It is also a basic daily ability .
author :Crossin sir
source :Crossin Programming classroom of (ID:crossincode)

“ English is not good, can you learn programming ?”
“ Is programming demanding on Mathematics ?”
Translation is : mathematics / Is English a prerequisite for learning programming ?
I think this problem is a bit like , If you are not tall, you can't play basketball . Although for professional basketball players , Height is a key factor , But for ordinary basketball fans , Even for a basketball related practitioner , This is not an inevitable condition . Put it on programming , Mathematics and English are both important , but :
At the entry stage , You don't have to care about this at all , Follow a tutorial and imitate it well Just go
For most daily development , Middle school level of mathematics and English have been able to cope 了
Different from the congenital condition of height , English and mathematics can be improved through learning , Where there is a shortage, there is a remedy . A popular sentence on the Internet :“ At the low level of effort of most people , There's no talent at all .” You can recite words for a long time , reading , It's enough to improve yourself . Always put XX I'm afraid it's more about making excuses for myself .
however , Have an ability , It really needs enough attention in the early stage of learning programming . But this , Many tutorials do not specifically emphasize , Related books often assume that you have mastered , So many learners are not aware of their weakness in this aspect , Leave hidden dangers for future study . All I have to say is :
Logic
In a way , Logic can be partially counted as mathematics , There are relevant contents in high school mathematics textbooks . This part also happens to be the foundation we need to know most when learning programming .

01 Boolean algebra
from really (1)、 false (0) Two kinds of state , as well as And (and)、 or (or)、 Not (not) Three basic operations constitute . Boolean algebra seems simple , But it corresponds to the two states of on and off in the digital circuit , yes The logical basis of computer . You may have heard of , Everything on the computer is internally controlled by 0 and 1 Indicated by , In other words , All the behaviors of the computer , The essence is realized by Boolean logic .
In programming languages , Boolean type (bool) It is also a very important existence . Without it , We can't make conditional judgments , There is no way to control the execution of the program .Python Of if、while Statements must be judged by the type of rybool .
therefore , Even if you don't want to study logic deeply , The basic rules of Boolean algebra must be understood anyway . Simply speaking , This is the next one “ Truth table ”:
p | q | not p | p and q | p or q |
1 | 1 | 0 | 1 | 1 |
0 | 1 | 1 | 0 | 1 |
1 | 0 | 0 | 0 | 1 |
0 | 0 | 1 | 0 | 0 |
These basic rules will combine into more complex logic , such as :
not (p or q) Equivalent to (not p) and (not q)
( Example :“ Not administrators or members ” amount to “ Not an administrator and not a member ”)
The logic judgment faced in actual development is complex and diverse , But in the final analysis, it will be transformed into the most basic rules .
Thinking questions 1: How to express “ New users registered through the activity or recharge more than 100 Old users of Yuan , Except for internal personnel ”
02 Propositional logic
Statements with unique truth values are called propositions , A proposition that cannot be decomposed into simpler propositions is called an atomic proposition . such as ,“1+1=2” It's an atomic proposition ,“ All cats are white ” It's an atomic proposition ( False proposition ),“ There are aliens ” It is also an atomic proposition ( Although we can't judge the truth , But the result must be unique ). The combination of propositions and logical operations , It will produce more complex logic .
such as Sufficient and necessary conditions .
If the proposition p It is inevitable to deduce a proposition q, that p Namely q Sufficient conditions of ,q Namely p Necessary conditions , Write it down as p→q.
For example, the poetry of Han Yuefu “ Mountain without edges , Harmony , But I dare to fight with you ”, How to express in logical language ?
( Mountain without edges and Harmony ) → And you Jue ?
Think about whether something is wrong ? According to semantics ,“ Mountain without edges ”、“ Harmony ” yes “ And you Jue ” Of Necessary condition , If “ And you Jue ” It's true , There must be “ Mountain without edges ” and “ Harmony ”, On the contrary, it may not . So the correct logic is :
And you Jue → ( Mountain without edges and Harmony )
Another example syllogism .
① You can't learn programming well without mastering basic logic knowledge
②Python Is a programming language
therefore , Learn from good examples Python You need to master basic logical knowledge
A big premise plus a small premise , A conclusion can be derived . This is the most commonly used form of argument , It seems simple , But there are always people who are confused about this . Take up a Examples of mistakes :
① Rich people use iPhone XS Max
② I use iPhone XS Max
therefore , I am rich
These logical relationships 、 The derivation process is closely related to the logical structure in the program . If you can't keep your mind clear about this , The code written is likely to differ from expectations , Or there are loopholes in some special cases .
Thinking questions 2: A small function of signing in and receiving awards every day , Every day 11~13 Point and 18~20 Open up , Ordinary users can receive it once a day , Member users can receive it once in each period . How to realize the logical structure of this program ?( I often take this as an interview question , Many people can't give the right answer in a short time )

03 inductive
occasionally , We cannot deduce an inevitable conclusion through logic , But it can still Through a series of experience and existing conclusions , Find out the basic rules .
such as :
①X The team has always equipped all members Dell Notebook as work computer
②C The teacher recently joined X The team
Through these two points , We can derive that ,C Teachers may also use Dell The notebook .
But you need to know The conclusion of induction is not necessarily true , If you encounter the inevitable counterexample of logical reasoning , Even if it is no longer in line with common sense , The conclusion of induction will also be overturned .
For example, in addition to the above two points , We also know that :
③C The teacher signed an apple endorsement
④ Apple spokesmen are not allowed to use other brands of mobile phones and notebooks
that , Above “C Teachers use Dell The notebook ” The conclusion is not tenable .
although Induction is not inevitable , But it is still important to solve the problem . Especially when you encounter errors in development, you need debug( debugging ) When , Not all errors can be directly seen from the error information ( such as Python Garbled code often occurs during development ), At this time, if you have rich experience and strong induction ability , The efficiency will be greatly improved . This is also an important manifestation of the gap between senior programmers and junior programmers .
Now the online programming tutorials are overwhelming , But what? , Everyone likes to write about how to make up a picture of a reptile catching 、 Grasp data and so on , But few articles are willing to talk about the thinking process behind . Readers don't want to read it after writing , Because I can't see any effect , Where can we adjust a few functions to get a result that is straightforward .
That you find , You can write the same code according to the example , But once an error is reported or there is no expected result , I'm completely blind , The parameters can only be changed from east to West , Run it over and over again , Expect a miracle . A new question in the future , I still don't know where to start .
This is because the logic behind the program is not understood . I often say in the Q & a group : Don't guess when you encounter a program error ! Make assumptions , Then verify the hypothesis through the output , Finally, locate the problem .
The text is just an introduction , It's impossible for you to master logic . But the logical basis mentioned above , Any book 《 Discrete Mathematics 》 perhaps 《 logic 》 There are all books on , And just a small part at the beginning is very useful . Find a book to read .
I really want to learn programming well , Don't limit yourself to reading online tutorials , These are all chewed and fed into your mouth . If you can only accept such secondary processed knowledge , Without the process of chewing , Then your baby teeth on study will never fall out .
Understanding that logic and thinking are logical is not completely equivalent . Some people have never learned logic , It's logical to speak and do , While some people have learned logic , It's just reciting mathematical formulas , All day “ Logical thinking ” Talking doesn't mean doing things logically .
On the network , You can often see some logical fallacies , Give a few common examples :
overgeneralization : You say with X The product encountered Y problem . Someone retorted , I also use X product , People around me also use X product , No problem , So you must have deliberately hacked .
Relevance is cause and effect : People in a certain area like to drink raw milk , At the same time, the average life expectancy of people in this area is higher than that in surrounding areas , So drinking raw milk can prolong life .
Black and white : The Internet is attacking a product for eavesdropping on user chat , And I have a criminal record of spam advertising before . You say eavesdropping is technically unrealistic , There is also a lack of clear evidence . Then someone thinks you don't spray together , You are the Navy 、 cleaning .
……
Similar illogical flooding the network .
There are many prejudices around us 、 The concept of discrimination , There are many people who like to argue “ Bar fine ”, in the final analysis , You will find that these people have a common characteristic : Logic confusion . such as , All of them will be sexist 、 Regional discrimination , It is because some special cases make inferences about the whole . And steal the concept 、 Reverse cause and effect 、 Motive speculation , It's the logical fallacy that punks like to abuse .
Not just in programming , If we pay more attention to logic , There will be fewer contradictions in this world . Even without special study and training , Just keep humble , Learn to listen , Treat different voices with an inclusive attitude , Think more about each other's views , Looking at things from different angles , Your logic will be more complete .
Thank you for forwarding and praising ~

Extended reading

Extended reading 《 Causality : Model 、 Reasoning and inference 》
Dry goods go straight to
More exciting
Enter the following dialog box in the official account dialog box key word
See more quality content !
read | book | dried food | Make it clear | God operation | handy
big data | Cloud computing | database | Python | Reptiles | visualization
AI | Artificial intelligence | machine learning | Deep learning | NLP
5G | Zhongtai | User portrait | mathematics | Algorithm | Number twin
According to statistics ,99% The big coffee is concerned about the official account
边栏推荐
- Learning to use livedata and ViewModel will make it easier for you to write business
- arthas使用
- 使用CMD修复和恢复病毒感染文件
- Etcd summary mechanism and usage scenarios
- 开源者的自我修养|为 ShardingSphere 贡献了千万行代码的程序员,后来当了 CEO
- Introduction to topological sorting
- Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its
- 单工,半双工,全双工区别以及TDD和FDD区别
- leetcode 322. Coin Change 零钱兑换(中等)
- 2022年PMP项目管理考试敏捷知识点(6)
猜你喜欢

洞态在某互联⽹⾦融科技企业的最佳落地实践

焱融看 | 混合云时代下,如何制定多云策略

详细讲解面试的 IO多路复用,select,poll,epoll

2022 · 让我带你Jetpack架构组件从入门到精通 — Lifecycle
![[anwangbei 2021] Rev WP](/img/98/ea5c241e2b8f3ae4c76e1c75c9e0d1.png)
[anwangbei 2021] Rev WP

MySQL六十六问,两万字+五十图详解!复习必备

Summary of interview questions (1) HTTPS man in the middle attack, the principle of concurrenthashmap, serialVersionUID constant, redis single thread,

2022上半年英特尔有哪些“硬核创新”?看这张图就知道了!

开源实习经验分享:openEuler软件包加固测试

我们该如何保护自己的密码?
随机推荐
Computer network interview knowledge points
Applet - multiple text line breaks in view
8款最佳实践,保护你的 IaC 安全!
Etcd summary mechanism and usage scenarios
详细讲解面试的 IO多路复用,select,poll,epoll
受益互联网出海 汇量科技业绩重回高增长
被裁三个月,面试到处碰壁,心态已经开始崩了
[flask] flask starts and implements a minimal application based on flask
当你真的学会DataBinding后,你会发现“这玩意真香”!
Summary of interview questions (1) HTTPS man in the middle attack, the principle of concurrenthashmap, serialVersionUID constant, redis single thread,
Spark source code reading outline
“国防七子”经费暴增,清华足足362亿元,甩第二名101亿 |全国高校2022预算大公开...
【IoT毕设.上】STM32+机智云AIoT+实验室安全监控系统
Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its
[Jianzhi offer] 54 The k-th node of binary search tree
QT社团管理系统
【剑指Offer】54. 二叉搜索树的第k大节点
Blind box NFT digital collection platform system development (build source code)
After being laid off for three months, the interview ran into a wall everywhere, and the mentality has begun to collapse
Leetcode question 1: sum of two numbers (3 languages)