A nice thing from various programming languages ASM BASIC C CPP LUA Python Golang Haskell

pmalhaire

pmalhaire

Posted on February 8, 2021

A nice thing from various programming languages ASM BASIC C CPP LUA Python Golang Haskell

One nice thing from various languages

I don't think there is a best programming language but each of them has some story to tell. Here is a thing I learned from 10 of them.

Assembly (ASM)

Probably the language I read most without writing a line of it. I learned how instructions are done here and how to compare language performance from a neutral point of view.
ASM is my comparing star. Don't forget that at the end there is a CPU / GPU / TPU running your code.

        push    rbp
        mov     rbp, rsp
        mov     DWORD PTR [rbp-4], edi
        mov     eax, DWORD PTR [rbp-4]
        imul    eax, eax
        pop     rbp
        ret
Enter fullscreen mode Exit fullscreen mode

https://godbolt.org/ is great for this !

Basic

10 LET N=10
20 FOR I=1 TO N
30 PRINT "Hello, World!"
40 NEXT I
Enter fullscreen mode Exit fullscreen mode

My first language. Simplicity is the Key. I felt just at home without any programming knowledge, it made it popular in the 80s.

C


 

#include <stdio.h>
int main() {
   printf("Hello, World!");
   return 0;
}
Enter fullscreen mode Exit fullscreen mode

The Root of Every language. Simple, old but elegant. Few key words and many features. C is the star of longevity.

Cpp

class MyClass {       // The class
  public:             // Access specifier
    int myNum;        // Attribute (int variable)
    string myString;  // Attribute (string variable)
};
Enter fullscreen mode Exit fullscreen mode

The meta language. I learned object oriented programming with Cpp.

Smart pointers is my star for cpp :

  • unique pointer (one owner)
  • shared pointer (one or many owner)
  • weak pointer (user not owner check still exist before use)

https://en.cppreference.com/book/intro/smart_pointers

Lua

    a.x = 10                    -- same as a["x"] = 10
    print(a.x)                  -- same as print(a["x"])
    print(a.y)                  -- same as print(a["y"])
Enter fullscreen mode Exit fullscreen mode

Tiny but strong one. Readable without knowing it but fast. Table is my Lua star, a list and a dictionary at the same time.

https://www.lua.org/pil/2.5.html

Python

>>> f'Hello, {name}!'
'Hello, Bob!'
Enter fullscreen mode Exit fullscreen mode

Python is the language for scripting. My python star is formatted string. f'Hello, {name}!' expanding variables in string feels just more natural than any other language I tried.

Golang

package main

import "fmt"

func send(c chan int) {
    // send 1 to c
    c <- 1 
}

func main() {
    // create channel
    c := make(chan int)
    // run in background
    go send( c)
    // wait for result
    x := <-c
    // print result
    fmt.Println(x)
}
Enter fullscreen mode Exit fullscreen mode

Golang is a simple and very portable language from plan9 team. Goroutine and channels are my star for golang. Parallel and concurrent programming fell just simple.

Launch an operation in background and get the result after. The syntax is the clearer I saw.

https://tour.golang.org/concurrency/2

Haskell

let x = 1:x in x
Enter fullscreen mode Exit fullscreen mode

Haskell feels like entering programming from an other door. Lost at First it gave me an other vision of programming. Lazy evaluation is my star of Haskell. It allows the language to define an infinite list as it will be used only when requested.

https://wiki.haskell.org/Lazy_evaluation

Conclusion

I hope this was interesting for you. Learning languages is a new way of looking at computer science.

💖 💪 🙅 🚩
pmalhaire
pmalhaire

Posted on February 8, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related