Hi everybody, my name is Simon and i am new to this forum.
I am currently coding in javascript, and i really enjoy using one letter variable in local function scope.
In term of optimization or compiler or interpreter, does it make any difference if a variable name is big or not?
What whould be the difference between:
var s = 'John';
and
var uncleFirstName = 'john';
Does it take more memory?
I think that javascript runtime compiler and interpreter are in C++ or Java,
and cannot find any documentation regarding my questions. :confused:
If anyone have a clue, please share...
Thanx alot.
Simon.
One letter variables
Started by SimonBoris, Nov 11 2009 08:49 PM
5 replies to this topic
#1
Posted 11 November 2009 - 08:49 PM
|
|
|
#2
Guest_Jordan_*
Posted 12 November 2009 - 06:30 AM
Guest_Jordan_*
In JavaScript, a one letter variable uses less space which means the user will need to download less from your website so a 1 letter variable is better. However, it is hard to read. There are obfusicators/compressors out there for JavaScript that will take large/better named variables and reduce them down to one letter variables (among other things). It would probably be best for you to code using meaningful names and then use one of these compressors before adding it to your site.
#3
Posted 12 November 2009 - 07:40 AM
I know what it does in javascript...
My questions is rather about how it will be handled by the Javascript compiler and interpreter that are loaded into the browser.
The javascript compiler and interpreter are in C or Java, and was wondering if the length of a name variable makes a difference in term of memory usage.
My goal is to optimize my code so the Compiler and the interpreter can execute it faster and use less ressources.
I cannot find such documentation(on optimization for compiler and interpreter) so i though i could ask people that code in C or Java.
So for a compiler/interpreter (in C or Java or else), does it take less memory if a variable name is short or big?
Thanx.
My questions is rather about how it will be handled by the Javascript compiler and interpreter that are loaded into the browser.
The javascript compiler and interpreter are in C or Java, and was wondering if the length of a name variable makes a difference in term of memory usage.
My goal is to optimize my code so the Compiler and the interpreter can execute it faster and use less ressources.
I cannot find such documentation(on optimization for compiler and interpreter) so i though i could ask people that code in C or Java.
So for a compiler/interpreter (in C or Java or else), does it take less memory if a variable name is short or big?
Thanx.
#4
Posted 12 November 2009 - 08:36 AM
The problem is there are several different Javascript interpreters/compilers out there, and each one potentially handles this differently. In general, however, I would expect there to be a symbol table that will be larger with a larger name. Result: it will have a very slight hit on RAM, but not performance if you use a larger name.
#5
Posted 12 November 2009 - 12:21 PM
Yes, I think it would take more memory, but the difference between a one byte character and 10 bytes of characters in negligible. Most programmers use multicharacter names for most variables and one-letter names for increment variables used inside for and while loops.
Life's too short to be cool. Be a nerd.
#6
Posted 12 November 2009 - 04:57 PM
Thanx alot for your time, everybody.


Sign In
Create Account

Back to top









