Some features that should not be used in java in technology and management

foreword

Java is an excellent software engineering language. But with the development of the times, some functional needs, some features that are boasted and meaningless, are forced to be implemented. Some of these features are touted as saving the world, but are used in the wrong places and by the wrong people, causing many problems. Next, Niaocai will interpret these features in depth to help you use them correctly

Features that should not be used

  1. lambda expressions and functional interfaces
  2. Stream Computing API
  3. type inference

Reason not to use

  1. Well written, the maintenance cost is very high
  2. Very poor readability
  3. high cost of learning
  4. Inconvenient to debug
  5. use incorrectly

lambda expressions and functional interfaces

It's a feature touted as saving the world, but is it?

// Java 8之前:
new Thread(new Runnable() {
    @Override
    public void run() {
    System.out.println("Before Java8, too much code for too little to do");
    }
}).start()
//Java 8方式:
new Thread( () -> System.out.println("In Java8, Lambda expression rocks !!") ).start();


too much code, for too little to do
Lambda expression rocks !!

when i need to expandEnter image description

On the way from the above, you will find a direct exception and need to be rewritten. Not extension friendly

Released from jdk7 in 2014, promoting lambda expressions. And then was blown into a god by many. Until now, I have rarely seen big cows use this feature. Therefore, it is not optimistic until now, and lambda is not used.

Stream Computing API

The first simple stream computing API was using the salsa language. It is super difficult to understand, the process cannot be known, cannot be debugged, etc. Raniao rookie is very disgusted with him.

I have encountered stream computing APIs written by others in the business code, but I can't understand them directly. When there is a problem with those codes, if you look at them, you can't understand them.

  • Just ask the person who wrote it, do you know what these mean?

  • Colleague: I can't remember either.

  • Niao Cai Q: Why did you choose this method?

  • Colleague: Simple, write simple,

  • Bird dish ah asked: Is there any more?

  • Colleague: cool, tall, trendy

  • Bird dish, my heart is: 10,000 animals of some kind...

    From analyzing requirements, coding, debugging, and verifying results, it took two days...

Since the above story is a bit of a rookie, I can't find the previous code, so I can only ask you to see a real example of the problem of stream computing api (please click)

type inference


public  List<Integer> getNum(){
	List<Integer> list = new ArrayList<>();
	list.add(new Integer(1));
	list.add(new Integer(2));
	return list;
}

public void test(){}
	for(var num : getNum()){
		// 请问你要调用那个?
	    num.doubleValue();
	    num.intValue();
	    num.longValue();
	}
}

The above code simply expresses the shortcomings of type inference, poor readability and error-prone,

Summarize

Summarizing some features of java, the learning cost is still relatively high. It is not used in most scenarios. Only use one style in the code, which is conducive to acceptance, direct coding (when there are two choices, there will be a little cost consideration) and so on. Uniform style (code style) is one of the most important things for architects and architecture teams.

Code readability, extensibility, rigor, and learning cost are always more important than code writing

Code readability, extensibility, rigor, and learning cost are always more important than code writing

Code readability, extensibility, rigor, and learning cost are always more important than code writing

Well written, want to die for maintenance. Often other people want to die, but when you accept other people's code, you can't help but scold a few words.

suitable scene

In business systems and functional systems, this feature should be avoided. If it is big data development, you can use this feature. But some details in the main stream computing API

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324939166&siteId=291194637