COMMON MODERN PROGRAMMING LANGUAGES
At present, the languages that are fast gaining popularity across the globe are Scala, Golang (abbreviated as Go), Rust, Kotlin and Swift. Here, we will go through what each language has to offer as well as similarities in all the languages. This comparison will be possible through the use of a simple declaration function.
Golang (Go)
Did you know that this language came to the market courtesy of Google? The organization handles highly
distributed systems and there thus came a time when the need for a specified language became inevitable. The
language grew popular at a fast rate, with some programmers attributing its success to one of the designers
in play: Ken Thompson.
If you have read a lot on the development of programming languages over the years,
you will remember that Ken created the UNIX OS which continues to wow people to date. There are those who
think of him as a hero in matters of computer science.
This language came into the industry back in 2009, and since then, it has been through many changes, one of
it being its release as an open-source project. The impressive thing about this language is that it came
about owing to the frustrations that its designers said they dealt with when working with C++.
According to
them, the latter option was quite complex, and they needed something that could work for them without
resulting in numerous complications. If you are in such a situation, you will be happy to know that Go could
be the solution to your problem.
Have you handled C language and liked it? You can think of Go as an improved version of the language. This
compiled language is much faster than C and C++, and it can manage memory automatically through the use of a
garbage collector. It’s also a favorite language owing to its ability to handle concurrency via channels and
goroutines.
As for the simple function declaration, this is what you should expect:
func factorial (x int) int {In Go, you declare your function using the func keyword. You then state the name of the function in the form of a factorial. From here, you outline the parameters in place, enclosing them in parentheses. Unlike the case of Scale, the factorial function in Go can only take one argument in the form of integer x.
// body goes here…. }
Again, the function also returns an integer which you will see shown as int after the parentheses. The body falls into the curly braces. A similarity between this and Scala is that the function return type follows the name of the function, in a system also known as the trailing return type. With Java or C, the function return type would come before the name of the function.
As for variables, you only have one option, and that is var. Here is an example:
var s stringIf you wish, you can have the initialization and the declaration at once. An example would be as follows: ,
s= “not welcome”
var s string = “not welcome”Additionally, you can declare the variables in a much shorter way than above. Here is an illustration of the same:
s : = “not welcome”In the example shown above, the compiler would refer to s as a string. When it comes to concurrency, this language does quite well as compared to others, through the use of channels and goroutines. If you wish to learn more about this language as well as where it has been in use, it will serve you to read about Docker. In this scenario, the language came in handy in software technology used in the creation of containers.
Scala
In the same way that there are old programming languages that date back to the nineteenth and twentieth
centuries, the same goes for modern languages. Those that came about in the first decade are seen to be old
as compared to the ones that have arrived in the industry in the second decade. Scala, having come into the
market in 2004, thus qualifies to be an old language.
Programmers regard it as a product of academia. Martin Odersky, the designer, was working at the EPFL in
Switzerland at the time of its formation. The exciting thing about this language is that it combines
functional programming as well as object-oriented paradigms. Any app written on this language can run on top
of the JVM.
For this reason, you can quickly move applications to other platforms, and this flexibility
appeals to users who prefer this language.
Onto the simple function declaration. In this language, you will find it written as follows:
def factorial (x: Int) :Int = {You will note that the function uses the def keyword as part of the declaration. For people familiar with programming languages, you will notice that this is similar to what you would find in Ruby and Python. From here, you have the factorial, also known as the name of the function. The parentheses create a space in which you can outline the parameters.
// The body goes here…. }
In the case shown above, the parameter is x which you will then follow by a colon before moving forward to the data type in play. For example, if you were to have an integer as the data type, int would be suitable. Suppose you plan on having more than one parameter in your function, you can separate each by the use of commas. Once you complete the parameter list, you will then have another colon which you will follow with the data type.
In our case, you would follow through with the use of int. When you do this, you have worked on the function as per the trailing function return type. Many people refer to this method as the result type, which is also acceptable and more commonly used than the latter.
Once you finish the result type, you add a = sign and two curly braces. Between the two braces is where you will place the body of the function. For people who are still learning the language and are yet to get the hang of things, having a = sign might be confusing.
However, if you were to look at it from a mathematical perspective, it would make sense. For this reason, it may be easier for you to think of the body as a math expression that results in yields based on what you set as the input. The return would then be proportionate to whatever would be on the left of the =.
In this way, whenever one uses the factorial function, the result would depend on what was in the body of the function. When you think of it in this way, it tends to be easy to grasp.
As for the variables, you have two ways in which you can declare them. The first is val and any variable expressed in this manner is immutable. That means that you cannot reassign them. When you are using this language, it is important to note that this is the preferred option. However, you can choose to declare them using var.
The difference between this and the latter is that you can reassign them. If you have used JavaScript in the past, you will be familiar with these keywords.
Suppose you initially give the variable a value, you would not have to declare its type as the interpreter in place can recognize its type. Take an example of val x = 100.
In such a situation, the type of x would be inferred as an integer and would thus get representation as Int. However, where the variable in question does not have a value initially, its type must be clear from the start. Here, you can use something such as var x: Int.
Scala has been in use for a long time, with Twitter adopting its use back in 2009. The thing with this language is that it takes a while to master it, but once you do, you will enjoy it over a lifetime.
Rust
Just as is the case with Go, this language came about due to deficiencies in the programming languages that
were available at the time. A Mozilla researcher felt that there was a need for a language that was not only
safer but also more efficient as compared to C and C++ which were ruling the industry at the time.
It came
into the industry as an open-source project in 2010 where it received lots of positive feedback, courtesy of
Graydon Hoare, who worked as a designer in its creation. He later moved on to Apple where he also made a
name for himself as part of the team that developed Swift, which is also a high-ranking modern language.
This language aimed to provide a safer and faster solution to the other programming languages that were
available at the time as well as to provide concurrency. Out of all the goals that its designers had in
mind, Rust excelled in providing a safe alternative the most.
How does it do this? Well, it’s pretty easy.
It’s possible through a concept that most languages are yet to exploit fully, the feature of ownership.
A simple function declaration in Rust would be as follows:
fn factorial (x: i32) -> i32 {Given the examples given in the other languages as to the components of the declarations, you might be able to tell what each of the symbols stands for and why. However, let’s dig in a little. The function in this language goes by the keyword fn.
// body goes here…. }
Having written this down, you then follow up by adding the name of the function, hence the factorial. As from this point, you can add the list of arguments which should be present within the parentheses.
Take an example of the example given above. In this case, we are dealing with one argument symbolized by x. Based on how it is; you can tell that it is an integer with a 32-bit sign. When working on such a declaration, it is essential that you note the type of the function argument which you must declare.
As is the case with Scala, if you wish to deal with more than one argument, ensure that you separate them through the use of commas.
The function in play yields another integer number with a 32-bit sign, and you can see this taking place after the right arrow, represented by the 132.
Where with Scala you had two options regarding variables, you should note that you only have one in this case. And by default, they are immutable.
This feature is what leads to high levels of safety when using this language. You declare your variables using let as is illustrated below:
let x = 5;The example code shown above declares a variable with a value of 5. The variable undergoes what is known as variable binding owing to this declaration. When this happens, you have bound 5 to the variable, which in this case is x.
The compiler in play will then regard the type of the variable as i32, as shown in the illustration before this. The great thing about variable binding is that it paves the way to match patterns as you continue. Take a look at one such instance:
let (x, y) = (5, 8);If you were to use this example, then 5 will remain bound to x, and the same goes for 8 which will thus get bound to y. You can then move forward to declare the type of the variable as shown in the instance below:
let x: i32 = 5;However, supposing that there will be a need for the variable to change once it undergoes initialization, it is important to add the mut keyword as shown:
let mut x = 5;If you have been keen as we have been going through the various statements, you will notice that they end with a semicolon as this is a requirement for their execution. It is different from most of the languages which you will come across.
Moving forward though, you will find that there are some exceptions to this rule, and it is thus important to note when it is necessary.
As for how hard it is to master this language, many people group it with Scala regarding difficulty. Over recent years, there have been many programmers embracing this language, leading to its use in tons of projects including Redox and Servo.
Kotlin
It took a while for people to learn about Kotlin and for this reason; it could be that you are yet to hear
of it. It gets its name from Kotlin Island in Russia. JetBrains is the company behind its creation. For
those familiar with PhpStorm, PyCharm, and IntelliJ IDEA, you will be happy to know that they all come from
the same organization.
This language became available to the market in 2011. It shares many similarities
with most of the modern languages. Take an example of the fact that it runs on top of the JVM like Scala. It
should not be hard to figure it out if you have dealt with other languages in the past.
This language became known towards the end of the second decade, in 2017. It was during the Google I/O
edition that the announcement came out that Kotlin was now getting first-class support on the Android Mobile
Platform.
On hearing this, you may wonder why that would amount to an increase in popularity. But once you
realize that it was the third language in history to receive such an honor, you begin to see what the big
deal is. Only C++ and Java have had such status before, and it was therefore impressive for a newcomer to
get that approval.
Following the announcement, developers in the Android community were quite excited, and this, in turn, led
to a buildup of interest in the language in the months that followed.
For some, this was somewhat a
strategic move on the part of Google. At the time, there were some struggles as to the use of specific Java
Classes in Android development and Google may have sought this language as an alternative to put an end to
the tension.
This language aims to interoperate with Java fully. It also promises users speed as fast as what they would
get were, they to use the Java native code. Let’s have a look at its simple function declaration and how it
compares to those of other languages:
fun factorial (x: Int) : Int {Can you see any similarities between this and what is present in the Scala declaration? They are pretty much the same thing, and thus if you know how to write a code block in Scala, you would not need much of an explanation in this regard. However, there are some things that you need to note.
//body goes here…. }
To start with, you will notice that the function gets declared by the use of the keyword fun. Additionally, you should note that the function only takes arguments of the type Int and that the yields are also in Int.
As for the variables, they are quite similar to what you would find in Scala. Do you remember the part where we delved into val and var and the differences in their execution? Well, the same thing applies to Kotlin as you will see in the examples below:
val x: Int = 5In the situation above where val is in use, the x serves as an immutable variable of the Int type. Y, on the other hand, is mutable and goes by Int.
var y = 8
When compared to Rust, Scala and Go, implementation of concurrency in this language is not as robust. In its execution, it uses coroutines. Additionally, it uses the idea of suspension where the computations can undergo suspension without barring a running thread.
There is a lot that you can do with this language, including the application of the same to existing codes in Java. Try it out and explore its versatility.
Swift
This language came to be as a means to deal with inefficiencies that were present in the Objective-C
language. Its creation took place at Apple under the lead of Chris Lattner. Interestingly, he was part of
the team that worked on the LLVM project. As compared to its predecessors, Swift aimed as being more concise
as well as safer than Objective-C.
The introduction of this language to the market took place in 2014 during a developers’ conference under
Apple before it became available as an open source project in 2015. Once you go through the workings of this
language, you will realize that it is quite similar to what you would find in Rust. Take a look at its
simple function declaration and see how it compares to modern languages:
func factorial (x: Int) -> Int {Have you seen this elsewhere? It is quite similar to what you would come across if you were to go through the declaration under Go. Take an example of the function declaration. Here, it goes under the keyword func which is close to what you would find under Go.
//body goes here }
In the case shown above, you will note that there is only one argument in play, of the type Int. The yield is also of the type Int.
As for the variables, you will notice that there are clear variations between the two. In the first case, there are immutable ones. These also go by the name constants as they do not change. In the second case, you have the mutable ones that also go by the name variables as they change.
The immutable ones undergo declaration using the keyword let while the mutable ones use var. Below is an example of how this works:
let str: String = “Welcome Home”In the first scenario, you are dealing with immutable str of the String type while in the second instance, you have a mutable variable x which falls into the Int type. When it comes to concurrency in the language, there has been a slow move in the adoption of language level concurrency features. However, recent versions have shown a change in the same.
var x = 5
However, that is not to say that you cannot have fun with this language. One of some ways in which it stands out is the use of Swift Playgrounds. Here, you get a sandbox in which you can execute codes on the fly. The impressive thing about this feature is that it also works on iPads.
Learning this language is not a hassle, and anyone who wants to do so can benefit significantly from the free manual that Apple has to offer. This compiled language works on Linux, iOS, macOS, watchOS and tvOS applications.
You will be happy to know that its syntax allows you to write clean and consistent code. Though this may feel a bit restrictive at times, it ensures that you prevent errors and thus improves readability, factors which in turn make it safe.
Also, using this language is fast. It features simple syntax coupled with handholding that allows you to work at a rapid rate. Compared to Python, it is an impressive 8.4 times faster. Compared to Objective-C, it is at least two and a half times quicker.
Thus, if you are looking to increase your performance, this may be the language for you. And it’s not only good regarding development speed, but it also enables you to create a product which you can safeguard from changes in the future. Suppose you want to add new features in a year, it would be easy to do so thanks to the extension capabilities owing to its ease of scaling.
Also, where you want to add developers to your team when you are well into the process, it is possible to do so thanks to the conciseness as well as the simplicity of its codebase.
How great is that! If there is one thing that sometimes bothers developers as they work apps is the third-party codes. There are the static libraries which get locked in the code as you compile them, and they thus become part of your file. As a result, the executable file increases in size and this adversely affects its loading time. Also, you cannot rely on automatic updates as the libraries remain in the version at the time of the compilation.
In the case of dynamic libraries, you can upload them when you need them, and you only require one of these as compared to the static ones which call for a copy in all the files. In this way, you can reduce your memory footprint.
What language appeals to you most? Try one of these modern languages and get to experience unparalleled performance levels at their best!