ys2843 commented on a change in pull request #18992: URL: https://github.com/apache/incubator-mxnet/pull/18992#discussion_r475335574
########## File path: docs/static_site/src/pages/community/code_guide.md ########## @@ -0,0 +1,77 @@ +--- +layout: page +title: Code Guide and Tips +subtitle: Tips in MXNet codebase for reviewers and contributors. +action: Contribute +action_url: /community/index +permalink: /community/code_guide +--- +<!--- Licensed to the Apache Software Foundation (ASF) under one --> +<!--- or more contributor license agreements. See the NOTICE file --> +<!--- distributed with this work for additional information --> +<!--- regarding copyright ownership. The ASF licenses this file --> +<!--- to you under the Apache License, Version 2.0 (the --> +<!--- "License"); you may not use this file except in compliance --> +<!--- with the License. You may obtain a copy of the License at --> + +<!--- http://www.apache.org/licenses/LICENSE-2.0 --> + +<!--- Unless required by applicable law or agreed to in writing, --> +<!--- software distributed under the License is distributed on an --> +<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY --> +<!--- KIND, either express or implied. See the License for the --> +<!--- specific language governing permissions and limitations --> +<!--- under the License. --> + +Code Guide and Tips +=================== + +This is a document used to record tips in MXNet codebase for reviewers and +contributors. Most of them are summarized through lessons during the +contributing and process. + +C++ Code Styles +--------------- + +- Use the [Google C/C++ style](https://google.github.io/styleguide/cppguide.html). +- The public facing functions are documented in [doxygen](https://www.doxygen.nl/manual/docblocks.html) format. +- Favor concrete type declaration over `auto` as long as it is short. +- Favor passing by const reference (e.g. `const Expr&`) over passing + by value. Except when the function consumes the value by copy + constructor or move, pass by value is better than pass by const + reference in such cases. +- Favor `const` member function when possible. +- Use [RAII](https://en.cppreference.com/w/cpp/language/raii) to manage resources, including smart pointers like shared_ptr and unique_ptr as well as allocating in constructors and deallocating in destructors. Avoid explicit calls to new and delete when possible. Use make_shared and make_unique instead. + +We use [`cpplint`](https://github.com/cpplint/cpplint) to enforce the code style. Because +different version of `cpplint` might change by its version, it is +recommended to use the same version of the `cpplint` as the master. +You can also use the following command via docker. + +``` {.bash} +ci/build.py -R --docker-registry mxnetci --platform ubuntu_cpu --docker-build-retries 3 --shm-size 500m /work/runtime_functions.sh sanity_cpp Review comment: Not super important, but if wrap this code block inside `{% highlight bash %}` and `{% endhighlight %}`, the clipboard feature will be added in the web page and user can click the button to copy, same for all languages. See [here](https://github.com/apache/incubator-mxnet/blob/master/docs/static_site/src/_includes/get_started/linux/python/cpu/pip.md) for usage. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
