facebookresearch / beanmachine

A library that allows for inference on probabilistic models
https://beanmachine.org/
MIT License
264 stars 49 forks source link

minibmg: reduce large cyclomatic complexity by using a table of functions. #1813

Closed gafter closed 1 year ago

gafter commented 1 year ago

Summary: We used to have a huge switch statement switching on the operator string read from json in order to read a graph from json source. However, this approach had two problems: (1) It used a custom string literal, which is hashed to an integer. See the related task for issues with that. (2) That switch had large cyclomatic complexity - it would have been hard to read and maintain.

We replace all that with a table of functions indexed by string.

Differential Revision: D41041374

facebook-github-bot commented 1 year ago

This pull request was exported from Phabricator. Differential Revision: D41041374

facebook-github-bot commented 1 year ago

This pull request has been merged in facebookresearch/beanmachine@376055762ef8d0cdc31a5a02b1d84be7ef59a9a2.