The 9 lines of code of Google


Are you still remembering the then hot debated news about Oracle suing Google allegedly copying a small portion of codes from Oracle‘s Java in 2010. At that time, Oracle experts estimated that Google owes Oracle between $1.4 billion and $6 billion in damages if liable. But the court thought Oracle was eligible only for statutory damages for that copying, which were not expected to exceed a few hundred thousand dollars. At last, Oracle agreed the zero damage result.

Are you curious about which portion of codes Oracle claimed were stolen? Actually, it‘s only a really small portion of it, around 9 lines of codes. These codes are for range check, it‘s really a common implementation which a general programmer can write.

Joshua Bloch is the developer who wrote this piece of code. Joshua Bloch was a Sun developer(then acquired by Oracle) for the development of Java APIs. Later he joined Google in 2004 and worked on Android in 2008.  While working for Google, he still contributed to the OpenJDK One of the things he contributed was a much faster implementation for sorting arrays, based on the algorithm TimSort used in Python. Both the old and new algorithm had the rangeCheck method in common, so he just copied it from the old implementation, as “a temporary measure”. But later somehow this temporary measure ended up in Android.

Below are the 9 lines of codes copied:

private static void rangeCheck(int arrayLen, int fromIndex, int toIndex {
     if (fromIndex > toIndex)
          throw new IllegalArgumentException("fromIndex(" + fromIndex +
               ") > toIndex(" + toIndex+")");
     if (fromIndex < 0)
          throw new ArrayIndexOutOfBoundsException(fromIndex);
     if (toIndex > arrayLen)
          throw new ArrayIndexOutOfBoundsException(toIndex);
}

 

Easy enough so that most programmers can write in just a few minutes or less. But the thing is not about the codes, it‘s about the attitude and incentive. Nowadays many API developers are not allowed to read other companies‘ similar APIs before implementing their own because the management fears that the developers may be interfered by the source codes they read and write the same without noticing it. They would be able to refer to the source code after they complete implementing their own API however.

Be careful when you are using open source codes especially when you are working for a company which gains its profit by selling commercial software.

 

The 9 lines of code of Google

时间: 2024-12-26 14:33:06

The 9 lines of code of Google的相关文章

Object Detection with 10 lines of code - Image AI

To perform object detection using ImageAI, all you need to do is Install Python on your computer system Install ImageAI and its dependencies 3. Download the Object Detection model file 4. Run the sample codes (which is as few as 10 lines) Now let's g

CLOC(Count Lines Of Code)代码统计工具

cloc 是一个 perl 脚本,它可以统计很多种编程语言的代码文件中的空行.注释以及实际的代码行数. 相关网站: http://cloc.sourceforge.net/ http://sourceforge.jp/projects/sfnet_cloc/releases/ 安装 环境 windows 7 + Vmware Player 6.0 + fedora 18(linux 3.6.10) + gcc 4.7.2 Linux环境下: [[email protected] ~]# yum

eclipse code format の google code format

一直有人问code format, 在摸里面混了这么久都是在说G 场子的XXX 所以闲来没事就去研究了下,果然大厂风范,定义规范,不多话上干货. http://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s3.3.1-wildcard-imports Git 的地址: https://github.com/google/styleguide 如何使用: 在次上干货详细代码: <?xml version="1.0&quo

Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code

Editor's Note: The following is a guest post from Mustafa Mahmutovi?, a Microsoft Student Partner who attends the Faculty of Electrical Engineering at the University of Sarajevo where he is a Computer Science Major. In this tutorial, you will learn h

google code 上源码的下载方法

SVN全称是Subversion,是Apache的一个子项目 ,具体能够到SVN中文站(http://www.subversion.org.cn/)去了解下.Google Code是Google的一个开放源码计划,当中包含源码托管,即提供一个server来保存.共享和管理源码.每一个人都能够创建自己的Project,至于空间的大小,请看下图: 我想一般项目都足够用了. 准备工具 TortoiseSVN-1.6.9.19725-win32-svn-1.6.12(Explorer 插件) SubEc

Google Summer of Code 2017 经验谈

Google Summer of Code (GSoC) 2018 又要开始了. 如果想实现你心中的开源梦想, 用代码让世界变得更美好. 参加GSoC可能是你进入开源的世界最好途径. GSoC是什么 Google Summer of Code是Google每年举办的一个活动. 从2005年开始到现在已经举办了十三届. Google在GSoC中的角色是一个平台和资金的提供者. 通过这个平台, 学生能够找到自己心仪的开源组织, 为了能获得实现project idea的资格而展开竞争. 申请期截止之后

Code is not literature

http://www.gigamonkeys.com/code-reading/ I have started code reading groups at the last two companies I’ve worked at, Etsy and Twitter, and some folks have asked for my advice about code reading and running code reading groups. Tl;dr: don’t start a c

利用EJS查找可用的Google搜索服务器IP,并缓存入系统Hosts文件内

此博客为9925.org的镜像,登录9925.org可以查看到最新博文. 原文出处:http://ily.so/qi2ENn 搜索可用的Google搜索服务器IP,并将搜索结果缓存入系统Hosts文件内. 提示:此脚本在R5以上版本的EJS脚本IDE工具内可成功解释运行. clear(); console.info("/**************************版权声明**************************/"); console.info("/*  

Linking code for an enhanced application binary interface (ABI) with decode time instruction optimization

A code sequence made up multiple instructions and specifying an offset from a base address is identified in an object file. The offset from the base address corresponds to an offset location in a memory configured for storing an address of a variable