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

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

例子一:要实现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))

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

相关推荐
外收内放12 分钟前
Python基础语法练习题(53-54)
python·学习
聪明蛋子哟20 分钟前
Python与Java双栈实战:手撸一个支持RAG与Tool Calling的高性能Agent框架
java·开发语言·python
谢亮_vipxieliang20 分钟前
Go Context 控制协程生命周期
开发语言·golang
xuxigifxfh25 分钟前
HJ4 字符串分隔
java·开发语言·华为机考
databook35 分钟前
什么是范数?用 NumPy 动手算一遍就明白了
python·数学·numpy
MayZork43 分钟前
Qt 开发集成CMake + vcpkg
开发语言·c++·qt
朝朝辞暮i1 小时前
VLA 系统学习第 5 课:神经网络的参数到底是什么?——从 nn.Linear 真正理解 W、 b 和 Gradient
人工智能·python·深度学习·神经网络·vla
XZ-0700011 小时前
week7-文本
python
零基础1231 小时前
PDF 处理工具全攻略:pdf24、PDFgear、Adobe Acrobat DC 与 Stirling-PDF 深度对比
java·开发语言·pdf
Java后端的Ai之路1 小时前
01-React基础教程
开发语言·前端·python·react.js·前端框架