I've been learning Go (the coding language) for the past few weeks, and it's teaching me a ton. I've been working on computational math problems from Project Euler, and so far I've solved 18 problems! You can check out my progress in my GitHub repository. And I'll have an actual article detailing what I've learned once I complete the first 50 problems.
Anyways, the Go compiler – and code compilers in general – remind me of an extremely intelligent but terribly stubborn five year-old. This five year-old will do exactly what you say, and has no capability to interpret and fix small mistakes.
The following are two conversations between Nathan Brown (NB) and the small five year-old child present within the Go Compiler (GC).
NB: I need to raise a base to an exponent for my code. Can you do that for me?
GC: Absolutely not. My five year-old friends use "^" as typical exponentiation notation, but I'm cool and quirky and so I use "^" as a bitwise XOR operator. I do not care whatsoever about your feelings.
NB: Why not?
GC: [Doesn't answer. Runs off to play with a 20-sided die.]
NB: Fine. [Googles "how to use exponents in Go". Finds the Math.Pow() function, and realizes that he needs to use the "math" package.] Great, so do I have to import the "math" package?
GC: [Suddenly intrigued] Oh yes. If you import the math package, I have the ability to learn trigonometry, exponentiation, calculus, and a whole bunch of archaic math in a matter of milliseconds.
NB: [Happy, he types import "math" into his code editor.] Great! [Does a bit of tinkering, and then realizes something.] Hey, I no longer need to use exponents in my code. Can I still run my code?
NB: You're telling me that you can't run the code, because I imported a package that you didn't use??
GC: Yup. Why would I bother learning all this math if I didn't use it in the program? That's a waste of valuable milliseconds I could have spent calculating the sum of the numbers 1 to 1,000,000,000.
NB: Fine. I'll put two slashes in front of my import "math" line. Happy?
GC: What are you – some kind of sorcerer? You made that line completely disappear! I can't see it now!! [Thinks for a second.] Whoops, you're missing something – sorry, I can't make your code run.
NB: What am I missing?
GC: I don't know. Maybe an end parenthesis or an end curly bracket? I couldn't care less. My job is way easier if I don't have to run your code.
NB: Have you ever considered helping me figure out my error?
GC: I don't get paid enough for this job. I'm up all the time, especially at night, and the compensation is terrible. I only get a few juice boxes and action figures per week. Give me a break.
NB: I never thought five year-olds were this moody.
NB: Hey, I'm back. Can you help me run this code? I have this variable that I just defined.
GC: Sure, everything else works – but I seriously cannot deal with the variable. You didn't use it!
GC: [Exasperated] This time, I'm saving myself the work of having to remember stupid stuff. If you tell me the volume of the Eiffel Tower and don't ask me to use it, I don't care.
NB: Fine. I'll make you use the variable. Now can we get this code running?
GC: We got another problem, buddy boy. You've given me a slice with fifteen different fruits and asked me to name the fifteenth one with fruits. [Sighs] Turns out I can't do that, because my Ultimate Compiler's Manual says that will return an "out-of-range" error.
NB: [Furiously Googles "out-of-range error".] Really? You guys refer to the 1st item in the slice with the index of 0? Also, what is the Ultimate Compiler's Manual?
GC: I don't make the rules here. I just follow them. Anyways, what are you trying to do with your fifteen different fruits? Code Fruit Ninja? Pretty sure you couldn't do something that complicated.
NB: [Growing angry] Don’t insult me. I want to use my ‘for’ loop now.
GC: Sure! But my Ultimate Compiler’s Manual says that you’ve got some kind of error in your ‘for’ loop declaration.
NB: I really hate you – you know that?? What even is wrong with my code?
GC: Not my problem. Why would I help you?