How to learn a new programming language

As a software engineer or a tech student, there is always going to be something new to learn and to keep up with the times, you’re going to need to learn it. Maybe you’ve changed jobs or a new framework is on the rise and the company you work for wants to change directions. In both cases you’re going to have the daunting task of teaching yourself a new framework or language and that sounds really scary but I promise it’s not. This blog is intended to help guide you into taking your old knowledge and applying it to learn new skills. I’m going to take this specific time to learn Swift, a language I know nothing about, coming from Ruby. I am going to apply all the tips however that I put below.
Get Setup:
First before you can even start learning you need to get an environment setup. Do some research into how to run code for your desired language, in my case Swift. There are a lot of online tools to run code but since I’m on mac and have Xcode installed, I know I have swift on my machine so I can run the code through the command line. Visit the language’s website and follow the install section to fit you needs. Most languages allow you type something along the lines of “language — version” to see if you have it installed. I got swift up and running so let me see what I can do. Similar to how I can run:

in ruby, ruby.rb being the filename, I can also run

in Swift, swift.swift being the file name and swift being the command line command to run code. It also seems Swift has an interactive code repl like Ruby which can be triggered in ruby with the command irb and the command swift respectively. This can be a helpful learning tool.
Tip #1 Code:
This might seem kind of out there, but trying to code in the new language is the best way to learn it. I like to take a project I did in the previous language or framework that I could do with my eyes closed, and try to translate it into the new language or tool. I do recommend if you’re learning a new framework or tool, that you spend sometime in the vanilla language first before jumping of the deep end. I have a helpful guide to learn a new language here:
Try picking a project that you can do easily in your home base language, and then translate it into the new one. Try picking a project that requires a lot of the basic concepts, like variables, loops, functions, and conditionals. This will help you get the basics of the new language and give you a jumping off point. I recommend building something like rock paper scissors in the command line, super simple and can be done a lot of ways.
Tip #2 Read Code and Use the Docs:
Reading the docs sounds like a no brainer, but it can sometimes be hard and overwhelming. The approach I follow is when researching how to do something in the new language, I make sure I understand what every character in each line of code is doing. Looking at how to declare a function in Swift

There are some new things compared to ruby which I needed to do some research on. It seems you can explicitly define type of parameters, and you denote the return type of the function with the arrow. This stuff is very essential in programming, but will differ from language to language. Another reason to read the docs is learning the ins and outs. Unlike in other languages, when you divide an integer by an integer, the answer will be a float. This is something that is pretty unique to Swift that would have caused bugs. This type of issue is something you could only really find in the docs.
Tip #3 Apply the knowledge.
Remember, you know how to program, and most of the time you know what you are trying to do. When you’re learning new syntax, try and break it. Try and apply the things you see online into new areas in your programs or in new programs. I always spend some time trying to break my program and reading the errors, learning from my failures helps me in the future. Take something you see online and try and make it work, reading the errors and googling until you can get it to work. You already have these skills from your programming experience in other languages it doesn’t change here. Another example of applying is using the language idiomatically. You can do almost anything you want in all modern programming languages, but many have conventions to do something you like better. For example in Ruby, you almost never explicitly define variable types. In swift you do not have to either, but once you assign a variable once, it assumes that variable will remain that type. This can lead to confusing to results, so It is best to explicitly define, by convention in Swift. It’s not required, but it’s like the difference speaking in a language and thinking in a language.


Starting to think in the new language is the best way to immerse yourself and will come with practice and time. Look at how programmers in the new language opt to solve the same problems and see what you notice.
Tip #4 Do not give up!
Programming languages are all designed to the same thing one way or another, and if you could conquer one you sure can conquer another. The more time you spend trying and the more time you spend failing will all add up to make the new languages and ideas click much faster. It took me an hour just to try and read in input from the console in Swift because of its distinct inner workings from Ruby. After I finally got it to work, I had that feeling like on my first day of coding when I was able to solve a problem I had for the longest time. Programmers are problem solvers and learning a new language is a perfect opportunity to practice the trade, as there will be plenty of new problems to solve. When things get tough just remember, If you can do it in one language , there must be a way to it in the other so keep looking. The similarities are all there and even when the devil is in the details, all it takes is a little reading. Drawing comparisons between two languages, you’ll find that there is much more that is similar than different and use that as a jumping off point!.