Implicit Vs Explicit: Understand the concept

Implicit Vs Explicit: Understand the concept

If you’re new to programming, the terms implicitly typed and explicitly typed may be uneasy to grasp initially, which is why I’ve put together this quick and precise guide for you.

As you probably, I’m an entry-level programmer and sometimes with programming concepts, things can get a little foggy.

To explain this concept, I’ll be using the Dart programming language as an example, but they should apply to other programming languages as well.

Explicitly typed

When a variable is said to be explicitly typed/declared, the datatype is specified during the initialization of the variable. Below the variable myAge is said to be explicitly declared because it has a datatype int that tells it from the unset, what type of value it should hold.

int myAge = 10;

Explicit declaration just means adding the data type before the name of the variable.

Implicitly typed

Implicit declaration happens when the compiler determines the type of the variable. Below the var keyword is used to declare a variable, it is not strictly stated what type of data the variable myGirlFriendAge should hold. It is left for the compiler to determine the variable type after a value has been assigned to it; since an integer is assigned to the variable myGirlFriendAge, the compiler automatically marks the variable type as an int. Basically, you are leaving it to the compiler to figure it out based on the value assigned, unlike with explicit declaration where you tell the compiler what type of value the variable should hold.

var myGirlFriendAge = 20;

Note: The compiler knows that myGirlFriendAge is an int with a process known as type inference. Not all programming languages may support type inference.

If you have any suggestions, contributions or corrections, share your thoughts.

Did you find this article valuable?

Support David's blog by becoming a sponsor. Any amount is appreciated!