Comments (2)
So, the design of Bluge's Config was influenced heavily by dgraph's BadgerDB Options structure: https://github.com/dgraph-io/badger/blob/master/options.go#L26
I personally found it awkward when I first used BadgerDB, but over time I came to appreciate some of the way it worked. Here are some of the aspects of the design:
- Struct members are mostly public
- User-facing options/config settings named X have a corresponding WithX() function to set them
- All these methods return a copy of the struct itself (this allows method chaining)
- A default config is created using a function
- Constructors taking the config also pass by copy
Things I like about this:
- Constructor taking copy means we generally aren't worried about people changing the config after they passed it in because we own our copy (NOTE: still have to be careful with the contents of the config)
- Also because of the copies, it's possible to reuse config definitions (again, must be careful that contents are not pointers to things with state) This is highly desirable for expressing configuration in one (or few) places and reusing many places safely.
- The method chaining feels very convenient for expressing configuration:
cfg := DefaultConfig(path).
WithX(x).
WithY(y)
To me, this is very readable. Subjectively, it is more readable than if the methods were called SetX(x)
.
Things I don't like about this:
- Config object can be large, and passed by copy means static analysis (and soon possibly go tooling itself) may warn about copying large objects. I've made peace with this as config objects are typically worked with infrequently.
from bluge.
So, with that as the background, @steveyen, I'd like to better understand your criticism. As I understood it you don't like a method named WithX(x)
for an option named X
. Here are some alternatives:
- Method named SetX(x), option named X
- Method named X(x) option named x
My thinking is that SetX(x) is more standard in Go, but perhaps less readable in this case, because it implies you've mutated the object, when in fact, we're returning a new one.
My thinking is that X(x) is simply confusing because it lacks a verb describing the action.
Your thoughts?
from bluge.
Related Issues (20)
- panic while merging in unit test HOT 5
- ice v2 data race HOT 6
- Comparison with Bleve and others HOT 1
- index out of range when visiting stored fields HOT 4
- Date aggregations support HOT 2
- TestBug87 fails in custom implementation of search.Context HOT 2
- Question on aggregation bucket HOT 2
- makeslice len out of range
- Define logger interface
- multi index search
- Example of indexing a document with tags? HOT 1
- Difference between a NewTextField() and NewKeywordField()
- Sorting by ascending order of _score
- Indexing/Analyzing URLs, Email Addresses, etc?
- Indexing/Querying Emojis
- Is there a way to use this library more as a caching layer?
- Concurrently close writer panic HOT 1
- Pre-query for getting terms list.
- index out of range panic
- Memory Size or Limiting Memory usage
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bluge.