About the dynamically typed thing:
You are describing type inference instead of dynamic typing.
Type inference means, that the runtime/compiler infers the type of a variable/parameter from the current context (the "it knows" part).
example (JS):
varhello="world";// string
example (C#):
varhello="world";// string
Dynamically typed on the other hand means, that the type of the variable/parameter can be changed during runtime and is not bound to a specific type. In most cases, it's used with type inference, allowing for confusion.
example (JS):
varhello="world";// stringhello=42;// number
example (C#):
varhello="world";// stringhello=42;// COMPILER ERROR, this is NOT SUPPORTED by default in C# since hello is of type string!
C# DOES support dynamic typing, but it's required to opt-in per variable/parameter using the dynamic keyword. Please note that for most use cases, this is considered bad practice since compiler type checking DOES prevent a lot of errors in development BEFORE publishing your application to the public.
(Errors are caught during development and don't crash the application for the user in runtime.)
Thanks! I know that C# DOES technically allow for dynamically typed, hence the caveat, but this article is for codenewbies and I couldn't think of another language to explain it with or get examples from!
We're a place where coders share, stay up-to-date and grow their careers.
About the dynamically typed thing:
You are describing type inference instead of dynamic typing.
Type inference means, that the runtime/compiler infers the type of a variable/parameter from the current context (the "it knows" part).
example (JS):
example (C#):
Dynamically typed on the other hand means, that the type of the variable/parameter can be changed during runtime and is not bound to a specific type. In most cases, it's used with type inference, allowing for confusion.
example (JS):
example (C#):
C# DOES support dynamic typing, but it's required to opt-in per variable/parameter using the
dynamic
keyword. Please note that for most use cases, this is considered bad practice since compiler type checking DOES prevent a lot of errors in development BEFORE publishing your application to the public.(Errors are caught during development and don't crash the application for the user in runtime.)
Thanks! I know that C# DOES technically allow for dynamically typed, hence the caveat, but this article is for codenewbies and I couldn't think of another language to explain it with or get examples from!