# Logic (That's what programming is centered around right?)

This topic is 1422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So, let's peak over at Wikipedia for a sec, to the article on "logic."

http://en.wikipedia.org/wiki/Logic

So, yeah, big topic. Lot's of research. Years and years of exhaustive toiling over the meaning of meanings....

Now you want to be a computer programmer. You see a few tutorials, play with a few languages. Write a few lines of code...

But how is your logic and reasoning?

Are you a problem solver? A good one?

I figured after watching an iTunes U course on Computer Science that logic is the main topic of a college level CS degree.

How do we solve complex problems efficiently?

Do you think that logic should be a prerequisite to computer programming?

If so, why don't we teach logic in grade school as a separate course?

##### Share on other sites

I voted "It depend" because logic does play a role in programming, but it's not all that programming is all about (if it was electronics then ill say it's way more proeminent).

True, a lot of ifs/switchs/comparaisons are used in most programs, but they also work with numbers (add/sub/mult/div ect...) so logic is only half of programming id say, the other half being computational task and IO stuffs.

Do you think that logic should be a prerequisite to computer programming?
If so, why don't we teach logic in grade school as a separate course?

Well, i belive most programming course should include a chapter or two on logic, i learned mine in my electrician course, and it was really easy for me (i didn't knew programming at that time very much).

Edited by Vortez

##### Share on other sites

I voted "It depend" because logic does play a role in programming, but it's not all that programming is all about (if it was electronics then ill say it's way more proeminent).

True, a lot of ifs/switchs/comparaisons are used in most programs, but they also work with numbers (add/sub/mult/div ect...) so logic is only half of programming id say, the other half being computational task and IO stuffs.

Do you think that logic should be a prerequisite to computer programming?
If so, why don't we teach logic in grade school as a separate course?

Well, i belive most programming course should include a chapter or two on logic, i learned mine in my electrician course, and it was really easy for me (i didn't knew programming at that time very much).

I am not sure how to best classify or describe programming (at a meta level).

I think probably just thinking things and writing out whatever they happen to be thinking at the moment (in code form) probably mixed with a fair bit of trial-and-error, are probably a pretty big part of the process as well.

well, and also sometimes the "feel" of engaging in a direct fiddle-and-feedback loop:

fiddle with code;

recompile and test;

fiddle a little more;

...

though, in terms of the experience, it seems like it should need to be very fast for this to work, it sort of works with a cycle time of potentially many minutes or more.

spending too long thinking without actually doing anything can make one feel irritable.

sometimes, it may get to be one acting out of habit, maybe doing a few cycles or building and testing things for "no reason in particular", it can become somehow oddly soothing/relaxing.

then again, apart from this sort of thing, my life is pretty empty sometimes...

##### Share on other sites
While formal logic has similarities to programming, it's really a separate field.

EDIT:
Re: Electronics.
Logic is not a prerequisite for electronics either. Boolean logic as used in electronics uses different symbols and terminology to formal logic, and is rather small subset of a logic course. Boolean algebra and karnaugh maps are better coupled with a math course or a circuits course than a straight logic course. Edited by King Mir

##### Share on other sites

Formal logic is probably a bit over the head for most children in grade school, even many first year students at university struggle with it.

So I don't think it's really needed in grade school, but for any higher technical or scientific education it should definitely be included, and I would be surprised if there wasn't at least some course in logic in any such program.

But a prerequisite? no... you can go a long way in programming without any knowledge of formal logic, just using your intuition.

It definitely helps knowing something about it though (in programming, and in life in general...)

##### Share on other sites

This is a bad question because "Logic" can mean many things. Primarily, it could be a branch of Philosophy or a branch of Mathematics. However, the answer is still "no". A smart kid can learn programming without any prerequisites whatsoever.

I started to program when I was 7. My dad taught me a few basic things about how his programmable calculator worked, and I played around with it until I figured it out. If instead of teaching me what "if" and "goto" do he had started by introducing Logic and whatever other things people think should be prerequisites for programming, I would have been overwhelmed and I wouldn't have learned anything.

##### Share on other sites
First I voted "it depends", then changed my answer to "no" because people are lazy when it comes to definitions.

In order to program you need to think logically, you need to be able to reason through problems. You need to be able to explain a problem in terms of equations.

However, the ability to reason is very different than the study of reason. Most people are able to logically reason their way through problems without formal study on the rules of logic, how implication works, playing reasoning mind-games, or, (since you likely meant computational logic rather than logic generally) study their way through formal languages of logic or proofs.

Also, due to lax definitions, I would say no to 'prerequisite', but yes to 'corequisite'. You need the material at the same time you are learning to program.

Logic is a big field. You can get advanced degrees in the study and expression of logic by itself. You don't need that as a prerequisite to beginning to program.

Finally, while I will agree that computer science can rely on formal logic, that is not the core. I would argue computer science is an application of general mathematics rather than logic. The machines are computational engines designed around mathematics, the values used in computation are a perfect fit within discrete mathematics, and when programmed the applications frequently align themselves around mathematics topics like linear algebra, trig, accounting and verifiability, cryptography, and more.

Do you need the ability to apply reason and the ability to break problems down, build problems up, and find equivalent solutions? Yes. All of these are areas of logic that you need while learning how to program.

Do you need formal study on logic, the history of logic, philosophy of logic, semantics of logic, logic in debate, logic in philosophy, logic in mathematics? No. While these can potentially be valuable in a career, and many people in computer science rely on them, they are not a prerequisite to programming. Edited by frob

##### Share on other sites

This is a bad question because "Logic" can mean many things. Primarily, it could be a branch of Philosophy or a branch of Mathematics. However, the answer is still "no". A smart kid can learn programming without any prerequisites whatsoever.

I started to program when I was 7. My dad taught me a few basic things about how his programmable calculator worked, and I played around with it until I figured it out. If instead of teaching me what "if" and "goto" do he had started by introducing Logic and whatever other things people think should be prerequisites for programming, I would have been overwhelmed and I wouldn't have learned anything.

yeah. I mostly started out fiddling with QBasic and later Turbo C and DJGPP and similar back when I was in elementary school (mostly on my own).

at the time, I didn't even really know what the order of operations were or similar, but it didn't take long to learn them from observation.

I did ok in high-school level algebra, but basically sucked at everything else.

got to college, pretty much sucked at everything.

and, as well, suck at pretty much anything life-in-general related.

not particularly good with dealing with abstract thinking either.

...

still reasonably good at programming though at least.

like, in life, there are relatively few things that actually make sense. programming seems to be one of them.

I suspect in many ways, it may be a lot more fundamental than all of the "meta" and academic disciplines and similar that people seem to try to glue onto it.

##### Share on other sites

However, the ability to reason is very different than the study of reason

Hmm. Good quote. Question though, do you think that taking a CS course in college teaches you to reason at a higher level? And when it comes to computer programming, don't  you think that a person should be able to reason at a higher level for that profession?

Sure, I can solve lots of problems, and I can reason through stuff, but there is no way I could write such complex algorithms as are out there to do complex tasks. It just feels like such reasoning/logic comes from college courses, and not from common sense.

The main reason I am asking this question is to find out if I need to learn about logic in order to become a better programmer, or at least a faster problem solver.

##### Share on other sites
Learning to write algorithms would probably come from studying a lot of existing algorithms and software patterns. It about of being able to express a problem in a generic way, and knowing which pieces can go together for the bigger picture. It's also about being able to articulate how you go about solving a problem yourself.

A formal logic course won't teach you that.

##### Share on other sites

However, the ability to reason is very different than the study of reason

Hmm. Good quote. Question though, do you think that taking a CS course in college teaches you to reason at a higher level? And when it comes to computer programming, don't  you think that a person should be able to reason at a higher level for that profession?

Sure, I can solve lots of problems, and I can reason through stuff, but there is no way I could write such complex algorithms as are out there to do complex tasks. It just feels like such reasoning/logic comes from college courses, and not from common sense.
We gain a certain amount of logic and reasoning through experience. They start out at a basic level (touching the stove is hot, falling down the stairs is painful, dirt tastes bad), where through experience we learn to reason about the world around us (touching something in the oven might also be hot, falling off a cliff might also be painful, mud probably also tastes bad). As we study in school and in life we gain more experience and more nuance.

Normally in a CS program the theory courses begin in the third year. During the first two years people are exposed to certain types of logic and reasoning, but they don't have any courses dedicated to it. Some students may ask questions about it, others will not. Also some students will drop out of the program and become arts or humanities majors. By the time you get into subjects like compiler theory, algorithmic theory and complexity theory, course where more formal logic is used, the instructors know they must generally teach a bit of formal reasoning skills to the students.

The main reason I am asking this question is to find out if I need to learn about logic in order to become a better programmer, or at least a faster problem solver.

I have only once heard someone seriously complain about having too much knowledge. It was because so many people kept coming to them asking for assistance that they were struggling to get their own work done.

Gaining more knowledge and experience in a field you find interesting is valuable in itself. If you want to increase your knowledge in a topic or field, that is reason enough to do it.

##### Share on other sites

So many points I would like to comment on on that post frob, good one.

Your first paragraph gives me some ideas about AI in programming. Some type of Experience Algorithm, or inference.

I like your last sentence also. I could increase my knowledge in a field, but if it is unnecessary to a goal I might not.

I felt that learning about games and game mechanics and game theory, even if a little, would help me to understand them more. I saw that a lot of topics here were technical, and there weren't many discussions about game theory and such. I wanted to get the the core of what games are, and why people play them, and why people prefer one over another. I mean, if I am making a game I want to sell, I figure such information would be useful.

Now I was wondering if when learning to program better, I should learn logic or study algorithms and such.

Now, I can relate this to another venture I took, to learn chess

What I found is that chess is a fun game, but it becomes less fun when you are playing someone who has studied all the possible opening moves and middle game variations and end- game variations. It becomes less fun when you are playing against someone who can see 20 moves ahead. It is more fun when you play with someone of your equal.

Also, if one understands the rules of chess, and the limitations and strengths of the pieces, one can naturally play a "best move" without study of chess theory.

Why is it not fun to play with people who went deep? They beat you every time!

I think there are two ways to go about logic. Understanding the building blocks of logic very well, and studying logic and reading endless books on logic. I prefer the former.

Understanding the DO's and DON'Ts and the WHYs.

I think I should apply this thinking to all new things I learn, to learn the basic building blocks so well that I can solve more complex problems with them.

Variables to functions to classes etc.

Edited by Tutorial Doctor

##### Share on other sites

Learning to write algorithms would probably come from studying a lot of existing algorithms and software patterns. It about of being able to express a problem in a generic way, and knowing which pieces can go together for the bigger picture. It's also about being able to articulate how you go about solving a problem yourself.

A formal logic course won't teach you that.

yes. a fair bit of programming is mostly rehashing things which already exist, or taking something that have been used in one context and applying it in a slightly different context, ...

probably having an ability to fit largish amounts of random stuff into their memory is on-par with having an ability to really understand or reason about it.

and, with memory, one can also benefit that others people have largely done most of the actual thinking and reasoning work, so to a large degree it becomes more a matter of remembering having seen a good or at least adequate solution which can be made to fit the current problem (or maybe remembering various solutions and ranking them according to some or another metric, ...).

##### Share on other sites

so to a large degree it becomes more a matter of remembering having seen a good or at least adequate solution which can be made to fit the current problem

Nice way to put it! That is what I meant by the chess thing. I remember playing this one chess game that teaches you how to play chess. I think it was ChessMaster for PC. He didn't teach you all the different variations and such. He said the move you should play is "the best move."

So he taught you how the pieces move and how to best move the pieces. Then he gives you a scenario and says, "play the best move." Now, there were good moves on the board also, but I had to play the best move. He then explains why the move is the best move. Usually, when you move "with tempo" that is the best move.

I wonder if there is some small basic principles of programming, that I could use as building blocks to solve more complex computational problems. There is probably a term out there that describes what I am talking about, I just haven't run across it yet.

##### Share on other sites

I wonder if there is some small basic principles of programming, that I could use as building blocks to solve more complex computational problems. There is probably a term out there that describes what I am talking about, I just haven't run across it yet.

Thats pretty much what programming is in the end. No matter what happens youll still end up using a loop or using an if or whatever other part of programming.

##### Share on other sites

Premise 1: All reasoning requires logic.

Premise 2: Programming a computer requires reasoning.

Conclusion: Computer programming requires logic.

Of course, you can come to that conclusion through trial and error, perhaps by throwing darts at a dart board with random words taped to it, or hiring infinite monkeys with spell-correcting word processors.  There are approximately 2¹? seconds in the expected lifetime of the universe, you can do it if you start now.

##### Share on other sites

If you really want

You must try though

##### Share on other sites

There are approximately 2¹? seconds in the expected lifetime of the universe, you can do it if you start now.

TIL the universe ends in three days

##### Share on other sites

Premise 1: All reasoning requires logic.

Premise 2: Programming a computer requires reasoning.

Conclusion: Computer programming requires logic.

The problem is that premise 1 is false.

Logic is to reason as grammar is to language. And I wouldn't say studying grammar is a prerequisite for speaking.

##### Share on other sites

Premise 1: All reasoning requires logic.

Premise 2: Programming a computer requires reasoning.

Conclusion: Computer programming requires logic.

The problem is that premise 1 is false.

Logic is to reason as grammar is to language. And I wouldn't say studying grammar is a prerequisite for speaking.

yeah.

likewise, trial and error isn't nearly so ineffective, since humans have a lot of general intelligence and intuition and similar, they can generally make fairly good guesses and approximate a good solution with far fewer iterations than what would be required if working completely at random.

like, humans can usually estimate when things are getting better/worse, internalize things which are known or discovered to work, make use of various heuristics and strategies, ... so, trial and error can be turned into a reasonably effective tool for many use-cases.

though, in some cases, I guess it might depend some of whether a person making use of a step-by-step algorithm in their head (such as using recursive/iterative range subdivision to tune numeric constants/...) counts as using logic (I guess it might, especially if ones' thought-process includes if-conditionals/branches and loops and similar, like they need to mentally evaluate the conditional to decide which branch to execute, ..., hence logic, *).

looking into it, some of this may classify as "guided empiricism" though.

*: well, and all the other inner-mind weirdness, which is sometimes often beyond explanation.