Being a Web Developer – Programming Languages

What are programming languages?

Programming languages are a way for humans and computers to communicate. People read code many, many multiples of times more than they write it – so developers create programming languages which are good at so…

What are programming languages?

Programming languages are a way for humans and computers to communicate. People read code many, many multiples of times more than they write it – so developers create programming languages which are good at solving particular problems with a small amount of code. Here’s an example using JavaScript:

var name = "Danger"
console.log("Hello, " + name)

The first line makes a variable (effectively a box you can store other things in) and then the second line outputs text to the console (for example DOS, or the terminal) “Hello, Danger”.

JavaScript is designed to work as a scripting language, which means the code starts at the top of the file and then goes through line by line downwards running that code. To provide some contrast, here is the same behavior in Java, which is built with different language constraints:

class Main {
  public static void main(String[] args) {
    String name = "Danger";
    System.out.println("Hello, " + name);
  }
}

These two code samples do the same thing, however the Java version comes with a lot of words that aren’t necessarily about telling the computer exactly what to do, e.g. class Main {, public static void main(String[] args) {, and two extra }s. It also has semi-colons at the end of some lines. Neither of these programming languages are wrong, Java however, is aimed at building different things from JavaScript, and these extra bits of code make sense within the constraints of building a Java app.

// JavaScript
var name = "Danger"

// Java
String name = "Danger";

Both of these lines declare variables called name which contain the value “Danger”.

In JavaScript you use the abbreviation var to declare a variable. Meanwhile, in Java you need to say what kind of data the variable contains. In this case the variable contains a String. (A string is a programming term for a collection of characters. They “look like this”. This 5m video is a good primer if you want to learn more.)

Both of these variables contain a string, but the difference is that in Java the variable can only ever contain a string, because that’s what we said when we created the variable. In JS, the variable can change to be anything, like a number, or a list of dates.

To illustrate:

// Before in JS
var name = "Danger"
// Also OK
var name = 1
var name = false
var name = ["2018-02-03", "2019-01-12"]

// Before in Java
String name = "Danger";
// Not OK, the code wouldn't be accepted by Java
String name = 1;
String name = false
String name = new String[]{"2018-02-03", "2019-01-12"};

These trade-offs make sense in the context for which these languages were built back in 1995. JavaScript was originally designed to be a small programming language which handled simple interactions on websites. Java on the other hand was built specifically to make complex apps which could run on any computer. They expected to be used to build codebases of different scales, so the language required programmers write different types of code.

Java required programmers to be more explicit with the values of their variables because the programs they expected people to build were more complex. While JavaScript opted for ease of reading by omitting information about the specifics, and expected codebases to be significantly smaller.

Paul Ishaili C.

Traditional Creative Director, Software Engineer and Tech Writer


Print Share Comment Cite Upload Translate
APA
Paul C. Ishaili | Sciencx (2024-03-28T14:20:01+00:00) » Being a Web Developer – Programming Languages. Retrieved from https://www.scien.cx/2022/07/18/being-a-web-developer-programming-languages/.
MLA
" » Being a Web Developer – Programming Languages." Paul C. Ishaili | Sciencx - Monday July 18, 2022, https://www.scien.cx/2022/07/18/being-a-web-developer-programming-languages/
HARVARD
Paul C. Ishaili | Sciencx Monday July 18, 2022 » Being a Web Developer – Programming Languages., viewed 2024-03-28T14:20:01+00:00,<https://www.scien.cx/2022/07/18/being-a-web-developer-programming-languages/>
VANCOUVER
Paul C. Ishaili | Sciencx - » Being a Web Developer – Programming Languages. [Internet]. [Accessed 2024-03-28T14:20:01+00:00]. Available from: https://www.scien.cx/2022/07/18/being-a-web-developer-programming-languages/
CHICAGO
" » Being a Web Developer – Programming Languages." Paul C. Ishaili | Sciencx - Accessed 2024-03-28T14:20:01+00:00. https://www.scien.cx/2022/07/18/being-a-web-developer-programming-languages/
IEEE
" » Being a Web Developer – Programming Languages." Paul C. Ishaili | Sciencx [Online]. Available: https://www.scien.cx/2022/07/18/being-a-web-developer-programming-languages/. [Accessed: 2024-03-28T14:20:01+00:00]
rf:citation
» Being a Web Developer – Programming Languages | Paul C. Ishaili | Sciencx | https://www.scien.cx/2022/07/18/being-a-web-developer-programming-languages/ | 2024-03-28T14:20:01+00:00
https://github.com/addpipe/simple-recorderjs-demo