gpt4 book ai didi

java - for-loop + Arrow Anti Pattern VS for-loop + continue

转载 作者:行者123 更新时间:2023-11-30 06:12:33 25 4
gpt4 key购买 nike

<分区>

你觉得下面这段代码(for-loop + continue)

for (Identity fileIdentity : fileIdentities) {
totalFileCount++;
if (!forceTheStatus(params, fileIdentity))
continue;
updatedFileCount++;
if (!params.shouldUpdateLinkedEntity())
continue;
Optional<Identity> batchIdentity = getLinkedBatchIdentity(fileIdentity);
if (!batchIdentity.isPresent())
continue;
totalBatchCount++;
if (!getRemittanceProcessor().forceTheStatus(params, batchIdentity.get()))
continue;
updatedBatchCount++;
}

比这个更好(for-loop + Arrow Anti Pattern)?为什么?

for (Identity fileIdentity : fileIdentities) {
totalFileCount++;
if (forceTheStatus(params, fileIdentity)) {
updatedFileCount++;
if (params.shouldUpdateLinkedEntity()) {
Optional<Identity> batchIdentity = getLinkedBatchIdentity(fileIdentity);
if (batchIdentity.isPresent()) {
totalBatchCount++;
if (getRemittanceProcessor().forceTheStatus(params, batchIdentity.get()))
updatedBatchCount++;
}
}
}
}

对我来说,continue 的解决方案看起来更难理解,但另一方面我们有一个反模式 :(

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com