当前位置:网站首页>Logic is a good thing
Logic is a good thing
2022-07-06 20:23:00 【Crossin's programming classroom】
Zero basis python Introductory tutorial :python666.cn
Hello everyone , Welcome to Crossin Programming classroom of !
Crossin I often receive such questions at the backstage of official account :
“ 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 .
One 、 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 “ through New users who have registered through activities or recharge more than 100 Old users of Yuan , Except for internal personnel ”
Two 、 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 )
3、 ... and 、 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 、 Flatterer .
……
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 .
Conversely , When you find that the Internet is full of illogical remarks , I don't want to express any views anymore .
thank forward and give the thumbs-up The fellow ~
_ Previous articles are recommended _
Core principles of video games
If you need to know Paid premium courses And Teaching Q & a service
Please be there. Crossin Programming classroom of Internal reply : 666
边栏推荐
- BUUCTF---Reverse---easyre
- PowerPivot——DAX(初识)
- HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
- Unity making plug-ins
- In line elements are transformed into block level elements, and display transformation and implicit transformation
- 【GET-4】
- 02 basic introduction - data package expansion
- 【每周一坑】输出三角形
- Poj3617 best cow line
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
猜你喜欢
What programming do children learn?
How does kubernetes support stateful applications through statefulset? (07)
Enumeration gets values based on parameters
B-杰哥的树(状压树形dp)
持续测试(CT)实战经验分享
Quel genre de programmation les enfants apprennent - ils?
Rhcsa Road
“罚点球”小游戏
Notes on beagleboneblack
Introduction of Xia Zhigang
随机推荐
5. 无线体内纳米网:十大“可行吗?”问题
腾讯架构师首发,2022Android面试笔试总结
永磁同步电机转子位置估算专题 —— 基波模型类位置估算概要
Redisson bug analysis
rt-thread i2c 使用教程
JVM_ Common [interview questions]
Recyclerview not call any Adapter method :onCreateViewHolder,onBindViewHolder,
RT-Thread 组件 FinSH 使用时遇到的问题
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
“罚点球”小游戏
逻辑是个好东西
Color is converted to tristimulus value (r/g/b) (dry stock)
Event center parameter transfer, peer component value transfer method, brother component value transfer
Case ① | host security construction: best practice of 3 levels and 11 capabilities
Linear distance between two points of cesium
Crawler (14) - scrape redis distributed crawler (1) | detailed explanation
腾讯云数据库公有云市场稳居TOP 2!
Poj3617 best cow line
Groovy基础语法整理
Web security - payload