Over a million developers have joined DZone.

A Receipt for Learning a New Programming Language

DZone's Guide to

A Receipt for Learning a New Programming Language

In this article, a developer shares how he tends to go about learning new programming languages, and by providing three exercises he likes to use.

· Agile Zone ·
Free Resource

The Agile Zone is brought to you in partnership with Techtown Training. Learn how DevOps and SAFe® can be used either separately or in unison as a way to make your organization more efficient, more effective, and more successful in our SAFe® vs DevOps eBook.

In the past few years I've found myself learning a bunch of new programming languages – Javascript (with some frameworks like Angular, React, Meteor and Node), Kotlin, Python and more. Being an experienced programmer, I always looked for the quickest way that will get me on the run with the new language. I must admit that sometimes it wasn't easy. Sometimes I didn't know where to begin. 

I don't like to read the beginners tutorials because they are full of explanations for, well, beginners. Things like what is a variable, what is a boolean expression, and why or when you iterate from zero to ten exclusively, it makes 10 iterations. I have to read a lot and waste a lot of time till I get to see the syntax I need. It's tiresome and boring. 

But unfortunately, there is a real shortage in tutorials for experienced developers. I guess no one really bothers to write those based on the (indeed true) assumption that an experienced developer would probably manage to find his way through the formal APIs without too much help.

After struggling with the same questions in every language, I've made a small list of useful exercises that I now write in every new language I learn. It's really a short list, but it leads me to the right places in the language and the exercises in it always help me understand the basic syntax of the new language.

So here is the first part of my list. It's not complete, and there are cons, but for a starter – give it a try next time you want to learn a new language.

Exercise 1: Print "Hello World" on the screen.

Yeah, yeah, I know, it's banal, boring and oh so seventies, but I like the tradition. Besides, this small exercise will help you understand the following things: 

  • How to compile and run a program.
  • How the simple output goes.
  • Is there a new line in the end? 
  • Are there any special characters, like commas or semi-colons needed?

And while you're there, try printing some other stuff like the current date, your name, age, and so on. You'll be amazed how much one can learn from some simple printings.

Exercise 2: Write a program that gets the radius of a circle from the user, and outputs the circle's area and perimeter. If the radius is not positive, make an error message.

This will help you to understand:

  • How the input is done. Does it require casting?
  • How the conditionals are done.
  • How the simple arithmetic looks.
  • How do you print strings and variables?
  • Are there constants in the language, and how do you write them?

And while you're there, try to make some more calculations. Calculate the square roots of an equation, generate a random number in some range, or anything involving some math functions and floating-point arithmetic.

Exercise 3: Write a program that gets from the user a number, and prints how many even digits are in the number.

This is a great simple exercise that will teach you the loop's syntax and some other things:

  • How does division work in this language? 
  • Does this language have a modulus operator?
  • Which kind of loops are there?

And why not write a loop that determines if each digit is unique in the number, or even sort the numbers by their digits? It will get your hands used to the syntax (and sometimes to the oddities) of a new language.

Ok, so those are three exercises to begin with, in the future I'll write the rest. From my experience, they give you the right focus without bothering you with beginners' stuff.

If you have your own ideas about useful coding exercises for migrating to a new language, or you like (or don't like) my examples, I'll be glad to hear.

Adopting a DevOps practice starts with understanding where you are in the implementation journey. Download the DevOps Transformation Roadmap, brought to you in partnership with Techtown Training

learn programming ,agile ,learning and development

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}