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

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

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

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

相关推荐
daphne odera�15 分钟前
PyCharm 中 Codex 插件启动失败:unknown variant default 的解决方法
python·chatgpt·pycharm
nbu04william42 分钟前
Deepseek-api省token的用法
python·大模型·token·deepseek
测试老哥1 小时前
Pytest自动化测试详解
自动化测试·软件测试·python·测试工具·测试用例·pytest·接口测试
坚持学习前端日记1 小时前
国产化适配全流程适配英伟达本地开发
人工智能·python
AFinalStone1 小时前
Android 7系统网络(四)Native层(下)—netd Controller详解
android·网络
jimy11 小时前
C语言模拟对象、方法:“函数指针+结构体“复用函数指针指向的函数体
c语言·开发语言
爱笑鱼2 小时前
Handler(一):post 之后,Runnable 到底在哪个线程执行?
android
源图客2 小时前
云途物流API开发-鉴权认证(Java)
java·网络·python
天外天-亮2 小时前
HBuilder X 使用 uview-plus 方式
开发语言·javascript·hbuilder x·uview-plus
木木子222 小时前
[特殊字符] 音乐播放器——状态驱动的多媒体控制
android·开发语言·华为·php·harmonyos