[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 16 KB, 396x334, intercambio-2-variables.png [View same] [iqdb] [saucenao] [google]
6880070 No.6880070 [Reply] [Original]

Why you cannot declare a variable starting with a number, explain yourself in a simple way, don´t try to show your intelligence speaking non-understandable garbage

>> No.6880074

>>6880070
>don´t try to show your intelligence speaking non-understandable garbage

You first.

>> No.6880077

You can.

>> No.6880081

>>6880070
What the hell are you asking?

>> No.6880083
File: 1 KB, 582x49, d.png [View same] [iqdb] [saucenao] [google]
6880083

>>6880081

>> No.6880086

>>6880077
I know ,but usually why you can´t

>> No.6880087

>>6880083
Well, because syntax, i.e the devolpers thought it'd get confusing (both to the programer and to the compiler) if you can treat literals as variables.

>> No.6880094

>>6880083
When you use 1 in your code, how should the interpreter know you mean 1=21 and not 1=1 ?

>> No.6880095

>>6880087
confusing to programmers? i don´t think so

>> No.6880097

>>6880094
how should the interpreter know i mean a = 21 and not 1=1.
see how counfising is your statement.

>> No.6880102

how should the interpreter know i mean a = 21 and not a=1.
see how counfising is your statement.
sorry wrote that shit wrong

>> No.6880104

>>6880097
a is not a statement.

Look at this
>a=21
>print(a+2)
>>23

and compare with
>1=21
>print(1+2)
What's the output? In the first example, a is unambiguous, since it doesn't have a previous value. Now what kind of 1 should the interpreter take? 1 or 21?

Keep in mind that a is a variable, where is "a" is a literal.

>> No.6880110

>>6880104
Hell dude , you blew my mind, thanks.

>> No.6880111

because 2a = 2 times a = a + a

>> No.6880144

>>6880070
The compiler needs to parse the program, and it was easier to just insist variables start with letters or _ in the early compilers and tokenizers.

It also makes it easier to catch programming errors.

>> No.6880148

>>6880070
It looks nicer.

The commutative property of multiplication should allow you to switch the numbers around in any order.

>> No.6880181
File: 2 KB, 174x128, programmer logic.png [View same] [iqdb] [saucenao] [google]
6880181

>>6880070
is 21e2 a variable or number in scientific notation?
is 0xDEAD a variable or number in hex?

>> No.6880185

>>6880181
is 0xDEAS a mistake or a variable?

>> No.6880189

>>6880181
Nice image, I was about to bring in the difference between object based languages and type based languages. Basically, object based languages allows you to do so since they point to an object representation of the concept, such that the object 1 can be made to reference the object 21 in earlier example. This is a conceptual choice and requires to be extra careful, but gives flexibility in the "types".

>> No.6880214
File: 2.97 MB, 620x412, 1414982987839.webm [View same] [iqdb] [saucenao] [google]
6880214

non-understandable garbage is the best way to communicate these ideas. That is why non-understandable garbage was invented in the first place. To be more descriptive and contextual so as to guide your interpretation of the concept in the right direction.

The answer:
It was easier for an earlier compilers/syntax checkers/parsers to distinguish variables by looking looking for characters to indicate the start of an expression.

>> No.6880251

>>6880214
Bullshit, writing a parser for to check for numbers is not "harder" than for characters. It's a conceptual choice to keep things simple, restricting variables' syntax not to overlap with anything else than comes into computations.