With a little programming experience, you can learn a new programming language in just a few days (and sometimes less).

Some people enjoy learning a new programming language, while others find it almost impossible. In this article, I’ll show you how to think like a programmer so you can confidently learn any programming language you want to learn.

In fact, once you learn how to program, the programming language you use becomes less of an obstacle and more of a formality. In fact, that’s one of the many reasons educators advocate for kids to learn programming as early as possible. No matter how simple their entry language, the logic of this programming makes sense to the logic of other languages that children (or adult learners) are likely to encounter later in life.

With a little programming experience (which you can get from several of our introductory articles here), you can learn any programming language in just a few days (and sometimes less). It’s not magic, and you do have to work at it. Of course, learning every available library in a programming language, or learning the nuances of packaging code and delivering it, can take much longer than a few days. But getting started is easier than you think, and the rest comes through practice.

There are five things experienced programmers look for when they settle down to learning a new programming language. Once you know these five things, you’re ready to start coding.

1, grammar,

The syntax of a language describes the structure of the code. This includes how to write the code line by line and the actual words used to construct the code statement.

For example, Python is known for using indentation to indicate where one code block ends and another begins:

while j < rows:
    while k < columns:
        tile = Tile(k * w)
        board.add(tile)
        k += 1
    j += 1
    k = 0
Copy the code

Lua just uses the keyword end:

for i,obj in ipairs(hit) do
  if obj.moving == 1 then
     obj.x,obj.y = v.mouse.getPosition()
  end
end
Copy the code

Programming languages such as Java, C, and C++ use curly braces:

while (std::getline(e,r)) {
  wc++;
  }
Copy the code

The syntax of a programming language also includes things like libraries, setting variables, and terminating lines. With practice, you will learn to consciously recognize syntax requirements (and conventions) as you read sample code.

practice

When learning a new programming language, try to understand its syntax. You don’t need to remember it, just know where to look if you forget it. It also helps to use a good IDE, as many will alert you to syntax errors.

2. Built-in functions and conditions

Just like natural languages, programming languages recognize a limited number of legitimate words. This vocabulary can be extended using other libraries, but the core language is aware of a specific set of keywords. Most languages don’t have as many keywords as you might think. Even in a very low-level language like C, there are only 32 keywords, such as for, do, while, int, float, char, break, and so on.

Knowing these keywords, you can write basic expressions, which are the blocks of code that build your program. There are many built-in keywords that help you build conditional statements that affect the flow of your program. For example, if you want to write a program that allows you to click and drag an icon, your code must detect when the user’s mouse pointer is on the icon. The code that causes the mouse to grab the icon is executed only if the mouse cursor is at the same coordinates as the outer edge of the icon. This is a classic if/then statement, but different languages can express it in different ways.

Python uses a combination of if, elif, and else to implement conditional statements, but does not explicitly close statements:

if var == 1:
    # action
elif var == 2:
    # some action
else:
    # some other action
Copy the code

Bash uses if, elif, else, and fi to end statements:

if [ "$var" = "foo" ]; then
   # action
elif [ "$var" = "bar" ]; then
   # some action
else
   # some other action
fi
Copy the code

C and Java, however, use if, else, and else if to enclose them in curly braces:

if (boolean) {
   // action
} else if (boolean) {
   // some action
} else {
   // some other action
}
Copy the code

Programming languages are basically the same, with slight variations in keyword choice and syntax. Learn how to define conditional statements in a programming language, including if/then, do… While and case statements.

practice

Familiarize yourself with a set of keywords that a programming language can understand. In practice, your code will contain more than just programming language keywords, and you can be sure that there are libraries of simple functions to help you do things like print output to a screen or display window. However, the logic that drives these libraries begins with the programming language’s built-in keywords.

3. Data types

Code is designed to process data, so you have to learn how programming languages recognize different types of data. All programming languages can understand integers, and most can understand decimals and single characters (a, B, C, and so on). They are usually represented as int, float, double, and char, and of course the language’s built-in vocabulary tells you how to refer to these entities.

Sometimes additional data types are built into the programming language, and sometimes complex data types are enabled by referencing libraries. For example, Python can recognize strings with the keyword STR, but C code must include the string.h header file to implement the string feature.

practice

Libraries can unlock various types of data for your code, but learning the basic data types included in a programming language is a smart place to start.

Operators and parsers

Once you understand the types of data that a programming language can handle, you can learn how to analyze that data. Fortunately, mathematics is a fairly stable subject, so arithmetic operators are usually the same (or at least very similar) in many languages. For example, adding two integers is usually done with the + sign, while testing whether one integer is greater than the other is usually done with the > sign. Testing for equality is usually done using == (yes, two equal signs, because one equal sign is usually used for assignment).

There are some exceptions, such as Lisp and Bash arithmetic operators, but as with other languages, this is simply a matter of mental translation. Once you understand the difference, you can quickly get used to it. A quick look at a programming language’s arithmetic operators is usually enough to give you an idea of how arithmetic operations are done.

You also need to know how to compare and manipulate non-numeric data, such as characters and strings. This is usually done through the core libraries of the programming language. For example, Python provides the split() method, while C requires the introduction of the str.h header file to provide the strtok() function.

practice

Learn the basic functions and keywords for handling basic data types, and look for core libraries that can help you with complex operations.

5, functions,

Code is not just a computer’s to-do list. Typically, when you write code you want to give the computer a set of theoretical conditions and a set of instructions that the computer will take when each condition is met. While you can do a lot with conditional statements and mathematical and logical operators for flow control, the code becomes much more efficient with the introduction of functions and classes because they allow you to define subroutines. For example, if your application needs a confirmation dialog very often, it’s much easier to write it once as an instance of a class than to rewrite and implement it every time you need it.

You need to learn how to define classes and functions in a programming language. To be more precise, you first need to know whether classes and functions are supported in the programming language. Most modern languages support functions, but classes are unique to object-oriented programming languages.

practice

Learn the constructs available in the language that help you write and use code efficiently.

You can learn anything

Learning a programming language, as such, is a subroutine in the process of coding. Once you understand how the code works, the language you’re using is just a medium for delivering logic. The process of learning a new programming language is almost always the same: simple exercises to learn grammar, vocabulary to build the ability to perform complex actions, and practice, practice, practice.


Via: opensource.com/article/20/…

By Seth Kenlon, Author: Lujun9972

This article is originally compiled by LCTT and released in Linux China