|
此文章由 DDD888 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 DDD888 所有!转贴必须注明作者、出处和本声明,并保持内容完整
本帖最后由 DDD888 于 2022-4-21 07:02 编辑
算法赚大钱啦,例如golang内存释放的算法,c++依赖程序员释放内存,csharp, java, golang自动释放内存,结果来了rust language的内存管理更优秀,导致程序维护简单,效率和c++差不多或更好,显然算法及其重要啦
题外话,我工作中曾见过同事在一个文件里写几万行代码,一个函数占用屏幕几页啦,我写的项目,我力求一个函数尽量短,最好是没有代码,一般函数不会超过一个版面,即少于20行代码啦,一个源文件含一个函数啦,当然啦我写的代码不是CRUD的代码啦
附段我写的rust language代码啦
use crate::client_error;
use std::fs;
use std::path: athBuf;
use log::info;
use crate::get_last_folder::get_last_folder;
use crate::remove_double_quote::remove_double_quote;
use std::collections::HashMap;
use crate::get_file_extension::get_file_extension;
use crate::loop_folder::loop_folder;
pub fn handle_item(
ignore_dictionary: &HashMap<String, bool>,
delete_file_extenions_dictionary: &HashMap<String, bool>,
path: PathBuf,
) -> client_error::Result<()> {
let mut string_path = format!("{:?}", path);
string_path = remove_double_quote(&string_path);
let metadata = fs::metadata(&path)?;
if metadata.is_dir() {
let folder_name = get_last_folder(&string_path);
if ignore_dictionary.contains_key(&folder_name) {
return Ok(());
}
return loop_folder(&path, ignore_dictionary, delete_file_extenions_dictionary);
}
if !metadata.is_file() {
return Ok(());
}
let extension_string: String = get_file_extension(&path);
if extension_string == "" {
return Ok(());
}
if !delete_file_extenions_dictionary.contains_key(&extension_string) {
return Ok(());
}
info!(
"filename: {:?}",
path.file_name().ok_or("No filename".to_string())?
);
fs::remove_file(path).expect("File delete failed");
return Ok(());
}
|
|