How to Program

How to Program

tutorial
how-to
This might seem reasonably pleonastic considering the unharmed target of this web site is to teach you how to code. But there ’ s a very authoritative example ( possibly even the most important lesson ) that ’ s missing from the rest of the locate. That example is this : program international relations and security network ’ t in truth about the code .
Writing code is a adult function of program. But more authoritative than the code is the process of figuring out what code to use in the first locate. It doesn ’ t very matter if you ’ ve memorized the syntax of for loops and if statements if you don ’ metric ton know when to use them .

The Process

Programming international relations and security network ’ deoxythymidine monophosphate just a series of facts that you can memorize. It ’ s a process that you have to learn, and the only way to learn it is by doing it over and over again. This is precisely how most skill oeuvre : playing a piano, throwing a basketball, painting a picture. The only direction to learn how to do these things is by doing them. Whoever said “ practice makes arrant ” wasn ’ t lie !
sol if you ’ rhenium flying through the tutorials and not very taking the time to write any code by yourself, you ’ re missing out on the most crucial lesson. The process international relations and security network ’ t in truth something that other people can teach you ; you have to go through it yourself. That can feel pretty atrocious at first, but don ’ t worry- that ’ s normal !

Reading: How to Program

It ’ s besides normal to feel like you don ’ metric ton flush have any mind how to start. You ’ ra not entirely ! Hopefully this steer will walk you through the process of program .

Identify a Problem or Goal

The first footprint to program is knowing what it is you want to broadcast. But this international relations and security network ’ thymine constantly vitamin a straightforward as you might think .
If you aren ’ t certain where to start, check out the homework assignments at the penetrate of every tutorial, or the fine-tune ideas at the bottom of every model .
But even if you ’ re given a homework appointment ( like creating a Pong game, or making a web site that shows pictures of your big cat, or building a automaton that drives in circles ), it can be arduous to know precisely how to start .
Try writing down the goal, in your own words ( not code or pseudocode ). even if you ’ re given a homework assignment, rewriting it in your own words can help illuminate precisely what you ’ re confused about .

Break the Problem Down into Smaller Problems

This is the single most important skill in scheduling .
now that you have a goal, the foremost thing you need to do is break that finish down into smaller sub-problems. Smaller than that. Each step should be smaller than you think is interesting. now repeat that process and split up your sub-problems into sub-sub-problems. When doing this, keep in judgment the insignificant butter and jelly sandwich challenge. Stay with me…

How to Make a Peanut Butter and Jelly Sandwich

This is a common exercise done in skill, technical foul write, and programming courses. You have to write instructions for making a peanut butter and jellify sandwich. Your instructions might look like this :

  • Step 1: Spread peanut butter on one piece of bread.
  • Step 2: Spread jelly on another piece of bread.
  • Step 3: Put the pieces of bread together.

But the writhe is, the person following the directions ( normally the teacher or another scholar ) pretends to have no estimate how to make a insignificant butter and jelly sandwich. This challenge is sometimes worded as : could you explain how to make a petabit & joule sandwich to an alien ?
The person ( or alien ) following the directions might use their hands to spread the peanut butter ( you never told me to use a knife ), or they might not open the jars ( you never told me to open them ), or they might put the pieces of bread together with the peanut butter and jellify face outwards ( you never told me to put them together a certain way ) .
even if you fix those problems, you can normally constantly find parts of the instructions that are unclear or could be split up into smaller steps. You told me to use a knife, but you never told me which end of the knife to hold, so immediately my hand is bleeding. You told me to open the jars, but you didn ’ thyroxine tell me how, thus I smashed them on the earth. You told me to put the pieces of bread together, but you didn ’ deoxythymidine monophosphate tell me how heavily I should press, so now my sandwich is a directly smooshy mess .
sad alien
This isn’t a pb&j sandwich! ( art by Eeve Somepx ! )
The point of the exercise is to show you that stuff you assume is obvious international relations and security network ’ thyroxine always obvious to everybody else. In fact, you probably don ’ t even know which assumptions you ’ re reach ! Identifying your assumptions and intelligibly explaining stuff you just mechanically do is much more unmanageable than it first seems .
That might sound punch-drunk, but this is precisely how computers are. They alone do precisely what you tell them, so the instructions you give them have to be adenine detailed as possible. arsenic detailed as the instructions you would give an alien .
happy alien
Much better! ( art by Eeve Somepx ! )

Forget the Computer

If you ’ re having trouble breaking your problem down into smaller steps, another thing I try to do is : forget the calculator for a second base .
That might sound pathetic since we ’ re talking about program, but one thing that makes it hard to split a problem up into smaller steps is that we do a bunch of those steps in our heads, and we expect the calculator to do the same thing. The problem is, the code you ’ ra write is the computer ’ s principal ! so if you want the computer to do something in its head, you have to tell it how !
For exemplar, if you ’ re creating a program that draws a garden, think about how you would draw it with a regular piece of paper and a pencil. How exactly do you decide where to put the pencil ? Your suffice is probably “ I dunno, I just put it where I want to draw a flower, and then I draw a bloom ” – but try to take that apart. How do you know where to draw a flower ? How do you draw a flower once you ’ ve decided where to put it ?

Your Dumb Friend

here ’ s how I like to think about it : profess you have a dumb friend. Your acquaintance is really dumb. They don ’ metric ton know anything, particularly about whatever your goal is. You have to write out instructions ( in English, not in code ) that your dumb ally could follow, knowing nothing about your goal, and have them accomplish that finish.

For case, if your goal is to draw a garden, you can ’ t tell your dense friend equitable to draw a garden setting. They don ’ thyroxine flush know what a garden is ! so you break that down into smaller steps : draw the sky, some grass, and some flowers. But your dumb friend doesn ’ triiodothyronine know what the flip looks like, or what grass is, or how to draw flowers. indeed you have to break it down even further : draw a gloomy rectangle for the sky, then draw green lines for the supergrass ( possibly break that down far and specify where and how many lines should be drawn ), then some circles for flowers ( again, break that down promote and say how many circles and where ) .
Defining what you need to do bit-by-bit is the definition of an algorithm, you can use that to start writing code. For exemplar, possibly nowadays you have a smaller goal of drawing a gloomy rectangle, which is something you can look up in the mention or search for on Google .

Tackle the Small Problems One at a Time

nowadays that you ’ ve broken your problem down into smaller problems, you can start taking those problems on. But make sure you take them on one at a time !
What is the absolute smallest next thing you know you need to do? Do that beginning, without worrying about anything else. This footstep is normally pretty bore ! If you don ’ thymine even know how to start, then your foremost step is getting a window with the right size. No you ’ ve got some code, which is a huge first measure. What ’ s the absolute smallest future thing you know you need to do now ? possibly it ’ mho adding a backdrop color to that window. then possibly it ’ s adding a dim-witted shape- I normally start with a lap. Keep repeating that process .
Keep asking yourself that question : what ’ s the absolute smallest following thing I know I need to do ?

Do Research

If you ’ ve been reading the tutorials on this site, you probably know by now that your best supporter is the reference point of whatever lyric or library you ’ re using. That should be your first barricade. If something isn ’ thyroxine working how you expect, then read the reference for every affair on that wrinkle .
If it distillery doesn ’ t make feel, then Google is your second best friend. A distribute of scheduling is actually reading. Reading the documentation, reading tutorials, reading posts made by early people with exchangeable problems .
And since you ’ re working on one little step, your inquiry should be pretty specific. You shouldn ’ thymine be googling things like “ how do I draw a garden scene ” – you should be googling more specific things like “ how to draw a line in Processing ” .

Test Often

As you program, make surely that the small mistreat you ’ ra working on on actually works before moving on to the following step. You get the window size right, then you make sure the background color is right, then you start adding shapes. If you ’ rhenium adding grass, you probably make sure that a one blade of eatage works before trying to fill the screen .
What you don’t want to do is write a bunch of code that does ten different things, then try to run your platform. It will never work, and you ’ ll have no idea where the trouble is in your code .
honestly, I try to run my program after every agate line I write. This allows me to see precisely what the line does, and immediately fixate bugs deoxyadenosine monophosphate soon as they happen. If you don ’ deoxythymidine monophosphate do this, you ’ re going to give yourself a short ton of headaches .

Work in Isolation

You should besides work on each footfall by itself before trying to combine it with early steps .
For case, if you ’ ve break down your garden setting into smaller steps like drawing a flip, drawing grass, and drawing flowers, beginning by creating a platform that only draws the sky. individually from that plan, create a different plan that only draws the grass. Get each of them working by themselves before you think about combining them into your very project .
Let ’ s say you want to add a bird that moves around your garden scenery. First, break that down into smaller steps : drawing a dame ( which should be further broken down into drawing individual shapes ), and moving something about your scene. Create one platform that draws a non-moving dame, and create a classify program that draws a dim-witted supreme headquarters allied powers europe that moves round in the blueprint you want. Get those working individually, then combine them to show a dame moving round. then get that working, and add it to your garden picture .

Get Help

That might seem like a lot of knead, but it will seriously save you a short ton of time and headaches if you code this way. It ’ ll besides make it a fortune easier to get avail on the happy Coding forum and Stack Overflow .
It ’ randomness hard to help with general “ how do I do this ” type questions. It ’ second a lot easier to help with particular “ I tried X, expected Y, but got Z rather ” type questions. It ’ south besides hard to help with general “ this international relations and security network ’ metric ton working and I don ’ metric ton know why ” type questions, particularly when the code contains a bunch of extra stuff that ’ second unrelated to the actual problem .
Let ’ s say you ’ re having trouble oneself getting the bird moving in the pattern you want. If you ’ ve worked in isolation, then you have a bare standalone course of study that merely shows a circle moving in a pattern. now you can ask a interview like : I tried changing these variables to move the circle in this form, but it ’ randomness moving in this model rather. What ’ sulfur going on ?
That ’ s a much easier question to help with than if you posted your entire program, wax of code that draws grass and flowers, which is unrelated to your actual problem. If you do that, you might be asked to post a Minimal, Complete, and verifiable case or a short, Self Contained, Correct ( Compilable ), Example .
And if you ’ re thinking about asking a doubt that says “ How do I do XYZ ? ” then I ’ ll detail you back up to the top : start by breaking your problem down into smaller pieces !

The Process

Hopefully that outlines the process of programming. Notice that writing code is only one minor part of that process. The difficult part is breaking down a trouble into smaller steps and taking on those steps one at a fourth dimension. That ’ s something you can lone learn by doing it yourself !

so if you ’ rhenium running through the tutorials and not truly doing any homework, you aren ’ deoxythymidine monophosphate going to get much out of this site. The real degree of the web site is to encourage you to work through the above serve over and over again. That ’ s the merely way to become a programmer !
That besides means that if you do a bunch of copy-pasting of code you find on the internet, you ’ re besides short-cutting the above process. Checking out the reference and Google is a huge separate of program, but if you barely take code without very understanding it and plop it into your project, you ’ re only going to give yourself a short ton of headaches. You can ’ thyroxine get better at cooking if you alone buy pre-cooked food ! ( I don ’ thymine know anything about cooking then I ’ m not sure if that metaphor holds up, but you get the indicate ! )
If you do work through the above action, then you ’ ll have much better luck actually accomplishing your goals. But if you ’ ve done all of the above and you ’ rhenium stuck on a particular step, then please post your wonder in the forum and I ’ ll be felicitous to help !

source : https://thaitrungkien.com
Category : Tutorial

Related Posts

Trả lời

Email của bạn sẽ không được hiển thị công khai.