当前位置:网站首页>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
边栏推荐
- [cloud lesson] EI lesson 47 Mrs offline data analysis - processing OBS data through Flink
- 01 basic introduction - concept nouns
- Ideas and methods of system and application monitoring
- Speech recognition (ASR) paper selection: talcs: an open source Mandarin English code switching corps and a speech
- Maximum likelihood estimation and cross entropy loss
- 爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
- Node. Js: express + MySQL realizes registration, login and identity authentication
- 【Yann LeCun点赞B站UP主使用Minecraft制作的红石神经网络】
- Force deduction brush question - 98 Validate binary search tree
- Linear distance between two points of cesium
猜你喜欢
Cesium 点击绘制圆形(动态绘制圆形)
Tencent T4 architect, Android interview Foundation
OLED屏幕的使用
OceanBase社区版之OBD方式部署方式单机安装
Anaconda安装后Jupyter launch 没反应&网页打开运行没执行
Boder radius has four values, and boder radius exceeds four values
I've seen many tutorials, but I still can't write a program well. How can I break it?
电子游戏的核心原理
JMeter server resource indicator monitoring (CPU, memory, etc.)
02 basic introduction - data package expansion
随机推荐
Leetcode question 283 Move zero
01 基础入门-概念名词
Problems encountered in using RT thread component fish
【GET-4】
[network planning] Chapter 3 data link layer (3) channel division medium access control
Appx code signing Guide
Period compression filter
Node.js: express + MySQL实现注册登录,身份认证
JMeter server resource indicator monitoring (CPU, memory, etc.)
Catch ball game 1
微信小程序常用集合
Unity writes a timer tool to start timing from the whole point. The format is: 00:00:00
Quel genre de programmation les enfants apprennent - ils?
String长度限制?
【每周一坑】信息加密 +【解答】正整数分解质因数
JVM_ Common [interview questions]
腾讯云数据库公有云市场稳居TOP 2!
Extraction rules and test objectives of performance test points
Technology sharing | packet capturing analysis TCP protocol
OLED屏幕的使用