Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Using Attributes

Using Attributes

Scheduled Pinned Locked Moved The Lounge
questioncsharpdesignperformancetutorial
24 Posts 23 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Richard Blythe

    I have rarely used attributes because they are obtained by reflection. (Performance hit) I have always design my apps not to depend on reflection. Here's the question: Are attributes an important part your applications? If so, give us a (good) example of your attribute implementation. (.Net or custom)

    The mind is like a parachute. It doesn’t work unless it’s open.

    P Offline
    P Offline
    Patrick Fox
    wrote on last edited by
    #21

    I use attributes a lot, I think they are amazing. They allow you to differentiate objects with metadata. This allows me to write reflection heavy code that checks properties for their attributes to decide what to do with them. I can often get away with decorating some properties with attributes as opposed to going in and writing code for certain object's properties. I can introduce a new object and it will behave the way I want without having to change any business logic. Performance should always be a concern, but only when it becomes obvious. Avoiding attributes because their performance is slower than just writing code is premature optimization. You should only reconsider use of attributes when it becomes apparent that the performance is not adequate, this applies to all situations where performance is a concern. In my experience, use of attributes leads to increased productivity. To give an example, imagine you are writing a plugin based application where certain plugin objects depend on others to be loaded first. The host application is dumb, it just loads plugins, it doesn't know anything about them. You can create a dependency attribute so that the plugin objects could tell the host that it depends on this other plugin being loaded first. The host could then sort the plugins based on dependencies before initializing them. If the host doesn't find a plugin, it could show a message that plugin X requires plugin Y, which wasn't found. Or you could blindly load plugin X and get some confusing error message like a null reference exception.

    1 Reply Last reply
    0
    • R Richard Blythe

      I have rarely used attributes because they are obtained by reflection. (Performance hit) I have always design my apps not to depend on reflection. Here's the question: Are attributes an important part your applications? If so, give us a (good) example of your attribute implementation. (.Net or custom)

      The mind is like a parachute. It doesn’t work unless it’s open.

      J Offline
      J Offline
      Jason Christian
      wrote on last edited by
      #22

      If you avoid them only because there is a "performance hit" then you are missing a very useful tool. To avoid them because of a performance hit that may or may not matter in the context of application is a mistake - use your brain and evaluate the situation to determine if the performance matters - and as other suggested you can cache the results of the attribute lookup or engage other techniques to mitigate the performance hit. If you are using attributes to do things in the UI for instance, the performance hit can be less than a human's ability to respond to stimulus anyway - so will never be noticed by a user.

      1 Reply Last reply
      0
      • R Richard Blythe

        I have rarely used attributes because they are obtained by reflection. (Performance hit) I have always design my apps not to depend on reflection. Here's the question: Are attributes an important part your applications? If so, give us a (good) example of your attribute implementation. (.Net or custom)

        The mind is like a parachute. It doesn’t work unless it’s open.

        F Offline
        F Offline
        frattaro
        wrote on last edited by
        #23

        Richard Blythe wrote:

        reflection. (Performance hit)

        I'm writing the third version of my own CMS. I don't use attributes, but I do use reflection to load third-party dll's on every page load, in case they want to run some analytics code, or run extra authentication/authorization stuff. I have yet to complete it, but I don't expect the performance hit to be bad. We'll see I guess.

        1 Reply Last reply
        0
        • R Richard Blythe

          I have rarely used attributes because they are obtained by reflection. (Performance hit) I have always design my apps not to depend on reflection. Here's the question: Are attributes an important part your applications? If so, give us a (good) example of your attribute implementation. (.Net or custom)

          The mind is like a parachute. It doesn’t work unless it’s open.

          S Offline
          S Offline
          Sandesh M Patil
          wrote on last edited by
          #24

          :) :) :) :) :) :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups