Name: Anonymous 2011-11-04 14:27
Summary: My coworker tells me not to use reflection because it makes code hard to understand; I disagree.
Research: A precursory google search of 'programming is reflection bad' I find that a lot is written about how there can be a large performance impact (and, stupid me, I realized that I was making one of the mistakes listed in some post, but someone listed a simple performance enhancement so I can fix that.) A few people complain about debugging and IDEs not being able to work well with it.
However, and this is the foundation of why I think the whole entire thing is stupid: I am working on a WPF application (C# XML based paradigm for GUI applications) that *USES* reflection to create the structures dynamically anyways! Furthermore, after I built an application with dynamic binding of model objects to view objects, and showing how much cleaner the code looks (no manually creating tables, not having to write complicated validation logic and little workarounds to translate input in the front end to the model object, significantly less lines of code, and less buggy code due to not hand making ideas built right into the libraries like modal windows, data translation, etc.), my coworkers took it as a model for how all WPF applications should be written from then on.
But this is all *GASP* done through the magic of reflection. I do not have a single line of code that I have written that includes "System.Reflection." but obviously the MS Libraries are reflecting to, for example, understand how to make a table with a column for each property of a model object, or knowing that number fields should automatically default to having validation that checks that a number has no invalid characters, and fits inside range int.min and int.max...
But, now, because it uses reflection to create the UI, all I have access to in a datagrid is a string containing the name of the property that that column is bound to. The only way (I can think of,) using this information to get a collection of all the values in that given column is to get a delegate of the getter method for that property and invoke it through reflection. Either that, or write a method for every column of every single attribute of every single object that will ever be used.
So... reading that,
1) is there actually a way to get a collection based off a column without reflection (if someone is familiar with WPF/c#, I have access to an IEnumerable<foo> from which the table is constructed, I was thinking maybe something in Linq might work, or some kinda lambda expression, except, like I said before, the only thing I have access to is a string of the property's name)
2) Is reflection really the Anti-Christ?
Research: A precursory google search of 'programming is reflection bad' I find that a lot is written about how there can be a large performance impact (and, stupid me, I realized that I was making one of the mistakes listed in some post, but someone listed a simple performance enhancement so I can fix that.) A few people complain about debugging and IDEs not being able to work well with it.
However, and this is the foundation of why I think the whole entire thing is stupid: I am working on a WPF application (C# XML based paradigm for GUI applications) that *USES* reflection to create the structures dynamically anyways! Furthermore, after I built an application with dynamic binding of model objects to view objects, and showing how much cleaner the code looks (no manually creating tables, not having to write complicated validation logic and little workarounds to translate input in the front end to the model object, significantly less lines of code, and less buggy code due to not hand making ideas built right into the libraries like modal windows, data translation, etc.), my coworkers took it as a model for how all WPF applications should be written from then on.
But this is all *GASP* done through the magic of reflection. I do not have a single line of code that I have written that includes "System.Reflection." but obviously the MS Libraries are reflecting to, for example, understand how to make a table with a column for each property of a model object, or knowing that number fields should automatically default to having validation that checks that a number has no invalid characters, and fits inside range int.min and int.max...
But, now, because it uses reflection to create the UI, all I have access to in a datagrid is a string containing the name of the property that that column is bound to. The only way (I can think of,) using this information to get a collection of all the values in that given column is to get a delegate of the getter method for that property and invoke it through reflection. Either that, or write a method for every column of every single attribute of every single object that will ever be used.
So... reading that,
1) is there actually a way to get a collection based off a column without reflection (if someone is familiar with WPF/c#, I have access to an IEnumerable<foo> from which the table is constructed, I was thinking maybe something in Linq might work, or some kinda lambda expression, except, like I said before, the only thing I have access to is a string of the property's name)
2) Is reflection really the Anti-Christ?