I feel like I’ve had a huge programming breakthrough and want to check if I’m understanding things conceptually with you guys

Posted by HorseFacedDipShit@reddit | learnprogramming | View on Reddit | 16 comments

You’re not coding. You’re writing a story for your computer. And it’s not just any story. It’s a story that tells your computer what to do. Your computer is very very smart. It will remember everything you’ve told it to do, and if you tell it to do things in an efficient way, you can have the computer do what you need it to do very well. I only (sorta) know Java, so what I’m saying is coloured by that, but it’s gonna be similar no matter what language. You need your computer to do something for you. But you can’t talk to it. You have to write it a story. In order to write a story, you have to know how to write in a language the computer can understand. It’s like writing something in French, English, Russian, etc. it doesn’t (really) matter what language you code in, at least when you’re learning. So you’re writing something for the computer. You’ve got the language you want to write in, but you still need a pen or pencil, something to write in, and somewhere to write it. Obviously your keyboard is how your write to the computer. But you need somewhere to do your writing. You could write code straight into the command prompt, but I wouldn’t recommend it. An IDE is like a nice, organised office for you to do your writing. Integrated Development Environments are like a nice, organised home office where you can quickly find all the pages you’ve written. Now you’ve got a language to write with, an office to do your writing in, and a pen to write with. But now you actually need something to write *in*. You might be writing a lot for the computer, or not very much. Think of your Programs folder as your entire book series. Everything you code lives in your languages (Java) programs folder. Your first book that you write is your class. Now, you could write *EVERYTHING* you ever say to the computer in this one book (class), but that’s not a great idea for a lot of reasons. You’re going to write lots of books (classes) to make it easier for your computer to read. The books we write for our computer are very different than books you’d like to read. Like I said earlier, we are writing instructions to tell our computer what we want it to do. Our computer is very smart, but it has ZERO imagination. If you don’t explicitly tell it how to do something, it can’t do it. So our books that we write are basically filled with instructions (methods). Now we have to have at least one set of instructions (main method) because otherwise there’s nothing for a computer to read. Like we could write everything in one class, we could also keep all of our instructions in this one method. Think of it like a paragraph. It just isn’t a good idea to have a single, LOOONNNGGG paragraph. That’s why we split our books into paragraphs, and why we write multiple methods in our classes. You wouldn’t write one really long book with one really long paragraph. I also feel like I’ve made some pretty big strides in understanding OOP too. I think OOP is one of the most intuitive ways to code, and in a lot of ways Java is a really good language to learn it with because of the way it’s structured compared to say python. Think of it like you’re giving orders to your computer, and you want to tell it what to do in as short of time as possible. You want it to build you a car (object). Now the very first time you ask it to do this, you’re going to have to write a lot of code telling the computer what a car does (methods) and what it is (attributes). Now the very first time you tell your computer what a car is and does you’re going to have to explicitly tell it everything about a car. But if you use OOP principles, you won’t have to do nearly as much work when you ask it to make a second car. The issue is like others have pointed out if the second car you ask it to make has details that directly conflict with your first car your drawing the information from. For example if the second car isn’t clutch driven but the first is. That’s why your initial object you draw from should be detailed, but not overly so in the sense that you constrain future objects. It just saves you so much work. And if you write your first object really well you can write all other objects as specific as you want. So when you write your first car object, it might be a good idea to not include something like the colour of the car. Even if you want this first car to be red, it’s better to write a main car object that’s not tied to a colour, then simply write another car object that links to this first one that is red. You should do this with what the car does (methods) as well. All cars can turn right or left for example, but not all can roll back the sun roof. This is overly simplistic of course. And there’s lots of complicated other stuff that comes into play as the code base grows. But I think that is the gist of what OOP should do. It should save you a lot of time writing code, because if you don’t use it you’re going to have to define the car object EVERY SINGLE TIME you need any alteration at all to the car you want your computer to make. I really do feel like I’ve broken through the mental barrier of what programming actually is. Please let me know if anything I’ve said is incorrect in a general sense. Thank you guys. I’m very excited because it really seems like things are coming together.