Strongly-Typed vs Weakly-Typed
A strongly-typed computer language is one where the programmer declares in advance what data-type something is.
1var x string = "Hello world"
2
3func example(input1 int, input2 int) {
4 input1 - input2
5}
A weakly-typed language is one where the data-type is determined by what is given to it.
1var x = "Hello World"
2
3func example(input1, input2) {
4 input1 - input2
5}
Strict typing will help you avoid errors, like the one we saw earlier when trying to subtract strings ( "hello" - "world"
), before we even get to the compilation or run-time stages.
Weak typing allows you to have more flexibility in what you can do. The most strictly typed languages won't allow you to add an integer to a floating point number, whereas a weakly typed language would allow you to add a string and an integer.
16 + "5" // 65
Just be cautious when using weakly typed languages, you might get unexpected results if you don't handle type checking yourself (e.g. you think you're adding integers to integers but you're actually adding integers to strings.)