GNU/Linux Programmer's Solver - Introduction

Programming exercises in 18 Programming Languages
linuxprogramming
Programmer's Solver provides solutions to simple programming exercises and common code you usually need in your programs and scripts using different programming languages. If you are learning are learning programming or you already know some languages but need to quicly switch to another one, this will become an useful reference.

Note: The GNU/Linux Programmer's Solver is a work in progress and when finished will be available as a free ebook you can download. In the meantime you can check the available content in this page

Introduction

This project was born as a way to get a quick reference for switch between programming languages. In my career I have had to use many different programming languages for different problems. Each programming language has is pros and cons and sometime, choosing the right one makes a huge difference on how quick and easily you can solve the problem.

However, many time once the problem got solved, I didn't have to use that language again for months and when it comes the time to use it again I had already forgot the syntax details and it took me a while to get up to speed. And that process usually required to check tutorials and code examples all over the Internet. Instead of doing that over and over again, I compiled together this collection of programming examples for quickly check how to do a loop in bash, or how I could print a string in Lua.

Even when that was the main motivation for this book, the examples it contains are simple enough to get somebody that wants to learn programming going in no time. So in either case, hope this may be useful for you. I have to recognize that I use it very often and it is really working as intended.

The Title

Many moons ago, when computer RAM was counted in Kbs and hard drives were a luxury only companies could afford, I discovered a wonderful book. Its title was:

The Programmer's Solutions Manual for IBM PC, XT, AT, and compatibles
That book is still on my shelf. It's one of my prized possessions. And now I'll tell you why.

Putting aside the sheer number of amazing things it told about the early PCs, the book was organized in a very peculiar way. Every topic it discussed, it solved in three levels.

First, it showed you a solution in BASIC (a language we won't be talking about here), then how to do it using the computer’s BIOS, and finally how to solve the issue by directly accessing the hardware. Believe it or not, this approach proved super practical to me, and I learned a great deal. Seeing the high-level solution made the low-level ones much more understandable. As I said, a true gem.

Well, now you know where the title comes from. A small homage to a book that gave me so much.

How to Read the Online Book

The magic of hypertext allows me to organize this content in a way that may better suit some of you. Here's how you can approach accessing the information in this book:
  • The Direct Approach. At the very end of this page, you will find a link to do a linear read, as you would with a physical book. This is the recommended reading, at least the first time, because some chapters make references to earlier ones. This is because all those programming languages, ultimately, are not that different.
  • Per Language. The next section includes a list of all the languages covered by the book, and each section will have a link to a mini-book version just for that language. This is great for reference if you are trying to use a forgotten or new language.
  • Per Exercise. Finally, also at the end, I provide a link to explore the book by exercise. That link will lead you to a list of exercises, each containing the solution for all the languages. This is more convenient if you are following a more comparative approach and want to know how some languages differ from others.
Choose the way that best suits your needs; however, I'd recommend a first sequential read so you know what is there and how things relate to each other. After all, the book is not that big—most of it is just code.

The Languages

The GNU/Linux Programmer's Solver shows those simple programming examples in 18 programming languages. In this section we'll go through the list with a brief note of what is that language good for and why you may need it.

C

The C programming language is among the oldest and most enduring, and remains a personal favorite. Contrary to popular belief, it is also remarkably portable.

Beyond its widespread use in the development of operating systems – making it a natural choice for interacting with them – C is often the only practical option when writing system tools, embedded software or other low-level programming applications.

Therefore, C is a language well worth learning.

C++

Personally, I find it unappealing, and from an object-oriented perspective, I can only consider it a regrettable design. However, this is merely a personal opinion. Regardless of my sentiments, it remains a very popular and widely used language for non-trivial software—software of substantial size and demanding high efficiency.

Regrettably, the language continues to evolve with each revision of the standard, making it an excellent choice for those seeking a lifelong intellectual challenge.

C++ is also prevalent in scientific application development and appears to be consistently gaining popularity, though without undue haste.

Objective-C

Objective-C extends the C language with an object-oriented model as elegant as that of its predecessor, Smalltalk. While the language was historically confined to the software framework associated with NeXT, its relevance has grown significantly in recent years due to its use in programming iOS devices.

Objective-C served as the foundation for the NeXTStep environment. As you will see, a significant portion of this environment has endured and remains in use today. Elements of NeXTStep are recognizable by the `NS` prefix in identifiers.

Perl

Perl was the preeminent scripting language before the rise of Python and remains a common sight in existing codebases. Setting aside the language's current popularity, Perl embodies the spirit of the hacker culture and the UNIX environment.

It is worthwhile to learn Perl for this reason alone, but in truth, it is remarkably powerful when processing text and crafting small utilities. Yes, it is a personal favorite, so you will have to accept this (or skip those chapters).

Perl was among the first languages (alongside the shell) employed to generate dynamic web content using the CGI interface. While CGI is now largely obsolete, it remains functional and may occasionally prove useful in unexpected situations.

Python

Python is arguably the most popular scripting language today, thanks to the tremendous support it has received in recent years, with Python modules now available for virtually any task.

Personally, I view it as the BASIC of the twenty-first century, although the difference between Python and those BASICs of the 1980s is substantial.

It is a language that is easy to learn and adequately covers the major programming paradigms: structured, object-oriented, and functional (to a certain extent).

Python is also prevalent in web development, with several frameworks written in this language, such as Django and Flask, among the most popular. It has also become the de-facto standard for machine learning and AI.

Ruby

Ruby, as its name suggests, is a gem. It is a remarkably elegant language and, from my perspective, an excellent introduction to object-oriented programming. Without a doubt, it is superior to C++ and, in my opinion, more consistent than Python.

While not as popular as Python or as it was in Perl's heyday, Ruby has carved out its own niche within the industry. In web development, Ruby on Rails is arguably the most well-known framework.

Ruby is also prominent in the security world, as it is the language in which the Metasploit framework is programmed—a framework popularized by the Kali Linux distribution, well-known among skids all over the world. All reputable security professionals understand that true hackers program in C or Perl ;).

Java

Java is the younger, more pragmatic sibling of C++. It’s a decent choice for those beginning their journey into object-oriented programming; however, the pursuit of simplicity and safety has resulted in the elimination of several important features, such as multiple inheritance.

Initially developed as a cross-platform solution (although its novelty was perhaps overstated at the time), it remains an interesting option for creating general applications that need to run on various platforms. The language falls short when it comes to system applications—which is logical, as true cross-platform compatibility is challenging at that level.

Java remains popular within enterprise environments and the back-ends of business-critical websites. Servlets and JSPs were significant in the past, and the underlying concept remains valid and continues to be utilized.

The term “Java” is often used not only to refer to the programming language itself but also to the Java Virtual Machine. In recent years, alternative languages have been developed leveraging the existence of the JVM. Languages such as Groovy, Jython, Clojure, Scala, and the more recent Kotlin (which will be discussed in this book) are a few examples.

Finally, Java is noteworthy as the original development language for the Android platform, now displaced by Kotlin.

Kotlin

One of the most recent languages built upon the Java Virtual Machine (JVM), Kotlin has gained popularity recently as it, alongside Java, represents one of the supported languages for Android Studio for Android app development. Being the preferred one nowadays.

Compared to Java, Kotlin is less verbose. Like other languages leveraging the same virtual machine, it offers concepts inherited from functional programming, which have become increasingly popular in recent years.

C#

C#, developed by Microsoft as the primary language for its .NET environment, doesn't offer significant innovations from a programming perspective. At first glance, it appears to be a cosmetic revision of Java with a few updates. However, what makes this language interesting is the ubiquity of the .NET environment on Windows platforms, as well as its adoption by Unity, which has become the standard platform for game development in recent years. This is the reason we are including it in this list of programming languages.

TCL

TCL is one of the most veteran scripting languages still in existence. It gained popularity long ago thanks to the TK graphical toolkit, which allowed for the creation of graphical user interfaces (GUIs) very easily—in the era of Motif, when programming a GUI was far from straightforward.

TCL is a language I hold a great deal of affection for, as it was the first scripting language I learned, even before bash. It’s very easy to learn and surprisingly powerful. In its day, before Java applets existed, it was already possible to write web applets in TCL, although they never achieved the same recognition as Java applets, which appeared around the same time.

Lua

Lua is a very lightweight scripting language. It’s so lightweight that WiFi microcontrollers like the ESP chose it as their default firmware. It’s a very simple language to learn, ideal for adding scripting capabilities to larger systems.

For example, nmap, THE PORT SCANNER (yes, with capital letters), offers a scripting engine that allows us to extend its capabilities using this programming language. Same happens with wireshark, THE SNIFFER (yes, also with capital letters). Or video players like `VLC` or `mpv` that can be extended using small scripts in Lua. It’s an easy-to-learn language that can provide significant benefits. Don't miss out on it. You can also find it as a scripting language in some games.

Go

Go is a relatively recent compiled language. It aims to be an improved version of C, addressing some of its problems, such as memory management, weak typing, and similar issues. Therefore, this language is oriented towards systems programming, just like C.

The language was developed internally by Google... and you can take a look at Wikipedia to consult the details.

The development of certain applications like `Docker` or `Kubernetes` has fostered its popularity in today's trendy devops environments.

Rust

Rust is another recently created compiled language that aims to solve the main problems of C++, specifically memory management, while attempting to provide its performance.

Rust allows the development of system applications, just like C or C++, and to demonstrate this, even test operating systems have been developed to showcase the language’s power and is officially accepted for the Linux kernel development. It's also used being used, modestly, in embedded systems

PHP

PHP, a proud heir of C and Perl, has been (and likely continues to be) the most popular programming language for web applications on the server-side in the world of open-source software. The best option for many years. WordPress, among others, is programmed in PHP. If you know C and/or Perl, this language will seem extremely easy to you.

It remains one of the best options for web application development.

JavaScript

When we talk about web development on the client-side, JavaScript is practically the only option available. No. HTML and CSS are not programming languages. With the advent of Google’s V8 engine and solutions like `node.js`, the language has started to be used in other environments.

JavaScript is an interpreted language, with weak typing and, at the very least, interesting features, especially from the perspective of object-oriented programming. For all these reasons, it's a language that every programmer should have in their arsenal, just in case.

Also note that Frida uses it for writing instrumentation implants.

Ada

Ada was developed by the United States Department of Defense (DoD), and it's popular in the aerospace and defense sectors, or more generically in so-called mission-critical applications.

Ada is a strongly-typed language that resembles Pascal and has an elegant and consistent syntax, offering built-in support for concurrent programming and great versatility in type definition, due to its strong typing.

It is really an elegant language that worth a try.

Assembly

While, nowadays, almost no programmers use assembly language, having some basic knowledge of this language is very interesting to be aware of what the computer is truly capable of and how it does it. The abstractions of high-level languages make certain operations seem simple, but much more than we believe happens behind the scenes.

The assembly language is much more powerful than many people think, and it's the only option when it's necessary to reduce the size of programs or optimize their speed.

Table of Contents

Chapter 1. Hello World

Chapter 2. Conditional Expressions [COMING SOON]

Chapter 3. Comparing Strings [COMING SOON]

Chapter 4. Loops [COMING SOON]

Chapter 5. Parsing command-line parameters [COMING SOON]

Chapter 6. User Input [COMING SOON]

Chapter 7. Functions [COMING SOON]

Chapter 8. Closure [COMING SOON]

Return to Home Page