📜 ⬆️ ⬇️

About variables in programming

If you look at Wikipedia, you can see that a variable in programming is a named, or otherwise addressed, area of ​​memory whose address can be used to access data. The word from this definition to which I would like to draw your attention is data. Is it really so that in the programming languages ​​in which we write, variables are used only for accessing data. I, for example, write in PHP. And in it, as in other programming languages, variables, in addition to access to data, are also used to access objects (instances of classes) and arrays (associative and ordinary) and some other things. Data (strings, integers, floating-point numbers, boolean values), objects (instances of classes) and structures (associative and ordinary arrays, if you take PHP) for a person are essentially different entities (abstractions), and it would be reasonable in our programming languages, treat them like different things, ignoring the fact that for the machine they are the same (named memory areas). To do this, I suggest that instead of variables, start using such entities as, for example: an object , structure , data .

//Если раньше, например, для хранения объектов мы использовали переменные, которые в нынешнем синтаксисе объявляются с использованием символа $ $objectVar = new SomeClass(); //То теперь для объектов у нас будет специальная сущность "объект", которая, к примеру, будет объявляться с использованием символа ^ ^objectEntity = new SomeClass(); //Сущности "структура", к примеру, будут объявляться с использованием символа * *simpleArray = ['one', 'two', 'three']; *associativeArray = ['key' => 'val', 'another_key' => 'another_val']; //А сущности "данные", с использованием символа % %string = 'abcde'; %integer = 123; %floating = 1.23; %boolean = true; 

Such a replacement allows for the mental separation of such different entities that have nothing in common (abstractions) as objects , structures, and data .

An RFC for PHP on this topic is already in the making.

PS
In general, to create an RFC for PHP did not work, because PHP developers said that they do not want to spend the characters that will be needed to implement this idea. I add from myself that in PHP it still would not have been possible to implement it because it has dynamic typing. But! In a language with static typing, where types do not change, it is quite possible to implement. Therefore, I hope the developers of such languages ​​will turn their attention to the proposed idea.

Source: https://habr.com/ru/post/437496/