Length of Variable Names and Performance Impacts

Posted on 2007-08-01
Last Modified: 2010-04-23
Hi, I've wondered this for quite some time, but never really got around to asking...

When we choose a variable's name, is there any type of performance impact depending on the length of that string?  For instance, would the variable "i" perform any better in memory than say, something like "str_My_Variable_Name_Which_I_Really_Like_And_Want_To_Use."  Clearly this is a gross exaggerations, but it's meant to illustrate my point.

Is there a rule of thumb for the length that a variable name should be kept?

Question by:Mr_Fulano
    LVL 81

    Assisted Solution

    by:zorvek (Kevin Jones)
    No performance impact at all. All it might do is slow the compiler down a wee little bit. The key to good names is readability.

    LVL 35

    Accepted Solution


    the reason why it should not slow anything down as when .net compiles into its intermediate language - it does not necessarily use the names that you actually put in to reference the data locations,

    becuase of this there may be a hit in the compiler - which is what kevin was referring to above - because there is more data to parse, but the end result should be the same.
    LVL 18

    Assisted Solution

    No need to think about this impact at all. It is so little an impact that if you start thinking so deep you can not do programming. Have variables which are defined with conventions and are immediately understood. So even if you have to use big names use them - as maintaining the project becomes very easy with good variable names.

    Author Comment

    Thanks for the information and for putting that to rest for me.

    Having said that, I increased the points  to 500 (Max) and awarded them in the following manner since you all helped.

    Zerveck - 150 ... he was first to answer
    Raynard7 - 250 .. he provided the best answer, because he gave a reason
    Sethi - 150 ... he provided good info as well

    Thanks to all!

    Author Comment

    Correction, Sethi was awarded 100 not 150... sorry for the miscalculation.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now