What is true about programming languages?

Updated: 04/12/2021 by Computer Hope

What is true about programming languages?

In computer programming, true is a boolean value that represents mathematical and logical truth.

True is an important value in computing, because it is the basis of logical operations.

There are two possible boolean values, true and false. If something is true, it is not false; if something is false, it is not true.

Note

"Not false" is not the same as "true." Something may be "not false," and also "not true," if its truth or falsity is unknown.

In many programming languages, either true or True (with an uppercase T) is a reserved word — a special named value that cannot be redefined.

True in JavaScript

In programming, a truth test is often used as a conditional statement: "if something is true, do this; otherwise, do that."

In JavaScript, the special value true is implicitly tested in conditional statements. At the beginning of the conditional statement, an expression is provided in parentheses, followed by a block of code. If the expression evaluates as true, the code in the block is executed. If the expression evaluates as false, the code block is skipped.

For example:

var x = 3; // Declare a variable named x, and assign it value of 3. if (x == 3) // Test equality of value of x and 3. If they are equal, // run the code inside the braces { and }. { console.log("x must equal 3, because this line of code is running!"); }

If you run the above code, it outputs the following text to the JavaScript console:

x must equal 3, because this line of code is running!

Notes about the above code:

  • In JavaScript, the single equals sign = is an assignment operator. It tells the program, "set the variable on the left to the value on the right."
  • The double equals sign == is an equality test. It tells the program, "I want to know if the value on the left is equal to the value on the right."
  • The double slashes // indicate that the rest of the line is a comment. Everything after the double slashes is ignored by the computer when you run the program.

Tip

In JavaScript, the double equals sign == represents a "loose" equality test. For example, it treats the floating-point number 5.0 as equal to the integer 5, despite the fact that they are different data types.

The Boolean() function

In JavaScript, the function Boolean(something) returns true if the expression something is true.

For example, if you provide the expression 1 + 1 == 2 ("does one plus one equal two?") to the Boolean() function:

Boolean(1 + 1 == 2);

The function returns the special value true:

true

However, if the expression is not true:

Boolean(1 + 1 == 7);

The function returns false:

false

Below is an example of using the Boolean() function to test if the sum of two integers x and y is equal to a third integer z.

To use this function, named testTrue(), you must provide it with three integers as the arguments x, y, z. It checks if x + y equals z, and provides the result. If you run this code in a browser, it displays the result in a pop-up alert window.

function testTrue(x, y, z) { alert(`"${x} + ${y} equals ${z}" is ${Boolean(x + y == z)}`); }

For example:

testTrue(1, 2, 3)

Would display the alert message:

What is true about programming languages?

You can test this code below. In each of the three text boxes, enter an integer (a whole number). Then, click the button to run testTrue() using those three numbers as x, y, and z.

+ =

Note

If you see "NaN" in your result, that means you typed something that is not a number.

Absolute, Condition, Linux, Programming terms, Valid, Verify

This is part II of our three-part series: Programming Languages: the Good, The Bad & The Ugly. For Part I on good programming languages, check out our blog post here.

First up, let’s define bad programming languages. To understand why a programming language is considered bad, one of the things to look at is its syntax. Syntax describes which strings of characters comprise a valid program. Sounds quite complicated. Put simply, the syntax describes the rules the code has to follow in order to be valid. When compared to spoken languages, the syntax is a little bit like grammar. In order to communicate effectively, you have to get your punctuation right. The same is true for code: in order to program effectively, you have to get your syntax right.

Different programming languages use different syntax. For a really great snapshot of what this looks like, check out this comparison of how many lines of code it takes to write “Hello World” in any given programming language.

But enough in terms of introduction. Let’s see which programming languages are the most dreaded.

The Bad

According to StackOverflow’s 2021 Developer Survey, COBOL is the most dreaded programming language. VBA and Matlab follow closely. For all three languages, more than 78% of developers say they dread them. Let’s find out why this is the case. Here’s how to write a “Hello World” program using COBOL:

What is true about programming languages?

Code required to write a Hello World program in COBOL

For comparison, here’s how to achieve the same in Python:

What is true about programming languages?

Code required to write a Hello World program in Python

To be fair, COBOL is a relatively old programming language. It first appeared in 1959. Python, on the other hand, was created in the 1990s, with three decades of extra knowledge.

What does the example above illustrate? A good programming language has easy, English-like syntax, making it easy to read, write and understand. Vice versa, a bad programming language is just the opposite. COBOL is considered wordy and cluttered.

Other Things to Consider

Even though we singled out COBOL as an example of a bad programming language, it does have its applications and some systems that are still in use, especially at government organizations or banks, were written in COBOL. In the 1970s, COBOL was in fact the most widely used programming language in the world.

Syntax apart, COBOL and other older languages are simply reaching their limitations. Applications are more complex than what can be achieved with older languages. There’s also the problem of finding developers who know how to write older languages. According to IBM, the average age of a COBOL programmer is 58 and around 10% of them retire every year.

So, to be fair, it’s not so much that these programming languages are bad. Just on the contrary: they more than served their purpose and their longevity is testament to their usefulness. It’s more that software engineering has moved on: the pace of innovation in software and its underlying languages is incredibly fast. And that’s where older languages gradually get replaced with newer, easier languages that are more popular, more in-demand and more useful.

First of all, not being compiled and being interpreted (what he surely meant by scripted, which is somewhat vague and used for different purposes anyway) are different sides of the same coin, and thus really the same reason.

The last reason, that it doesn't run on every platform, is just confusing. It sounds like he's trying to tout Java's portability and PHP simply isn't Java. However, Java runs on one very specific platform: the JVM. That platform in turn runs on many other platforms, and thus gives Java its portability, but it's not quite the same as the traditional use of "portable". For example, C is portable and runs on everything from a PDP-11 to the latest embedded devices.

However, C does that by specifying rules of its own abstract platform, and compilers transform C code into assembly according to those rules. This is how Java's portability is similar to C's: they both define rules which are translated into instructions for a specific, concrete machine (processor); the difference is when that occurs.

All problems in computer science can be solved with another level of indirection.
  — David Wheeler

In reality, even assembly or "machine code" is interpreted by the processor into its native actions. (I don't have a good source at hand for this, but I recall that it's lightly covered by A Crash Course in Modern Hardware, which is a good presentation anyway.) As processor speeds get faster, we hardly notice on our underused boxes whether a given program is in asm or run through an interpreter, but this is where the definition of "real programming language" comes into play.

The only sensible way to define a "real programming language" is as "a language to get real work done", but that really punts on the definition of "real", too. (It does, however, establish a distinction with esoteric programming languages, because nobody does real work, for example, in Malbolge, for any definition of "real" you could get ten people to agree upon.) And, compared to today, your choices of a programming language were much more limited by their implementation strategy and overhead (e.g. a runtime interpreter) in the past. However, even today, some languages are more "real" than others for certain applications and expected loads, it all depends on your requirements.

It sounds like your teacher has only experienced PHP through toy web applications (and maybe using 'application' is a stretch for what he's seen). Toy programs aren't real work. PHP definitely has a lot of problems, but I could not say it isn't a real programming language, except in jest.

Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.
  — Dan Kaminsky

There is a certain association of "real" with "hard to do" (related to "real work") and your teacher may have been expressing this sentiment. This has always appeared to me as a form of bikeshedding (there's a better term for this exactly, but I can't remember it), where one's estimation of the value of a thing is related to the effort one had to put into it (e.g. a bikeshed is more important when I provided input on the color of the roof and whether it should have a sign). We intrinsically value our own effort more than that of others – just because we're familiar with it, if for no other reason – even when it doesn't make sense to do so. PHP, despite its faults, does make some things easy, and it and programs written in it can consequently be perceived as worth less.