java、php、python的开发效率对比
2013-03-26 09:09
711 查看
我对java最熟悉,对php和python只是了解,实际工作中也没有真正用过,昨天一个合作方发过来一个service api的demo实现,里面有java,php和python三种实现,打开一看,第一眼就被python这类脚本语言所折服,单从代码量上来说,差别实在是太大,如果都是熟手开发,业务场景也正好适合该语言的话,开发效率自然就不用再说:
扣除掉注释之后:java 56行;php:30行;python:15行
不得不再次感叹脚本的威力
扣除掉注释之后:java 56行;php:30行;python:15行
不得不再次感叹脚本的威力
package com.test.http; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.security.MessageDigest; import java.math.BigInteger; public class ApiDemo{ public static void sendRequest(String id, String secureKey) throws IOException{ URL request = new URL("xxxxxx?id="+id); HttpURLConnection connection = (HttpURLConnection)request.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.connect(); String scanParam = "{\"scanlist\":[{\"sid\":\"123\", \"url\":\"http://dl.test.com/test.apk\", \"md5\":\"3d41f29d762ec547bfa4b42f57f3dc7c\"}]}"; String authKey = getStringMd5(scanParam + id + secureKey); String post = "authkey=" + authKey + "&request=" + scanParam; DataOutputStream writeStream = new DataOutputStream(connection.getOutputStream()); writeStream.writeBytes(post); writeStream.flush(); writeStream.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line=""; while ((line = reader.readLine()) != null){ System.out.println(line); } reader.close(); connection.disconnect(); } public static String getStringMd5(String src) { MessageDigest md; StringBuilder md5 = new StringBuilder(); try{ md = MessageDigest.getInstance("md5"); md.update(src.getBytes()); for (byte b : md.digest()) { md5.append(String.format("%02x", b)); } } catch (Exception e) { e.printStackTrace(); } return md5.toString(); } public static void main(String[] args) throws Exception { try { sendRequest("test", "123456"); } catch (IOException e) { e.printStackTrace(); } } }
<?php $id="test"; $secure_key="123456"; $api_url="http://xxxxx?id=".$id; $scan_parm="{\"scanlist\":[{\"sid\":\"123\", \"url\":\"http://dl.test.com/test.apk\", \"md5\":\"3d41f29d762ec547bfa4b42f57f3dc7c\"}]}"; $authkey=md5($scan_parm.$id.$secure_key); $post="authkey=".$authkey."&request=".$scan_parm; $url_info=parse_url($api_url); if(!isset($url_info["port"])){ $url_info["port"]=80; } $request.="POST ".$url_info["path"]."?".$url_info["query"]." HTTP/1.1\r\n"; $request.="Host: ".$url_info["host"]."\r\n"; $request.="Cache-Control: no-cache\r\n"; $request.="Content-type: application/x-www-form-urlencoded\r\n"; $request.="Accept: text/html\r\n"; $request.="Content-length: ".strlen($post)."\r\n"; $request.="Connection: close\r\n"; $request.="\r\n"; $request.=$post; $fp = fsockopen($url_info["host"], $url_info["port"]); if(!$fp){ echo "$errstr($errno)\n"; } fwrite($fp, $request); while(!feof($fp)){ $response .= fgets($fp, 128); } echo "$response\n"; ?>
#!/usr/bin/python import httplib, md5 if __name__ == "__main__": id="test" secure_key="123456" scan_param='{"scanlist":[{"sid":"123", "url":"http://xxxxx/test.apk", "md5":"3d41f29d762ec547bfa4b42f57f3dc7c"}]}"' authkey=md5.new(scan_param + id + secure_key).hexdigest() post= "authkey=%s&request=%s" %(authkey, scan_param) domain="xxxxx" url_path = "/api/scansoft?id="+id headers = {"Content-type": "application/x-www-form-urlencoded"} connect = httplib.HTTPConnection(domain) connect.request("POST", url_path, post, headers) res = connect.getresponse() print res.read()
相关文章推荐
- java python php 经典开发流程 开发效率 运行效率&并发&可扩展
- 后台开发语言的比较 java php python asp.net ruby on rails
- 六种主流编程语言(C、C++、Python、JavaScript、PHP、Java)特性对比
- 编程开发(C/C++&Java&Python&JavaScript&Go&PHP&Ruby&Perl&R&Erlang)
- Java, Python, Ruby, PHP, C等语言性能对比
- 六种主流编程语言(C、C++、Python、JavaScript、PHP、Java)特性对比
- golang、python、php、c++、c、java、Nodejs性能对比
- C、C++、Python、JavaScript、PHP、Java语法对比(纠正篇)
- paip.提高效率---集合的存取括号方式 uapi java python php js 的实现比较
- ubuntu下搭建Android(Java)、PHP、Python、C/C++等的开发环境
- paip.提高效率---集合的存取括号方式 uapi java python php js 的实现比较
- 2017年的golang、python、php、c++、c、java、Nodejs性能对比
- 六种主流编程语言(C、C++、Python、JavaScript、PHP、Java)特性对比
- 用数据阐述Java, Python, Ruby, PHP, C等各语言性能对比
- 六种主流编程语言(C、C++、Python、JavaScript、PHP、Java)特性对比
- PHP 比 Java 的开发效率高在哪?
- 2017年的golang、python、php、c++、c、java、Nodejs性能对比(golang python php c++ java Nodejs Performance)
- 微信公众开放平台开发02---微信公众平台PHP接口和java接口对比
- 2017年的golang、python、php、c++、c、java、Nodejs性能对比[续]
- NDK开发 从入门到放弃(六:JAVA与C++灰化图片的效率对比)