I've written C# and the mantra coming from on high seems to be "never use reflection in production code". I have used it for test code, but never anything that runs in the wild. All the arguments seem reasonable, and there's always a way to do it by adding another layer of abstraction or design pattern or whatever.
Now I'm starting to write some serious Python code, I wonder if the same principle applies. It seems that python is designed with reflection in mind. Modules and classes store members in an easily accessible dictionary. Django's models' Meta classes, for example take strings to reference members.
I could write C#/Java in Python but I really don't want to. I still firmly believe in 'no reflection' for said languages. Is the Python way just fundamentally different?
IMO the reason for me about avoiding using reflection in production code is the fact than reflection could make code really harder to maintain and debug.
I think that the "no reflection in production code" is not correct in c#.
Reflection often allows the programmer to do things otherwise impossible.
I would say "no reflection for non-public members in production code" and "use reflection with care!" if not used correctly, you could lose performance. Used correctly could make you gain performance (just think about static reflection) Don't use reflection for massivly called code.
Python instead is a dynamic language. All concepts are different. The normality (and the correct way to do it) is using the techinques you are talking about.
Yes, in that aspect, Python developement is fundametally different.
Reflection in C#/Java refers to the ability of the runtime to know things about the code it's running, and to take decisions based on that information.
Since Python uses dynamic typing, any type discovery is delegated to the runtime and not the compile time, so basically that means, that any Python program must use reflection in order to work, only it's not called reflecting, it's called running the program :)
In addition, the Python philosophy embraces the dynamic nature of execution, so you should not hesitate to use it to your advantage.
P.S. While one should avoid using reflection in tight loops, and one should be aware that reflection is one or two orders of magnitude slower, one should not be afraid to use it when it's the right tool for the job.
As a dynamic language Python is fundamentally different than statically typed languages, so everything is reflection in it :-) Also never use reflection in production code (for static languages) seems a bit extreme to me.
Reflection is very advanced and powerfull technology. But it's slow. You can use reflection, but not to often. So CLR developers added one more cool type to .NET 4.0 - dynamic type. I strongly recommend you to refer to some documents or books for more info. F.e. CLR via C#.
CLR via C#: