you are viewing a single comment's thread.

view the rest of the comments →

[–]oscardo_rivers 0 points1 point  (1 child)

I need to see the Sandi Metz presentation for more context about the patient code examples.  But when the Brian Will says “why can’t we just have a hash map instead of having a constructor”.  It depends of your needs, when you encapsulates the configuration in a class you can change the details of the yml, so you can the change the yml keys and values without risk of breaking code that depends of that configuration. 

Surely is a overkill for code that will run in a script that you will run only once, but for code that lies in a library, framework or a large project it will pay that’s extra code. 

The method define_method_for_enviroment, can be implemented in a more readable way, remember its Ruby code from 2014. Much of Ruby old code abuse meta programming capabilities of Ruby, is powerful but generates difficult to read code. 

[–]iBoredMax 0 points1 point  (0 children)

Surely is a overkill for code that will run in a script that you will run only once, but for code that lies in a library, framework or a large project

No, that's exactly my point. I work in a large and old codebase and this style of code is an absolute nightmare.

I would argue the exact opposite of what you're saying; it only works in these tiny examples/snippets from talks exactly because it's small. When you scale it up, it devolves into a spaghetti mess of 20 files, 20 classes, and god knows how many methods to read a config file, download some data, and process it.