![]() ![]() Strings can get confusing if we’re not paying close attention. Think about a sentence as being a string of text, and that will help you remember. When precision is really important, it might be better to use integers when possible.Īnytime we want to work with text, the computer will represent that using the string datatype. Representing information in binary means that we lose precision when we’re working with complex datatypes like floats. Suddenly, our computation has become much less precise. But if we round to the first decimal point, 1.25 + 1.33 = 2.6. We know that 1.25 + 1.33 = 2.58 if we don’t round. You might be familiar with the idea of rounding error. On the other hand, floats are much harder to represent precisely using binary. Integers are actually pretty easy to represent using binary, so computers are able to store information about very small and very large integers with the same amount of precision. We can get more complex representations by creating longer sequences of these two values. In other words, computers only understand the values 0 and 1. You might have heard that computers represent information in binary. Why would there be an integer datatype at all, if it seems like a float is capable of representing the same information, and more? This is a great question, and I’ll try to answer it without getting into too much technical detail. But, because the computer started off with a float datatype 2.5, adding things to the float results in another float. For example, we know that the result of 2.5 + 2.5 = 5, which looks like an integer to the human mind. Sometimes, the computer uses the float datatype to represent a number that looks like an integer. You can think of it as a number that “floats” on a number line between two integers. What about numbers that do contain a fraction or decimal point? This datatype is called a float. ![]() On a standard number line, integers are the “tick marks.” These are all examples of integers: -99, 0, 200. There are certain types of data, and what you’re allowed to do with those data depends on what their types are.įrom high school math classes, you might remember that an integer is a number that doesn’t contain a fraction or a decimal point. From the computer’s perspective, trying to add 5 and "5" makes about as much sense as trying to add 5 and "Detroit". But if we aren’t paying attention, we might miss the fact that the computer is not processing the number 5, but the text "5". It might seem obvious that the number 5 and the text "five" are different from each other. The same is true for digital objects that are handled by your computer. But of course, you wouldn’t want to try biting into a bowling ball, and you probably don’t want to fling a watermelon at bowling pins. An orange is approximately the right shape, and many bowling balls are orange-colored. A big watermelon is about the same weight as a bowling ball. But if you’re not paying attention, you might mistake one type of object for a different type of object. For example, there are fruits and there are bowling balls. ![]() There are different types of objects out in the world. I’ll review the relevant concepts along the way, so if you feel like your math is a little shaky, you’ll still be able to follow along. The only prior knowledge I assume is a little bit of high-school level algebra. The goal is to familiarize you with some of these ideas in plain English so that when you’re learning a particular programming language, the act of writing code is just learning how to express an idea using some fancy computer syntax. So, this is my best attempt at synthesizing some of the key ideas and insights about programming without writing a single line of code. Because of this, I understand the feeling of being code-phobic, and just how much of an overwhelming task it can feel like to learn programming. Through trial and error (frankly, mostly error), I’ve gone from flunking two introductory computer science classes to teaching programming. ![]() This came as an incredibly rude surprise when I embarked upon my first independent research project as a college senior. For example, it is becoming increasingly common to program computerized experiments, and to perform statistical analyses using code. Increasingly, research in the social sciences requires some knowledge of programming and computing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |