Jump to content

One letter variables

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
SimonBoris

SimonBoris

    Newbie

  • Members
  • Pip
  • 5 posts
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.

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
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
SimonBoris

SimonBoris

    Newbie

  • Members
  • Pip
  • 5 posts
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.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
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.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
DarkLordoftheMonkeys

DarkLordoftheMonkeys

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
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
SimonBoris

SimonBoris

    Newbie

  • Members
  • Pip
  • 5 posts
Thanx alot for your time, everybody.