Click here to Skip to main content
15,887,267 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Reflection Optimization Pin
CDP180219-May-12 4:29
CDP180219-May-12 4:29 
GeneralRe: Reflection Optimization Pin
Mike Marynowski19-May-12 4:59
professionalMike Marynowski19-May-12 4:59 
GeneralRe: Reflection Optimization Pin
CDP180219-May-12 23:04
CDP180219-May-12 23:04 
GeneralRe: Reflection Optimization Pin
Brisingr Aerowing23-May-12 13:02
professionalBrisingr Aerowing23-May-12 13:02 
GeneralRe: Reflection Optimization Pin
CDP180223-May-12 21:31
CDP180223-May-12 21:31 
GeneralRe: Reflection Optimization Pin
Mike Marynowski19-May-12 5:03
professionalMike Marynowski19-May-12 5:03 
GeneralRe: Reflection Optimization Pin
BillW3319-May-12 6:57
professionalBillW3319-May-12 6:57 
GeneralRe: Reflection Optimization Pin
CDP180219-May-12 23:39
CDP180219-May-12 23:39 
That depends very much on your goals. This looks like you wanted to be able to assign any data to any object's property. In that case you would have to check wether the object in question really has the property you were looking for. I would expect something similar to this in the code that loads XAML markup and then creates object instances from it. It obviously must be able to assign values to any of an object's properties.

If that kind of general purpose use was not intended, then I would not call your little mistake a code horror. It can be changed and optimized easily enough. Personally, I would be more concerned about two things: Performance and type safety. Reflection is slow and can kill your code's performance if you use it carelessly all over the place. That's why I would like to have all of it hidden away in some class and separated from the rest of the application. Then performance issues can be tracked down easily to the places where those classes are used, should they arise.

Also, an application that passes around objects and relies on reflection in each and every method really would be a horror. All the checking that would be needed would be error prone and obfuscate the real intention behind each method. Debugging such a thing would be a pain and maintaining it a nightmare. That's why I again would prefer to use type safety to my advantage as much as possible and use reflection as sparingly as possible. And I would again hide it away in some class, so that the application stays clean of such generic and complicated code.
At least artificial intelligence already is superior to natural stupidity



GeneralRe: Reflection Optimization Pin
Mike Marynowski22-May-12 4:39
professionalMike Marynowski22-May-12 4:39 
GeneralRe: Reflection Optimization Pin
englebart22-May-12 3:00
professionalenglebart22-May-12 3:00 
GeneralRe: Reflection Optimization Pin
Mike Marynowski22-May-12 4:30
professionalMike Marynowski22-May-12 4:30 
GeneralRe: Reflection Optimization Pin
BrianPayne22-May-12 9:47
BrianPayne22-May-12 9:47 
GeneralRe: Reflection Optimization Pin
MiddleTommy22-May-12 3:44
MiddleTommy22-May-12 3:44 
Rantreturn value optimization PinPopular
Rahul Rajat Singh16-May-12 19:32
professionalRahul Rajat Singh16-May-12 19:32 
GeneralRe: return value optimization PinPopular
Ankush Bansal16-May-12 19:47
Ankush Bansal16-May-12 19:47 
GeneralRe: return value optimization Pin
Jochen Arndt16-May-12 21:09
professionalJochen Arndt16-May-12 21:09 
GeneralRe: return value optimization Pin
Ankush Bansal16-May-12 22:03
Ankush Bansal16-May-12 22:03 
GeneralRe: return value optimization Pin
BobJanova17-May-12 2:04
BobJanova17-May-12 2:04 
GeneralRe: return value optimization Pin
Vasily Tserekh21-May-12 8:01
Vasily Tserekh21-May-12 8:01 
GeneralRe: return value optimization Pin
BobJanova16-May-12 22:59
BobJanova16-May-12 22:59 
GeneralRe: return value optimization Pin
Mohibur Rashid17-May-12 0:12
professionalMohibur Rashid17-May-12 0:12 
GeneralRe: return value optimization Pin
BobJanova17-May-12 0:55
BobJanova17-May-12 0:55 
GeneralRe: return value optimization Pin
jsc4221-May-12 22:13
professionaljsc4221-May-12 22:13 
GeneralRe: return value optimization Pin
BobJanova21-May-12 23:51
BobJanova21-May-12 23:51 
GeneralRe: return value optimization Pin
jsc4222-May-12 0:11
professionaljsc4222-May-12 0:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.