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

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

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

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

相关推荐
贝猫说python1 分钟前
阿里云部署qwen 大模型从0-1,第3步:阿里云服务器上部署大模型
python
少陽君5 分钟前
服务器服务检查报告
python
x秀x6 分钟前
sam3新手使用教程
开发语言·python
Java后端的Ai之路7 分钟前
大模型LLM评估完全指南
开发语言·人工智能·python·llm·评估
外收内放11 分钟前
Python学习记录25(基础知识终结篇)
python·学习
别动我齐刘海13 分钟前
ROS2 Jazzy + C++ 实战路线——基础学习1
c++·vscode·python·ubuntu·机器学习·自动驾驶·github
Brilliantwxx19 分钟前
【STM32】 从HAL库源码深度解析I2C(源码解析+面试题)
开发语言·stm32·单片机·嵌入式硬件·架构
life码农20 分钟前
python框架Flask多语言配置示例
python·flask
yxlalm22 分钟前
对话记忆持久化-Redis热与MySQL冷
android·redis·mysql
苏离~Hack27 分钟前
SL-crawler:一个可视化配置的通用网页与 API 数据采集工具
python