What is the difference between "Explicitly" and "Implicitly" in programming language?
Asked Answered
L

5

14

I would like to have a clear and precise understanding of the difference between the two.

Also is the this keyword used to implicitly reference or explicitly ? This is also why I want clarification between the two?

I assume to use the this keyword is to reference implicitly (being something withing the class) whilst explicitly (is something not belonging to the class itself) like a parameter variable being passed into a method.

Of course my assumptions could obviously be wrong which is why I'm here asking for clarification.

Lorikeet answered 27/9, 2016 at 5:28 Comment(5)
"Explicitly" and "implicitly" are just words, not programming jargon. You would have to bring specific examples if you want to understand them in a particular context.Orfinger
Possible duplicate of When should I use "this" in a class?Blither
Those 2 words are adjectives, they could produce a different meaning base on how you use it.Humberto
If you use the word this in your program, e.g. this.foo = 2;, you are using it explicitly. If you leave it out but the compiler treats it the same as if you used this, e.g.foo = 2; where foo is an instance variable in your class, you are using this implicitly.Motive
Think of the dictionary definitions of the words. Explicit means that you state something without leaving out any details, and can be necessary to prevent ambiguity. Implicit means some details are not stated but can be determined without being stated because enough information is available. In programming the most common usage of these words is to describe how variables are declared. In Python you don't declare the type, but the type is implied by the value you assign. As for "this", it is explicit because it is potentially unnecessary information stated to prevent ambiguity.Ensoul
C
31

Explicit means done by the programmer. Implicit means done by the JVM or the tool , not the Programmer.

For Example: Java will provide us default constructor implicitly.Even if the programmer didn't write code for constructor, he can call default constructor.

Explicit is opposite to this , ie. programmer has to write .

Caracole answered 27/9, 2016 at 5:33 Comment(2)
Cool answer. no need to scroll down :😊Bemire
Beautiful answer. So basically, one way of looking at this is that explicit programming actions are hardcoded? Do I have that right? For example: if i explicitly tell a box to be 100 px by 100 px, thats hardcoded and explicit. Whereas if I make the program determine the box size programatically and dynamically, it is implicit.Outthink
D
7

already you have got your answer but I would like to add few more.

Implicit: which is already available into your programming language like methods, classes , dataTypes etc.

-implicit code resolve the difficulties of programmer and save the time of development.

-it provides optimised code. and so on.

Explicit: which is created by the programmer(you) as per their(your) requirement, like your app class, method like getName(), setName() etc.

finally in simple way, A pre-defined code which provides help to programmer to build their app,programs etc it is know as implicit, and which have been written by the (you)programmer to full fill the requirement it is known as Explicit.

Dovev answered 27/9, 2016 at 8:9 Comment(0)
H
5

1: Implicit casting (widening conversion)

A data type of lower size (occupying less memory) is assigned to a data type of higher size. This is done implicitly by the JVM. The lower size is widened to higher size. This is also named as automatic type conversion.

Examples:

    int x = 10;                    // occupies 4 bytes
    double y = x;                  // occupies 8 bytes
    System.out.println(y);         // prints 10.0

In the above code 4 bytes integer value is assigned to 8 bytes double value.

  1. Explicit casting (narrowing conversion)

A data type of higher size (occupying more memory) cannot be assigned to a data type of lower size. This is not done implicitly by the JVM and requires explicit casting; a casting operation to be performed by the programmer. The higher size is narrowed to lower size.

   double x = 10.5;             // 8 bytes
   int y = x;                   // 4 bytes ;  raises compilation error

1 2 double x = 10.5; // 8 bytes int y = x; // 4 bytes ; raises compilation error In the above code, 8 bytes double value is narrowed to 4 bytes int value. It raises error. Let us explicitly type cast it.

   double x = 10.5;                  
   int y = (int) x; 

1 2 double x = 10.5;
int y = (int) x; The double x is explicitly converted to int y. The thumb rule is, on both sides, the same data type should exist.

Hieratic answered 27/9, 2016 at 5:36 Comment(0)
B
4

I'll try to provide an example of a similar functionality across different programming languages to differentiate between implicit & explicit.

Implicit: When something is available as a feature/aspect of the programming language constructs being used. And you have to do nothing but call the respective functionality through the API/interface directly.

For example Garbage collection in java happens implicitly. The JVM does it for us at an appropriate time.

Explicit: When user/programmer intervention is required to invoke/call a specific functionality, without which the desired action wont take place.

For example, in C++, freeing of the memory (read: Garbage collection version) has to happen by explicitly calling delete and free operators.

Hope this helps you understand the difference clearly.

Bantling answered 27/9, 2016 at 7:3 Comment(0)
P
0

This was way more complicated than I think it needed to be:

explicit = label names of a index (label-based indexing) example:

df['index label name']

vs

implicit = integer of index (zero-based indexing)

df[0]
Piwowar answered 13/11, 2021 at 6:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.