Java after volcanic eruption
Some sarcastic employer asked me to improve Java, and, although I am not the president of Indonesia, but that’s what I’ve done quickly so that I accidentally get puzzled for half a day. I would like to like this. The general principle is maximum simplification without loss of logical control. For this, obviously, it is necessary not only to add to the language what was not there, but also to remove from the language much of what was there, continuing the good tradition of C--.
- Ability to return more than one result from a function.
- The default values of primitive fields must be explicitly declared. The “static” modifier is removed from the language, and the default instance is available as a static instance, accessible by reference to a typed null. Call it all the “default instance.” The possibility of the “abstract” modifier for fields, which would mean both the impossibility to create an instance of a class, and the need to specify the default value of this field in the descendant of the class.
- For the “protected”, “default” and “public” fields, autogeneration of setters and getters by the compiler, without autogenerating visible sorts, but with the possibility of overloading, “private” will be removed from the language, since the fields themselves will all be “private” without overload capability. Add "local" - about this in paragraph 8.
- Autogeneration of public interfaces from all “public” class fields, as well as a new type of protected, etc. interfaces from the fields corresponding to the modifier. Class types are compared by hash code that will be generated by field names, argument names, types, and return values, since the probability of coincidence of all this is insignificant and can be detected during compilation with warnings.
Thus, “interface” as such is no longer needed, only “class”, “abstract” is just an instruction prohibiting the creation of an instance. Regarding multiple inheritance - in the next paragraph 5.
- Add merge rules for extends. Explicitly specify the ancestor for all conflicting fields that will be indistinguishable from the methods, in paragraph 8 of this. As a result, the object will inherit the code and implement all parent types. Types that are not fully preserved as a result of Merge simply disappear from the formal ancestors, leaving the code, but creating a compilation error when trying to misuse the object.
- Dynamic types Templates as in C, but not as zheneriksy in Java. Typing does not suffer from this, since dynamic types cannot be directly used in the sorts, but can be used in all cases when basic types or reflection or templates are used, in which it is also not difficult to organize redevelopment with an instance type extension directly runtime, or narrowing to deny.
- Submethods as in Pascal.
- All methods are full-fledged default instromells of internal classes and are indistinguishable from fields. For this, the class constructor will return a value. The class constructor will be the body of the default method that will be created at compile time, in accordance with clause 2 of the “default instances”. You no longer need special references to a method, as in Java 8. A method reference will mean an object reference.
Calling a method and creating a temporary object just for calling an internal method becomes identical; all this can be optimized by the compiler as a simple method call. On the other hand, the creation of a “method” by the “new” operator, for subsequent manipulations with a reference to it, means the creation of a new instance of a “class”. Assigning a function reference to a field — directly through the method name without parentheses; function values — with parentheses and arguments in them. Fields with the “local” modifier are not saved between method calls.
All identical methods with different sets of arguments must be grouped into a subclass in order to garbage the outer class. The default fields of such a subclass become, accordingly, not absolutely static, but static with respect to the external class. Except for the case when the external class itself is a default instance.
- Instead of “try” - “catch” there are also methods, “throws” identifies the allowed type of the calling method, “throw” makes a goto on the handler's method, cutting off the callstack, and the handler methods themselves are no different, returning from them is performed in the usual way, but so it turns out that in one of the previous calling methods. Accordingly, the handler is called at the closest level of the hierarchy, as happens with try-catch. Thus, in the case of exception, to jump through some code following a certain method, you need this code, with this certain method at the beginning, to be placed in a sub-method class in which to overload the necessary handlers. This approach will significantly shorten the long, to say the least, methods of real Java projects.
"Finally" add the attachment to the method at the end to no extra brackets.
- New operator to runtime encrypt all sorts of primitives and arrays of primitive fields and String and compress them in memory for later retrieval with an access key, in bulk for the entire class instance. So that you just want to unpack-use-pack in one method, rather than scratching your head “how to do it better”.
- Arrays need border control only while writing, and I would give the opportunity to read directly from memory without controlling the array boundaries. Thus, given the presence of System.arraycopy, the array boundaries will be monitored without affecting performance. Since most of the additional calculations are most often performed during recording, and, in comparison with them, the recording itself does not take much time.
- Providing an additional basic alternative to synchronization by blockers is the simplest method in the Thread class, which sends a custom message to another Thread, and a method through which you can get custom messages from other Threads. In addition, in the “run” method of the Runnable object that is passed to Thread, you need to explicitly call the method that terminates the thread, and that without this there is a compilation error. Also, add a method that triggers custom Runnable events from other threads, accepts-sends messages every time after this interruption. All this does not fundamentally change anything, but it will simplify thread-oriented development in 90% of cases. Especially in cases where the development is in a hurry, and this is the majority of real cases.
- In fact, the graph of all objects in memory always has only primitive types, arrays, or null, or a link to something native on all its vertices. A basic tool that can save this entire graph in any text form will be very useful. Large arrays of primitives can be stored separately, small - encoded inline. Plus version of the virtual machine and - let's go, this structure can be restored in memory.
- A useful tool to search for any objects in the object graph by specified criteria, taking into account access modifiers, by the type of simple SQL. This task is greatly simplified by using points 1 ... 9. Such a tool can not only simplify the hierarchy of objects, but also organize various tests and control of permissible values and try to catch up with the Prologue.