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

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

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

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

相关推荐
2403_883261097 小时前
C#怎么计算两个日期的差值_C#如何处理时间跨度【笔记】
jvm·数据库·python
m0_740653227 小时前
Golang切片底层原理是怎样的_Golang切片实现原理教程【简明】
jvm·数据库·python
yexuhgu7 小时前
CSS如何处理CSS逻辑属性兼容性_通过PostCSS转译为物理属性
jvm·数据库·python
m0_624578597 小时前
CSS如何给Bootstrap背景添加半透明层_使用rgba颜色模式与定位
jvm·数据库·python
智慧物业老杨7 小时前
智慧物业数智化转型实战:从工单响应到业主满意度的闭环构建
java·开发语言
m0_470857647 小时前
CSS如何实现等宽表格布局_利用table-layout与盒模型
jvm·数据库·python
Kiling_07047 小时前
Java集合框架:List集合详解与应用
java·开发语言·windows
kexnjdcncnxjs7 小时前
HTML 中使用 EXIF.js 读取图片元数据失败的常见原因与解决方案
jvm·数据库·python
iuvtsrt7 小时前
Python如何实现定时异步任务_结合asyncio与loop.call_later调用
jvm·数据库·python
m0_463672207 小时前
HTML怎么标注成就连续打卡中断_HTML“断连,重新开始”提示【方法】
jvm·数据库·python