聊一聊后端语言的差异和特性差异

假如有一个需求要实现一个统计的需求,可能不同的人会有不同的实现方式,最为掌握一门编程语言和掌握多门编程语言,以及一年工作经验的编程人员和多年的编程人员的实现思路肯定是不一样的。

例子一:要实现A表中某个条件下,a字段、b字段、c字段对应不同数值的出现次数

java的compute函数能统计map中出现的次数

java 复制代码
for (int i = 0; i < hello.length(); i++) {
            char key = hello.charAt(i);
            map.compute(key, (k, v) -> {
                if (Objects.isNull(v)) {
                    v = 1;
                } else {
                    v += 1;
                }
                return v;
            });
        }

使用mysql直接进行统计:

sql 复制代码
select sum(case when a="a1" then cot end) a1,sum(case when a="a2" then cot end) a2,sum(case when a="a3" then cot end) a3,
sum(case when b="b1" then cot end) b1,sum(case when b="b2" then cot end) b2,sum(case when b="b3" then cot end) b3,
sum(case when c="c1" then cot end) c1,sum(case when c="c2" then cot end) c2,sum(case when c="c3" then cot end) c3 from (
select a,b,c from table group by a,b,c
) t

使用python

python 复制代码
# Python3 code to demonstrate 
# occurrence frequency using 
# lambda + sum() + map()
  
# initializing string 
test_str = "GeeksforGeeks"
  
# using lambda + sum() + map() to get count 
# counting e 
count = sum(map(lambda x : 1 if 'e' in x else 0, test_str))
  
# printing result 
print ("Count of e in GeeksforGeeks is : "
                            +  str(count))

总结:对于同一个需求可能需要考虑基于现有编程语言的特性,已有手脚架等,在对扩展和性能以及编程规范等等进行达到最优的实现

相关推荐
阿龍1787几秒前
媒体文件问题检测脚本(一)(python+ffmpeg)
开发语言·python
速易达网络2 分钟前
flask与fastapi的区别
python
用户416596736935511 分钟前
Android 媒体库高效扫描器:基于协程与 `ContentObserver` 的 `FileScanner`
android
Arenaschi14 分钟前
Android中的release下面的包有什么左右和debug 的包有什么区别
android
2501_9411118416 分钟前
分布式日志系统实现
开发语言·c++·算法
ycydynq22 分钟前
python html 解析的一些写法
linux·python·html
stevenzqzq24 分钟前
android recyclerview缓存2_四级缓存机制
android·spring boot·缓存
用户693717500138436 分钟前
Kotlin 函数详解:命名参数与默认参数值
android·后端·kotlin
西猫雷婶42 分钟前
CNN的四维Pytorch张量格式
人工智能·pytorch·python·深度学习·神经网络·机器学习·cnn
未来之窗软件服务1 小时前
幽冥大陆(二十三)python语言智慧农业电子秤读取——东方仙盟炼气期
开发语言·python·仙盟创梦ide·东方仙盟·东方仙盟sdk·东方仙盟浏览器