10 Programming Languages Side by Side (JS, Python, Ruby, PHP, GO, Rust, Dart, C#, Java, Ballerina)

Posted on

Using the below you can see the basics of 10 different languages. For most of these langauges you should be able to try them out by generating a REPL.



How to print text to the console

One of the first things you need to learn in any language is how to print text in the console. Being able to print text to console allows us to…

  • print the value of variables to check that they have the right values
  • print the return values of functions so we can make sure they return the right value
  • be used just to print text to confirm parts of our code are running



Javascript

console.log("Hello World")
Enter fullscreen mode

Exit fullscreen mode



Python

print("Hello World")
Enter fullscreen mode

Exit fullscreen mode



Ruby

puts "Hello World"
Enter fullscreen mode

Exit fullscreen mode



PHP

<?php

echo "Hello World";

?>
Enter fullscreen mode

Exit fullscreen mode



GO

import fmt

func main(){
  fmt.Println("Hello World")
}
Enter fullscreen mode

Exit fullscreen mode



Rust

fn main(){
  print!("Hello World");
}
Enter fullscreen mode

Exit fullscreen mode



Dart

void main(){
  print("Hello, World!");
}
Enter fullscreen mode

Exit fullscreen mode



C Sharp

using System;

namespace HelloWorldApp {
  class HelloWorld {
    static void Main(string[] args){
      Console.WriteLine("Hello World");
    }
  }
}
Enter fullscreen mode

Exit fullscreen mode



Java

class HelloWorld {
  public static void main(String[] args){
    System.out.println("Hello, World");
  }
}
Enter fullscreen mode

Exit fullscreen mode



Ballerina

import ballerina/io;

public function main() {
  io:println("Hello World");
}
Enter fullscreen mode

Exit fullscreen mode



Declaring Variables

Storing data to use is pivotal in programming. Data is generally stored in variables that we declare. These variables can hold data like numbers, strings and booleans (true/false).



Javascript

let number = 5
let str = "Hello"
let bool = true
console.log(number, str, bool)
Enter fullscreen mode

Exit fullscreen mode



Python

number = 5
string = "hello"
boolean = True
print(number, string, boolean)
Enter fullscreen mode

Exit fullscreen mode



Ruby

num = 5
str = "Hello"
bool = true
puts num, str, bool
Enter fullscreen mode

Exit fullscreen mode



PHP

<?php
$num = 5;
$str = "Hello";
$bool = true;

echo $num;
echo $str;
echo $bool;
?>
Enter fullscreen mode

Exit fullscreen mode



GO

import fmt

func main(){
  num := 5
  str := "Hello"
  boolean := true
  fmt.Println(num, str, boolean)
}
Enter fullscreen mode

Exit fullscreen mode



Rust

fn main(){
  let num = 5;
  let string = "Hello";
  let boolean = true;
  print!("{0} - {1} - {2}", num, string, boolean );
}
Enter fullscreen mode

Exit fullscreen mode



Dart

void main (){
  var number = 5;
  var string = "hello";
  var boolean = true;
  print(number, string, boolean);
}
Enter fullscreen mode

Exit fullscreen mode



C Sharp

using System;

namespace MyProgramApp {
  class MyProgram {
    static void Main(string[] args){
      int num = 5;
      string str = "Hello";
      bool boolean = true;

      Console.WriteLine(num);
      Console.WriteLine(str);
      Console.WriteLine(boolean);
    }
  }
}
Enter fullscreen mode

Exit fullscreen mode



Java

class Main {
  public static void main(String[] args){
    int num = 5;
    String str = "Hello";
    boolean bool = true;
    System.out.println(num);
    System.out.println(str);
    System.out.println(bool);
  }
}
Enter fullscreen mode

Exit fullscreen mode



Ballerina

import ballerina/io;

public function main(){
  int num = 5;
  string str = "Hello";
  boolean bool = true;

  io:println(num);
  io:println(str);
  io:println(bool);
}

Enter fullscreen mode

Exit fullscreen mode



Collection arrays and key/value pairs

Usually you have two main collections you’ll use most of the time.

  • Arrays/Lists that will be used to store data in an order that is referenced by a zero based index

  • A key/value pair structure by which you can reference different values based on a key.



Javascript

const myArray = [1,2,3,4,5]
const myObject = {name: "Alex Merced", age: 35}

console.log(myArray)
console.log(myObject)

Leave a Reply

Your email address will not be published.