`
sevenduan
  • 浏览: 12444 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
最近访客 更多访客>>
社区版块
存档分类
最新评论

use less code to deliver high quality product

    博客分类:
  • java
阅读更多
Less Code == [Less Bugs,Better Readability,Less programmers to hire, Less organizational communication costs, Less maitain cost]
Less Code != [Higher Productivity,Better Performance]
1, import static
remove duplicated namespace
what does it do?
package com.toolbox.lang;
public class ClassWithStaticMember {
  public static final String name="value";
  public static String say() {
    return "111";
  }
  public static String say(String msg) {
    return msg;
  }
}
package com.toolbox.lang;
import static com.toolbox.lang.ClassWithStaticMember.say;
import static com.toolbox.lang.ClassWithStaticMember.name;
public class Test {
  public static void main(String[] args) {
    System.out.println(say());
    System.out.println(say(name));
  }
}

import同名的member
意味着不同方法签名的member都会import, e.g. say() and say(String msg)
const #45 = Method      #46.#48;        //  com/toolbox/lang/ClassWithStaticMember.say:()Ljava/lang/String;
const #46 = class       #47;    //  com/toolbox/lang/ClassWithStaticMember
const #47 = Asciz       com/toolbox/lang/ClassWithStaticMember;
const #48 = NameAndType #49:#38;//  say:()Ljava/lang/String;
const #49 = Asciz       say;
const #62 = Method      #46.#63;        //  com/toolbox/lang/ClassWithStaticMember.say:(Ljava/lang/String;)Ljava/lang/String;
const #63 = NameAndType #49:#64;//  say:(Ljava/lang/String;)Ljava/lang/String;

copy primitive type value
意味着编译后,Test class中static import的String, int 等是值的写入class中,不会在去引用ClassWithStaticMember
   43:  ldc     #55; //String value
   45:  invokestatic    #57; //Method com/toolbox/lang/ClassWithStaticMember.say:(Ljava/lang/String;)Ljava/lang/String;
   48:  invokevirtual   #50; //Method java/io/PrintStream.println:(Ljava/lang/String;)V

when to use it?
Do it when frequent access to static members from one or two classes
Not Do it when has naming conflict or complicated class body, otherwise, make you confuse with so many polluting namespace

2, apply lanuage feature
2.1 String contact
String s = "a" + "b";
compile into:
const #15 = Asciz       ([Ljava/lang/String;)V;
const #16 = String      #17;    //  ab
if String constance + String constance
直接编译成结果写入class
else
使用StringBuilder.append
So always use "+" unless you need to use StringBuffer or other specific class
3, inner class {{}}
  List<String> list = new ArrayList<String>() {{add("data1");add("data2");}};
4, use PMD to find and remove duplicated code
0
0
分享到:
评论

相关推荐

    The Definitive Guide to Squarespace Learn to Deliver Custom, Professional epub

    The Definitive Guide to Squarespace Learn to Deliver Custom, Professional Web Experiences for Yourself and Your Clients 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息...

    Models to Code: With No Mysterious Gaps

    This might not be your particular target language or platform, but you can use you can use what you learn here to engineer or re-evaluate your own code translation system to dramatically increase the...

    Developer Express XtraNavBars Suite AllSourcesCode

    less code and deliver more! And like all of our .NET components, the XtraNavBar is available with FULL SOURCE CODE. Total Control, Flexibility and Power The No Limits Navigation Bar for .NET

    Quality Code: Software Testing Principles, Practices, and Patterns

    Whether you’re developing cutting-edge code for a new start-up, or maintaining an unruly old system, this guide will help you deliver exactly what you need: quality code. • Simplify unit testing ...

    Expert one-on-one J2EE Design and Development(part1)

    deliver high-quality solutions on time and within budget. I'll focus on those features of J2EE that have proven most useful for solving the commonest problems in enterprise software development. In ...

    Expert one-on-one J2EE Design and Development(part2)

    deliver high-quality solutions on time and within budget. I'll focus on those features of J2EE that have proven most useful for solving the commonest problems in enterprise software development. In ...

    演讲出彩的三种方式three ways to deliver Effective Presentations

    演讲出彩的三种方式three ways to deliver Effective Presentations

    Infrastructure.as.Code.IAC.Cookbook.epub

    This book will help you to use the right tools, techniques, and approaches to deliver working solutions for today's modern infrastructure challenges. Style and approach This is a recipe-based book ...

    Unity3D Obi Cloth 3.5版本

    Obi is an advanced cloth simulator for Unity that uses particle physics to deliver high-quality, flexible and easy to use cloth simulation. Available for Windows, Mac, iOS and Android. Features: - ...

    Agile.Product.Development.epub

    As a result we still continue to see high failure rates in new product development, be it inside organizations or startups. Unfortunately, or rather fortunately, these failures are largely avoidable....

    Software Development, Design and Coding-2nd Edition-Apress(2017).pdf

    You’ll have thought about working in a team to deliver a product to a written schedule. You’ll begin to understand project management, know some metrics and how to review work products, and ...

    High Performance JavaScript

    Identify problem code and use faster alternatives to accomplish the same task Improve scripts by learning how JavaScript stores and accesses data Implement JavaScript code so that it doesn’t slow ...

    Obi Cloth 4.1.unitypackage

    Obi is an advanced cloth simulator for Unity that uses particle physics to deliver high-quality, flexible and easy to use cloth simulation. 不支持2019

    High.Performance.Mobile.Web.14919125

    This book will give you the knowledge and tools to measure your mobile website or webapp performance, how to find bottlenecks and the tips to deliver the fastest possible experience to end-users. ...

    Testing with Junit(PACKT,2015)

    This book explains JUnit concepts and best practices applied to the test first approach, a foundation for high quality Java components delivered in time and budget. From the beginning you'll be ...

    cloth simulator.zip

    Obi is an advanced cloth simulator for Unity that uses particle physics to deliver high-quality, flexible and easy to use cloth simulation. Available for Windows, Mac, iOS and Android.

Global site tag (gtag.js) - Google Analytics