問題
関数やメソッドをどこまで細かく分けるべきかわからない
例題
python
1def to_cleaned_text(text: str) -> str: 2 text = normalize_to_hankaku(text) 3 text = remove_parenthesis(text) 4 text = remove_blanks(text) 5 paragraphs = split_to_paragraphs(text) 6 paragraphs = remove_long_paragraphs(paragraphs) 7 text = ''.join(paragraphs) 8 return text 9 10def normalize_to_hankaku(text: str) -> str: 11 return unicodedata.normalize('NFKC', text) 12 13 14def remove_parenthesis(text: str) -> str: 15 return re.sub(r'(.+?)', '', text) 16 17 18def remove_blanks(text: str) -> str: 19 return re.sub(r' ', '', text) 20 21 22def split_to_paragraphs(text: str) -> List[str]: 23 return text.split('\n\n') 24 25 26def remove_long_paragraphs(paragraphs: List[str]) -> List[str]: 27 return list(filter(lambda p: not is_too_long(p), paragraphs)) 28 29def is_too_long(paragraph: str) -> bool: 30 return len(paragraph) >= _LENGTH_OF_TOO_LONG_PARAGRAPH
python
1def to_cleaned_text(text: str) -> str: 2 text = unicodedata.normalize('NFKC', text) 3 text = re.sub(r'(.+?)', '', text) 4 text = re.sub(r' ', '', text) 5 6 paragraphs = text.split('\n\n') 7 paragraphs = list(filter(lambda p: not len(p) >= _LENGTH_OF_TOO_LONG_PARAGRAPH, paragraphs)) 8 text = ''.join(paragraphs) 9 10 return text
上と下のどちらの実装の方が良いと思いますか?(「良い」の判断は個人の価値観で構いません)
外からはto_cleaned_text()
しか利用されないとしたら、どちらが良いと思いますか?
おまけ
よりよい分け方や気になる点がありましたら、指摘してください
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。