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

  • Home
  • SEARCH
  • 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 89931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:47:38+00:00 2026-05-10T22:47:38+00:00

Edit: Warning – I now realize that the following technique is generally regarded as

  • 0

Edit: Warning – I now realize that the following technique is generally regarded as a bad idea because it creates hidden dependencies for the sake of looking neat.


I recently discovered that you can use the StackTrace to infer information about the caller of a method.

This enables you to create a seemingly ‘cool’ API whereby you simply invoke a method without bothering to pass any explicit parameters to it, and the method works out what to do based on the StackTrace.

Is this a bad thing to do, and if so, why?

Example:

public class Cache {   public Object CheckCache()   {     Object valueToReturn = null;     string key = GenerateCacheKeyFromMethodPrototype(new StackTrace().GetFrame(1).GetMethod()); //frame 1 contains caller     if(key is in cache) valueToReturn = itemFromCache;      return valueToReturn;      } }  public class Foo {    private static Cache cache = new Cache();    public Blah MethodFoo(param1, param2...)   {     Blah valueToReturn = cache.CheckCache(); //seems cool!     if(valueToReturn == null)     {       valueToReturn = result of some calculation;       //populate cache     }      return valueToReturn;   } } 

I’m sure there are errors in the above pseudocode, but you get my drift.


Edit: thanks for everyone’s responses.

  • 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. 2026-05-10T22:47:39+00:00Added an answer on May 10, 2026 at 10:47 pm

    There’s two reasons why not to do this:

    • It’s slow
    • It’s creates a brittle solution.

    If you wanted to do this, you’d better off using a tool that supports Aspect Oriented Programming, such as Castle’s Dynamic Proxy.

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

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer As the support is not there yet for the feature,… May 11, 2026 at 11:29 am
  • added an answer You might want to do that if the class has… May 11, 2026 at 11:29 am
  • added an answer Use the JDK's swap method The JDK's Collections class contains… May 11, 2026 at 11:29 am

Related Questions

Edit: Warning - I now realize that the following technique is generally regarded as
Is it possible to suppress warnings in Eclipse for JDK1.4 project? EDIT: Longer version.
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
EDIT: This question is more about language engineering than C++ itself. I used C++
EDIT What small things which are too easy to overlook do I need to
Edit : Solved, there was a trigger with a loop on the table (read
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.