How to code when you don’t know how to code I don’t really know how to write R or JavaScript code. Does that stop me from writing some when I need to? Of course not! Not when the internet and hive mind is at my fingertips. Here is the algorithm I follow for writing code in a foreign language. Step 1: Google what you need to do. Step 2: Click top hit. Step 3: Copy the code. Step 4: Paste the code. Step 5: Change variable names as necessary. Step 6: Run the code. Step 7: Check if the code worked. Step 8: If code worked go to step 22. If an error message appeared go to Step 9. If no error message appeared but obtained spurious results go to Step 15. Step 9: It is possible you copied some bad invisible characters. Paste code into a text editor such as Notepad and repeat Steps 3–8. Step 10: If error message still appears copy the error message and perform Google search. Step 11: Repeat Steps 2–8. Step 12: If stuck in an infinite loop of Steps 2–11 break out of loop and go to Step 13. Step 13: It’s possible the original code you copied from Step 2 was for a different version of the software you are using and you got unlucky. This is frustrating because all the message boards will be filled with comments thanking the poster yet the code isn’t working for you, and of course no one ever mentions what version they are using. Either consider the possibility you don’t have the appropriate version or dependencies installed and fix this, or start over at Step 1 but click the second best hit this time. If you continue to arrive at this step make sure to click new links in Step 2. Step 14: Repeat Steps 1–13 until you eventually break out to Step 15 or Step 22, pass out from exhaustion, or smash your laptop. Step 15: The code is doing stuff, but not quite the stuff you need it to do. Randomly make changes and see what they do. This might make you feel silly. You might think you are no better than a monkey randomly pressing buttons. And you’re not. But if it makes you feel any better you can consider this a heuristic algorithm. And if anyone questions what you are doing be sure to tell them you are dynamically searching a random forest to get to the solution as quickly as possible. Step 16: If your changes worked go to Step 22. If not go to Step 17. Step 17: Get some coffee, you’re going to need it. Step 18: Try to understand what is happening with the code. Languages such as R and JavaScript are evil and aren’t meant to be read by normal humans, but you are going to have to make an exception this one time. Step 19: If unable to understand what the code is doing (likely), do an extensive Google search for a very clear example of what you are trying to do. Step 20: If the hive mind failed you break up the problem and try to solve each part separately. Maybe you find some code that does half of what you need, and then you find code that does the other half. Step 21: The break glass in case of emergency step. Write some code. But how are you going to write code in a language you don’t know? Well you’ve just spent hours or days working with the language and trying to debug it, so you probably picked up a little bit. Break your problem into its smallest parts and code each part. Google search any parts you can’t code. Step 22: Code works. Grab a beer and consider taking a shower after working with such a dirty unpythonic language.
This algorithm may sound silly, but it has never failed me. You might wonder why Step 1 isn’t to post a question on a forum. Well, first of all most questions have already been asked so you would just be wasting someone’s time. More importantly I guess my ego is too big to ask for help and I think that if I can’t solve the problem then clearly some random person online won’t be able to solve it. My first language was Python and it was love at first sight. All the parentheses and curly brackets of JavaScript give me a headache. And no matter what anyone tells you, R is not meant to be a programming language, it is basically just a bunch of standalone functions. I’ve completed multiple tutorials for R and JavaScript, and even used these languages in peer-reviewed publications, but still can’t write code in these languages without reference manuals or forums. It’s like learning a spoken language, you can’t expect to learn it without fully immersing yourself in it, and I’ve never had a need or desire to code an entire project in a language other than Python. I’m not a computer scientist, but I think it is much better to be a master of one language than average at several languages.
If you would like to comment on this post it is available at Medium