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

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

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

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

相关推荐
Cyber4K4 分钟前
【Python专项】Nginx访问日志分析时间范围处理示例
开发语言·python·nginx
中犇科技13 分钟前
郑州无代码APP开发公司哪家好呢?推荐
开发语言
周末也要写八哥17 分钟前
代码中的注释的重要性(二)
开发语言·python
therese_1008617 分钟前
安卓-IPC
android
沙粒029 分钟前
Mac 使用 scrcpy 局域网无线投屏指南
android
XingshiXu31 分钟前
【NWAFU×KUL】不打扰,也能看懂一头牛:非接触式技术正在改变精准畜牧
人工智能·python·深度学习·目标检测·机器学习·计算机视觉·目标跟踪
kybs199131 分钟前
springboot租车系统--附源码68701
java·hadoop·spring boot·python·django·asp.net·php
过期动态1 小时前
MySQL中的约束
android·java·数据库·spring boot·mysql
wxin_VXbishe1 小时前
springboot新能源车充电站管理系统小程序-计算机毕业设计源码29213
java·c++·spring boot·python·spring·django·php
好运的阿财1 小时前
OpenClaw工具拆解之memory_search+memory_get
人工智能·python·ai编程·openclaw·openclaw工具