2

In the Ruby on Rails communication, it is often said that RoR is "convention over configuration".

Can you say for React / Redux / Flux and AngularJS, Angular2, they are also "convention over configuration"?


Some details: the reason is, engineers probably do things in quite standard, or convention ways, such as

// in index.js:

const createStoreWithMiddleware = applyMiddleware(ReduxPromise)(createStore);

<Provider store={createStoreWithMiddleware(reducers)}>
  <App />
</Provider>

// in the container file:

function mapStateToProps(state) {
  return {
    dataList: state.data
  }
}

export default connect(mapStateToProps)(DataList);

and you usually won't tweak or change these conventions. (I just hope no interviewers will ask me to recite these lines verbatim at interviews... as whether you memorize these lines, do they make you a better programmer? The concepts can be important, but how these lines are verbatim, what is so good about memorizing them?)

3
  • 1
    So how does your example relate to convention over configuration? The code you posted looks pretty explicit and not convention based to me. Apr 4, 2017 at 17:13
  • 1
    I'd say that uppercase tag = directive, lowercase tag = html counts as convention in React. Apr 4, 2017 at 17:15
  • that's because it is how it wires up the state to props, and the action creators to the props, and it is all conventions. Apr 4, 2017 at 19:14

1 Answer 1

1

No, you've misunderstood convention over configuration.

The idea of convention over configuration is that you should not have to explicitly configure the framework. Instead, conventions are automatically applied.

Take for example:

export default connect(mapStateToProps)(DataList);

React makes you explicitly include this code. If React followed convention over configuration, it would assume that you wanted to do this as soon as you defined a mapStateToProps function and automatically do it for you.

So the point isn't that there is a standard convention. Convention over configuration is when the convention is automatic, not explicit in code.

12
  • but will you write something other than export default connect(mapStateToProps)(DataList);? If you will not, what is the difference between it automatically add it for you, or you add it yourself? Apr 4, 2017 at 19:15
  • @太極者無極而生 your question doesn't make any sense. Surely you understand the difference between the computer doing something for you and you having to do it yourself. Apr 4, 2017 at 19:19
  • It doesn't automatically do it for you. In convention over configuration, it's not even needed, because it's implied
    – RMalke
    Apr 4, 2017 at 19:42
  • My main concern is "it is more of a convention" vs "freestyle". Whether the computer "automatically does it for you", is not of a main concern here. So maybe the name is not "convention over configuration" but "convention over free style programming". My focus is the "convention" part, not whether something is done "automatically". Apr 4, 2017 at 19:43
  • @RMalke, what's the difference between automatic and implied? Apr 4, 2017 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.