Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6882925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:18:57+00:00 2026-05-27T05:18:57+00:00

I am not sure if this question is not silly, but I really want

  • 0

I am not sure if this question is not silly, but I really want to get some opinions. I will directly provide an example of what I am currently working on.

I am using HtmlAgilityPack to parse some HTML pages.

I have a method in my code which receives the HtmlDocument and does the parsing. Currently, the code is like this :

private void OperateOnDocument (HtmlDocument pageSource)
{
  HtmlNode node;
  node = pageSource.DocumentNode.SelectSingleNode (/*XPath to find a node */);
  // do some operation on the extracted HtmlNode.

  node = pageSource.DocumentNode.SelectSingleNode (/* XPath to find another node */);
  // do some operation on the newly acquired node.

  // Likewise, reuse the same reference variable "node" to extract all the nodes and operate on them.
}

Pros : A single reference variable is used to operate on all the nodes.

Cons : You dont know what node an individual parsing extracts, as all the extracted nodes have different value and purpose (One node may contain rate, another may contain city name.)

Another way of doing this is :

private void OperateOnDocument (HtmlDocument pageSource)
{      
  HtmlNode idNode = pageSource.DocumentNode.SelectSingleNode (/*XPath to find the node containing id*/);
  // parse the text and store it in string.

  HtmlNode rateNode = pageSource.DocumentNode.SelectSingleNode (/* XPath to find the node containing the rates */);
  // parse the text into decimal.

  // Likewise, use separte meaningful names of reference variables to extract all the nodes and operate on them.
}

Pros : Separate meaningful name to each node being operated.

Cons : At times, the number of operations may mount to 10; hence, 10 different reference variables.

So, my question is if the second method is really worth doing? Or it can prove a bit expensive because of so many reference variables? How expensive are such variables in .Net? or any other language/framework in general?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:18:59+00:00Added an answer on May 27, 2026 at 5:18 am

    If you’re worried about the cost of doing something, then measure it. If you can’t measure a difference, then the difference can not possibly matter (if it mattered, you’d be able to measure it).

    To answer your more specific question, a variable does not have any intrinsic cost. Variables do not exist in the code that is actually executed on the CPU. They are a source-level construct, and the compiler is not obliged to create some kind of 1-to-1 mapping between source code variables and, say, push instructions executed, or registers used, or anything else. A single variable in your code can correspond to the use of several different registers (the compiler might choose to move it around from time to time), or several different variables might all end up sharing the same register because they’re never used at the same time.

    One of the many things a compiler does is determine the lifetime of a variable. When is it first used, and when is it last used? It doesn’t matter when you declared it, or when it goes out of scope.

    A transformation commonly used by compilers to put your code into a form more amenable to optimizations is to turn every assignment into a new, unique, variable, basically like in your second example. That’s how the compiler prefers to work with the code, because now it can see the dependencies clearly. In the first case, it looks as if the same variable has to exist throughout the function, and be reused for both operations. In the second case, we can easily see that they’re separate, independent, variables, and we can see that their lifetimes do not overlap (idNode is not used after the declaration of rateNode).

    Both versions will likely produce the exact same code, but the second version is closer to what optimizing compilers do to the code internally.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this question sounds a little silly, but I am not sure what
I'm not sure this question is appropriate here but I hope I could get
I'm not exactly sure whether or not this is a silly question, but I
This might be a silly question, but I'm not sure how to tackle the
Not sure if this is a silly question, but I just noticed this: public
I'm not sure if this is a silly question or not but I have
probably a silly question, but I'm not sure how to handle this 'correct'. I
this question might sound silly to some but i just had to make sure.
Apologies if this is a silly question, and I'm not even sure of the
I am not sure if this question is already answered. But here it goes:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.