append 换行_代码风格:答应我,让括号换行吧!!
生活随笔
收集整理的這篇文章主要介紹了
append 换行_代码风格:答应我,让括号换行吧!!
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
不換行是不可能不換行的,這一輩我都要換行!
求你了,讓你的括號另外再起一行吧!
就問你,這樣的java看著舒不舒服!?
public static double dot(Map<Integer,Double> vecA,Map<Integer,Double> vecB) {double normA = 0;double normB = 0;double dot = 0;for(Entry<Integer,Double> entry : vecA.entrySet()){normA += Math.pow(entry.getValue(),2);if( vecB.containskey(entry.getKey()) )dot += entry.getValue() * vecB.get(entry.getKey())}if(dot == 0)return 0;normA = Math.pow(normA,0.5);for(Entry<Integer,Double> entry : vecB.entrySet())normB += Math.pow(entry.getValue(),2);normB = Math.pow(normB,0.5);return dot /(normA * normB) }還有scala也可以,就是看著有點奇怪,不過我還是選擇這種方式
def dot(vecA:Map[Integer,Double],vecB:Map[Integer,Double]):Double= {var normA = 0d;val dot = vecA.map(x =>{normA += x*xif(vecB.contains(x._1)) x._2 * vecB(x._1) else 0}).reduce(_+_)if(dot == 0)0else{normA = Math.pow(normA,0.5)val normB = Math.pow(vecB.map(x => x*x).reduce(_+_),0.5) dot/(normA * normB)} }但是我在團隊中就顯得很另類,一般需要合作的時候,我不動別人的代碼,別人也不動我的代碼......
其實這樣的另起一行,會顯得代碼行數變多,但是這樣潛意識下也會迫使你不斷優化,復用,重構自己的結構使得程序顯得擴展性很強,減少某個函數的總體代碼行數,比如你看java se的代碼方法很少有占據整個屏幕的,這是我覺得很長的java se 方法的代碼,ThreadLocal的部分代碼:
大多數的java se方法行數一般也下面這么多了
我是一定要換行的,這杯輩子都要還行的.....
什么?這你兩種都不想要..............
那么.......你這樣只能這樣了...........
def training_gbdt(df_data,labels):from sklearn.metrics import roc_auc_scorecol_processor = []col_processor.append(('contract_type_vec', OneHotEncoder(categories='auto'), ['text_contract_type']))col_processor.append(('case_vec', OneHotEncoder(categories='auto'), ['col_complainttype_cust_case_case']))col_processor.append( ('city_vec', OneHotEncoder(categories='auto'), ['city']) )col_processor.append(('edu_vec', OneHotEncoder(categories='auto'), ['edu']))col_processor.append(('sex_vec', OneHotEncoder(categories='auto'), ['sex_client']))col_transformer = ColumnTransformer(col_processor, remainder='passthrough')param_estimators = [20,40,80,100]_labels = [1 if label == "neg" else 0 for label in labels]train_X, test_X, train_y, test_y = train_test_split(df_data, _labels, test_size=0.2)max_auc = 0.5best_model = Nonefor pe in param_estimators:gbdt = GradientBoostingClassifier(n_estimators=pe)estimators = [('col_trans', col_transformer), ('gbdt', gbdt)]pipe = Pipeline(estimators)pipe.fit(train_X,train_y)pred_y = pipe.predict(test_X)auc_score = roc_auc_score(test_y, pred_y)if auc_score > max_auc:max_auc = auc_scorebest_model = pipejoblib.dump(best_model ,"../model/cbrc_gbdt.pkl")print("saving gbdt done...........")以上當然是開玩笑的拉
總結
以上是生活随笔為你收集整理的append 换行_代码风格:答应我,让括号换行吧!!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python关键字爬取文章_【Pytho
- 下一篇: bitnamigitlab_Bitnam