Binding, assignment, and such: Difference between revisions

From Helpful
Jump to navigation Jump to search
mNo edit summary
 
mNo edit summary
 
Line 5: Line 5:
<!--
<!--


Binding - create new variable in the current context
Assignment - change value of a given variable, often within the narrowest scope


This one is a little messy in that
: ''the most abstract'' definitions are relatively vague,
whereas
: language-specific ones may be more understandable, but also not exactly match other language's




The language you use has an effect
Declaring - create new name in a scope
 
Binding - tie a name to something
 
 
 
 
 
 
A lot of the time, declaration means '''variable declaration''', which
* can but does not need to declare the variable's name
* can but does not need to declare the variable's type
* can but does not need to declare the variable's value be allocated / reference be set
* can but does not need to declare the variable's initial value
* can but does not need to declare the variable's scope
* can but does not need to declare the variable's mutability (of ''reference'' and/or value)
 
Depending on the language you're working in, some of those may be ''required''.
 
 
But also frequently not.
 
Say, in JS
* nothing settles type (it's a [[dynamically typed]] language)
* var settles a name, and scope (via var's rules)
* const settles a name, initial value, and scope (via const's rules)
* function definition, the initial value and its type, and its scope
 
 
'''Binding''' -
: usually refers to altering the association of a variable name with variable entity
 
 
 
'''Assignment''' - alter the value of a given variable (and/or the reference to an object)
:: often within the narrowest scope
 
 
 
Some languages are somewhat fuzzy about the distinction in binding and assignment,
and e.g. = may be doing a bit of both.


Some languages are somewhat fuzzy about this distinction,
for example python's = can be both, which in a few cases can mean you need


functional languages tend to not assign, but may well still bind
functional languages tend to not assign, but may well still bind


-->
-->

Latest revision as of 16:50, 22 June 2024