| One important concept to understand when | | | | languages are more flexible. Since more errors |
| programming is the difference between static and | | | | tend to occur at run-time than compile-time, |
| dynamic typing. Static typing can be seen in | | | | these programs are often more difficult to debug. |
| languages such as Java or C++, and dynamic | | | | As such, the principle of unit testing, or testing |
| typing is used in languages such as Python or PHP. | | | | one piece of the program at a time, is extremely |
| Each has its advantages and disadvantages. | | | | important when working with a dynamic language. |
| Static typing, because type checking is performed | | | | Note that static and dynamic typing are not the |
| during compilation, allows for errors to be caught | | | | same as strong and weak typing. Strong typing |
| early in the development process. This way, the | | | | simply means that variable types are required, |
| checks do not need to be performed each time | | | | and weak typing is when variables do not have a |
| the program is run and can make program | | | | specific type. Many people assume static and |
| execution more efficient. Variables cannot be | | | | strong typing are the same thing as are dynamic |
| created on the fly as they are needed; they | | | | and weak typing, but this is not necessarily true. |
| must first be defined. Some programmers dislike | | | | In Python, variables can be dynamically created as |
| this extra step in coding, but it often makes for | | | | they are needed, but it is not a weak language as |
| safer, more predictable program outcomes. | | | | variables have types. |
| In dynamic typing, type checking is done at | | | | As you can see, understanding the difference |
| run-time rather than compile-time. As a result, | | | | between static and dynamic typing is an |
| these languages can produce more run-time | | | | important aspect of programming, and can help |
| errors and have less guarantees with how the | | | | you chose the language which best suits the |
| program will run, since certain "invalid" programs | | | | needs of your application. Each has its own pros |
| which a static typing language would reject at | | | | and cons, but both are widely used. |
| compilation are allowed to run. However, dynamic | | | | |