A Love Song of Death

As the battlefield fogged with smoke and the cloying smell of death, I saw the woman walking from body to body as if she were a specter.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Computers are like your dog. Coding explained

Writing code is like speaking with your dog. Your dog can only understand a few keywords. They might understand ‘sit’, ‘stay’, ‘fetch’ and ‘drop it’. Simple words that on their own are mainly neat party tricks or fun to play with. But what if you string these commands together?

Let's say you are super lazy today and you are hanging out on the couch. You feel like reading the news but the rolled-up newspaper is way over on the other side of the room. You get the bright idea that maybe if you give your dog the right commands in the right order, she can get the newspaper for you. You call her over then tell her ‘fetch’ and point her where to go, she runs back to you with the newspaper in hand. But she won't put it down now because she doesn’t understand until you tell her with one of the commands she knows… ‘drop it’. Voila, your laziness has prevailed. With just a couple of simple commands, you have a dog that can do things for you.

Unlike dogs, computers only speak in binary, 1’s and 0’s. Fortunately, people before us have made programming languages, these languages give us the ability to write human-readable English commands that, when you run your code, get translated into 1’s and 0’s. When you hear someone say ‘my code won't run’ or ‘I need to debug my code’ they are saying that the programming language didn't know how to translate what they wrote into binary code for the computer. So they must have given a wrong command somewhere and they need to figure out what command couldn’t be understood, just like if you told your dog to do a backflip, she will probably just look at you very confused.

So what are these commands that a programming language knows and where do you write them? Let's look at the programming language python, it is known to be a language that is close to English, even if it knows very limited words.

Let's look at the commands ‘if’ and ‘else’

In this code, we are setting a to be equal to 33. Anywhere a is used, you can just think of it as the number 33. Anywhere b is used you can think of it as 200. By writing if b > a: we are setting the condition that if this is true (b > a), the computer will print “b is greater than a” to the screen. If it is not true (else), we will print “b is not greater than a” to the screen. This way the computer knows how to act in both situations. In our example, b is greater than a (200 > 33) so the computer will only print “b is greater than a”.

One of the great things about coding is that you can define new words. With your dog, to get her to grab the newspaper for you, she had to be told to ‘fetch’ then ‘drop it’. But what if you are extra lazy and want to say as few commands as possible. You could teach her the new command ‘fetch newspaper’. When she hears this she knows that she needs to ‘fetch’ the newspaper first and then ‘drop it’.

In python, we can use the ‘def’ keyword to define a new command.

Now we have a new command called ‘compare’ which compares a and b the same way that we did earlier.

Once ‘compare’ is defined we can use it like this.

This code will do the same as the first piece of code we saw, but now we have a single command that we can use.

How do we go from these commands to the software that we use every time we are on a computer? With a lot of hard work and teamwork. If I define new commands that I think others could find helpful, I share them in a library for other coders who will use my commands to build even more complicated commands on top of it and so forth. Eventually, we can have a single command that can do a lot. For instance the clap button on this article (hint hint). The ‘clap’ command will start a bunch of smaller simpler commands that will display the number of times you clapped, update the number of claps this article has, send the update to me and so much more.

‘fetch’ is actually a command that your dog and many programming languages have in common. In your code, you can tell the computer to fetch information from a certain URL and like the good dog that your computer is, it will!

Different languages have different specialties. Some languages are made to be purely logical and easy to read like python, other languages are made to style a webpage like Cascading Style Sheets (CSS) which is what makes this article look better than just a bundle of text.

I hope this has given you a better understanding of what coding is, how programmers do what they do, and what goes on behind the scenes of the applications you use.

Add a comment

Related posts:

HTML to PDF in Clojure

Some months ago our colleague Jose wrote a post about our experience constructing pdf’s from clojure code. That post got some feedback, and suggestions like the one shared by Dmitri Sotnikov, the…

Jangan Terlalu Over dalam Thinking

Semua orang punya fase dimana mereka harus memutuskan suatu pilihan, pun semua orang akan memasuki fase setelahnya yaitu bertanggung jawab atas pilihannya. Semua orang akan keluar dari fase ini…

Is Python Developer A Good Career?

Python Developer has recently become a job in the industry. Every day I meet many curricula of Python developers. The demand for Python programmers at all levels in the IT industry has increased. The…