Should reflection be part of design?

I’m currently designing a somewhat large program that will involve the simulation of math/physics models and collection of data (I have not implemented any code yet). One of the main problems I’m facing is how to pass data around easily without having to have multiple copies of data (that may potentially be outdated and redundant).

Initially I was thinking of having the model objects each implement a function that returns a data structure containing copies of their data, then collecting all those data structures together and passing that around. This would involve a lot of copying however, and the data wouldn’t be mapped to the actual object anymore. (The data structure idea I had would involve using a trie so that the data is nice and hierarchical and lookups can be done easily by string)

So now I was thinking that instead of designing the program to use a data structure to pass data around, the program would simply pass the model, and then data can be extracted with reflection. This would pretty much avoid any redundancy and the data passed will always be up to date.

The problem is that I also need this program to be fast (it has soft realtime constraints), and I’m not sure about the performance impact of reflection. And reflection does seem kinda ugly. But at the same time, people say it’s never a good idea to optimize early, so I’m on the fence here.

So should I design the program to use reflection, and if so, how liberally? Or should I try to avoid reflection as much as I can during design?

8

Without an example, this question is a little bit too broad for my taste, so best answer I can give you is a very generic one. IMHO what you need is a more functional approach:

  • model your data using immutable objects. For immutable objects, there is no need to create any copies, they can be passed by reference without the risk of creating any side effects.

  • using only immutable data structures forces you to organize your program in a way where each function which could deliver potentially out-of-date results is called “on the fly” at the point in time when the data is needed, not earlier.

  • instead of solving problems imperatively by “calculating some data x and y, store it somewhere, reuse parts of it later to calculate a, b, and c”, learn how to model problems in a functional way (write functions for calculating a, b, and c based on the functions for calculating x and y).

  • model your data flow, maybe graphically – make sure you know exactly which components in your system get data from which other components, and where the “asynchronous changes” are introduced. I recommend Flow Design for this.

  • reflection is most probably the wrong choice for your problem (not for performance reasons, but for actually introducing more problems than it will solve for you)

EDIT: a really good example of a physical model which seems similar to your problem is the digital circuit simulator in “Structure and Interpretation of Computer programs”. And this example is indeed based on mutable data (though its also using functional elements). Maybe this approach maybe a blueprint for yours.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Should reflection be part of design?

I’m currently designing a somewhat large program that will involve the simulation of math/physics models and collection of data (I have not implemented any code yet). One of the main problems I’m facing is how to pass data around easily without having to have multiple copies of data (that may potentially be outdated and redundant).

Initially I was thinking of having the model objects each implement a function that returns a data structure containing copies of their data, then collecting all those data structures together and passing that around. This would involve a lot of copying however, and the data wouldn’t be mapped to the actual object anymore. (The data structure idea I had would involve using a trie so that the data is nice and hierarchical and lookups can be done easily by string)

So now I was thinking that instead of designing the program to use a data structure to pass data around, the program would simply pass the model, and then data can be extracted with reflection. This would pretty much avoid any redundancy and the data passed will always be up to date.

The problem is that I also need this program to be fast (it has soft realtime constraints), and I’m not sure about the performance impact of reflection. And reflection does seem kinda ugly. But at the same time, people say it’s never a good idea to optimize early, so I’m on the fence here.

So should I design the program to use reflection, and if so, how liberally? Or should I try to avoid reflection as much as I can during design?

8

Without an example, this question is a little bit too broad for my taste, so best answer I can give you is a very generic one. IMHO what you need is a more functional approach:

  • model your data using immutable objects. For immutable objects, there is no need to create any copies, they can be passed by reference without the risk of creating any side effects.

  • using only immutable data structures forces you to organize your program in a way where each function which could deliver potentially out-of-date results is called “on the fly” at the point in time when the data is needed, not earlier.

  • instead of solving problems imperatively by “calculating some data x and y, store it somewhere, reuse parts of it later to calculate a, b, and c”, learn how to model problems in a functional way (write functions for calculating a, b, and c based on the functions for calculating x and y).

  • model your data flow, maybe graphically – make sure you know exactly which components in your system get data from which other components, and where the “asynchronous changes” are introduced. I recommend Flow Design for this.

  • reflection is most probably the wrong choice for your problem (not for performance reasons, but for actually introducing more problems than it will solve for you)

EDIT: a really good example of a physical model which seems similar to your problem is the digital circuit simulator in “Structure and Interpretation of Computer programs”. And this example is indeed based on mutable data (though its also using functional elements). Maybe this approach maybe a blueprint for yours.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật