kou commented on code in PR #46031: URL: https://github.com/apache/arrow/pull/46031#discussion_r2057611991
########## cpp/src/arrow/record_batch_test.cc: ########## @@ -1215,6 +1244,21 @@ Result<std::shared_ptr<Array>> MakeStatisticsArray( std::move(statistics_array)}; return std::make_shared<StructArray>(struct_type, n_columns, struct_arrays); } + +std::shared_ptr<Array> GenerateString( + const std::shared_ptr<::arrow::DataType>& data_type) { + if (data_type->id() == Type::FIXED_SIZE_BINARY) { + auto byte_width = data_type->byte_width(); + auto a = std::string(byte_width, 'a'); + auto b = std::string(byte_width, 'b'); + auto c = std::string(byte_width, 'c'); + std::stringstream ss; + ss << R"([")" << a << R"(",")" << b << R"(",")" << c << R"("])"; + return ArrayFromJSON(data_type, ss.str()); + } + return ArrayFromJSON(data_type, R"(["a","b","c"])"); Review Comment: This is for readability not performance. In general, the early return style is used for the following propose: ```cpp if (exception_case) { // exception case return; } // normal case ``` With the style, we can focus on important codes quickly. For example, if we're interested in an exception case, we can only focus on `if (exception_case) {...}`. If we're interested in the normal case, we can ignore all `if (...) {return}` codes. In this case, all cases (`data_type->id() == Type::FIXED_SIZE_BINARY` and `data_type->id() != Type::FIXED_SIZE_BINARY` cases) are normal cases. So we can represent it by the following style not the early return style: ```cpp if (condition) { // normal case1 return; } else { // normal case2 return; } ``` This is a blog post that was written by my colleague: https://www-clear--code-com.translate.goog/blog/2012/3/28/best-practice-how-to-use-if-and-return.html?_x_tr_sl=ja&_x_tr_tl=en&_x_tr_hl=ja&_x_tr_pto=wapp This may help you. -- 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. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org