« Java JSR » : différence entre les versions

De Lillois Fractale Wiki
Aller à la navigation Aller à la recherche
Contenu ajouté Contenu supprimé
(Page créée avec « == Suggested improvements for the java langage == This page contains several improvements suggested for the java langage - my favorite programmind and thinking langage.... »)
 
Aucun résumé des modifications
 
(13 versions intermédiaires par le même utilisateur non affichées)
Ligne 2 : Ligne 2 :
== Suggested improvements for the java langage ==
== Suggested improvements for the java langage ==


This page contains several improvements suggested for the java langage - my favorite programmind and thinking langage.
This page contains several improvements suggested for the java langage - my favorite programming and thinking langage.


They would possibly be translated into JSRs, if this is not too complex and dissuasive.
They would possibly be translated into JSRs, if this is not too complex and dissuasive.

Together, they describe the '''''langage that I would have loved to use'''''...


== Fuzzy primitive type ==
== Fuzzy primitive type ==


Besides the existing primitive types, it is suggested to add the fuzzy type, which may be consisdered as a mix of boolean and real value.
Besides the existing primitive types, it is suggested to add the <span style="font-family:courier new,courier,monospace;">fuzzy</span> type, which may be considered as a mix of boolean and real value.


A fuzzy varaible would be used to represent fuzzy logic values, probabilities, ad generally speaking real values in the [0.0,1.0] range. Example of computing and mathematics concepts are : saturation levels,&nbsp;permeabilities, similarities, etc...&nbsp;&nbsp;
A fuzzy variable would be used to represent fuzzy logic values, probabilities, and generally speaking real values in the [0.0,1.0] range. Example of computing and mathematics concepts are&nbsp;: saturation levels,&nbsp;permeabilities, similarities, etc...&nbsp;&nbsp;


The code of an AI project using fuzzy logic would certainly be easier to write, read, understand and maintain (fuzzy logic is a key of AI - see Alex project)&nbsp;
The fuzzy type should be involves in various casting process


*fuzzy ->&nbsp;boolean
The fuzzy type should be involved&nbsp;in various casting

*fuzzy ->&nbsp;boolean (result is true if and only if&nbsp;fuzzy value>=0.5)
*boolean -> fuzzy
*boolean -> fuzzy
*real (double or float) -> fuzzy
*real (double or float) -> fuzzy (the real value is first reduced t0 1.0 if it is higher than&nbsp;1.0&nbsp;: extended to 0.0 if it is lower than 0.0)
*fuzzy -> real (double or float)
*fuzzy -> real (double or float)


Fuzyy variable should then be usable wherever boolean vars are used, like in if and while statements.
Fuzzy variables should then be usable wherever boolean variables are used, like in&nbsp;<span style="font-family:courier new,courier,monospace;">if() </span>and <span style="font-family:courier new,courier,monospace;">while()</span> statements.


The displayed value (toString()) of a fuzzy var may be <span style="font-family:courier new,courier,monospace;">true</span>, <span style="font-family:courier new,courier,monospace;">false</span> or a real value between (excluding) 0.0 and 1.0 ;&nbsp;&nbsp;<span style="font-family:courier new,courier,monospace;">true</span> is a short form of 1.0 , <span style="font-family:courier new,courier,monospace;">false</span> is a short form of 0.0.&nbsp;
The displayed value (toString()) of a fuzzy var may be <span style="font-family:courier new,courier,monospace;">true</span>, <span style="font-family:courier new,courier,monospace;">false</span> or a real value between (excluding) 0.0 and 1.0&nbsp;;&nbsp;&nbsp;<span style="font-family:courier new,courier,monospace;">true</span> is a short form of 1.0 , <span style="font-family:courier new,courier,monospace;">false</span> is a short form of 0.0.&nbsp;


Operations on fuzzy variable should include
Operations on fuzzy variable should include


*not (!x) :&nbsp;
*not (!x)&nbsp;:&nbsp; &nbsp;!x == (fuzzy)(1.0-(real)x)
*and (x&&y)&nbsp;:&nbsp;&nbsp;x&&y&nbsp;==&nbsp; (fuzzy)((real)x * (real)y)
*and (&&) :
*xor (x^^y)&nbsp;:&nbsp;&nbsp;x^^y&nbsp;==
*or (||)
*or (x||y)&nbsp;: x||y ==
*&nbsp;areal operations (with the restriction that te result is transformed into 1.0 (true) if it exceeds 1.0,&nbsp;and into 0.0 (false) if it falls below 0.0.
*real-derived operations + - * / (with the restriction that the result is transformed into 1.0 (<span style="font-family:courier new,courier,monospace;">true</span>) if it exceeds 1.0,&nbsp;and into 0.0 (<span style="font-family:courier new,courier,monospace;">false</span>) if it falls below 0.0.


== Access control to variable ==
== Access control to class variables (goodbye to getters and setters) ==

Access to class variables in java is determined mainly by the modifiers <span style="font-family:courier new,courier,monospace;">public protected private</span> (and <span style="font-family:courier new,courier,monospace;">final</span>)

This does not allow to distinguish between read access and write access.

Nay coder dreamed of readonly vars sometimes.

As an indirect effect, the lack of read / write modifiers is generally circumvented by the use of numerous heavy getXXX() and setXXX() methods, making the code heavy.

It is suggested here to define access to variables using a more granular modifier set.

The modifiers are&nbsp;defined as 3-chars sequences. The first one related to this class, teh second one to this package, and the third one to the reste of the world.

Each char may be 'w' (read and write access) 'r' (read only access) and 'n' (no access).

The allowed values are:

*<span style="font-family:courier new,courier,monospace;">'''www&nbsp;'''</span>(equivalent to <span style="font-family:courier new,courier,monospace;">public</span>)
*<span style="font-family:courier new,courier,monospace;">'''wwr'''</span>
*<span style="font-family:courier new,courier,monospace;">'''wwn&nbsp;'''</span>(equivalent to <span style="font-family:courier new,courier,monospace;">protected</span>)
*<span style="font-family:courier new,courier,monospace;">'''wrr'''</span>
*<span style="font-family:courier new,courier,monospace;">'''wrn'''</span>
*<span style="font-family:courier new,courier,monospace;">'''wnn&nbsp;'''</span>(equivalent to <span style="font-family:courier new,courier,monospace;">private</span>)
*<span style="font-family:courier new,courier,monospace;">'''rrr&nbsp;'''</span>(equivalent to <span style="font-family:courier new,courier,monospace;">public final</span>)
*<span style="font-family:courier new,courier,monospace;">'''rrn&nbsp;'''</span>(equivalent to <span style="font-family:courier new,courier,monospace;">protected&nbsp;final</span>)
*<span style="font-family:courier new,courier,monospace;">'''rnn&nbsp;'''</span>(equivalent to <span style="font-family:courier new,courier,monospace;">private final</span>)


== Depending vars ==
== Depending vars ==

Sometimes in java you want to maintain some (destination) variables as values derived from other (source) variables.

The code to achieve this is often heavy. You have to check any possible change of the source variables, and recompute the destination vars in all these places, with the risk to forget one.

If the variable are proteced or public, you&nbsp;have to create a complex set of getters() and setters() with sometimes subtle dependencies.

This could be transferred to the langage compiler.

It is then sggested to introduce in the code a new modfier link:

For instance
<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">int x;</div> <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">int y;</div> <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">int productxy link:(x*y);</div> <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">int funcxy link:(f(x,y);</div>
It is then the compiler and virtual machine responsibility to update destination vars whenever they are called.


== Primitive type simplification ==
== Primitive type simplification ==


In java we have float and double.
Simplified min affcat

In java we have byte, short, int, long. These are implicitely insigned (or not).

Given the fact that current processor handle long and double as fast (or faster) than other types, it is suggested

*to remove float type (and rename "double" "real")
*to replace all discrete type with only the int type (with the 64 bits of the previous 'long' type)
*to add min: and max: modifiers in the variable declaration, for instance
*to add the init: modifier with a syntax similar to the min: and max: modifiers.&nbsp;
<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">int ix min:0 max:100 init:20;</div> <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">int iy&nbsp;min:-128&nbsp;max:127;</div> <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">int iz&nbsp;min=0 max=256;</div> <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">real rr&nbsp;min:-Math.PI max:Math.PI;</div>
== Simplified min max conditional assign ==

Often in java, code contains
<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">if (x<minx) minx=x;</div>
This could be rewritten in a more compact way
<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">minx =<= x;</div>
When the new minimum candidate (x) is a heavy function, it is necessary for efficiency reason to write something like
<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">var x&nbsp;= function(xx);&nbsp;&nbsp;if (x<minx) minx=x;</div>
And of course, the rewriting would be simply
<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">minx =<= function(xx);</div>
And similarly
<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">if (x>maxx) maxx=x;</div>
could&nbsp;be rewritten
<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">maxx =>=x;</div>
As a side effect, the generated code could be more efficient (? to be checked with processor instructon set&nbsp;?).

Dernière version du 23 juillet 2018 à 19:34

Suggested improvements for the java langage

This page contains several improvements suggested for the java langage - my favorite programming and thinking langage.

They would possibly be translated into JSRs, if this is not too complex and dissuasive.

Together, they describe the langage that I would have loved to use...

Fuzzy primitive type

Besides the existing primitive types, it is suggested to add the fuzzy type, which may be considered as a mix of boolean and real value.

A fuzzy variable would be used to represent fuzzy logic values, probabilities, and generally speaking real values in the [0.0,1.0] range. Example of computing and mathematics concepts are : saturation levels, permeabilities, similarities, etc...  

The code of an AI project using fuzzy logic would certainly be easier to write, read, understand and maintain (fuzzy logic is a key of AI - see Alex project) 

The fuzzy type should be involved in various casting

  • fuzzy -> boolean (result is true if and only if fuzzy value>=0.5)
  • boolean -> fuzzy
  • real (double or float) -> fuzzy (the real value is first reduced t0 1.0 if it is higher than 1.0 : extended to 0.0 if it is lower than 0.0)
  • fuzzy -> real (double or float)

Fuzzy variables should then be usable wherever boolean variables are used, like in if() and while() statements.

The displayed value (toString()) of a fuzzy var may be true, false or a real value between (excluding) 0.0 and 1.0 ;  true is a short form of 1.0 , false is a short form of 0.0. 

Operations on fuzzy variable should include

  • not (!x) :   !x == (fuzzy)(1.0-(real)x)
  • and (x&&y) :  x&&y ==  (fuzzy)((real)x * (real)y)
  • xor (x^^y) :  x^^y ==
  • or (x||y) : x||y ==
  • real-derived operations + - * / (with the restriction that the result is transformed into 1.0 (true) if it exceeds 1.0, and into 0.0 (false) if it falls below 0.0.

Access control to class variables (goodbye to getters and setters)

Access to class variables in java is determined mainly by the modifiers public protected private (and final)

This does not allow to distinguish between read access and write access.

Nay coder dreamed of readonly vars sometimes.

As an indirect effect, the lack of read / write modifiers is generally circumvented by the use of numerous heavy getXXX() and setXXX() methods, making the code heavy.

It is suggested here to define access to variables using a more granular modifier set.

The modifiers are defined as 3-chars sequences. The first one related to this class, teh second one to this package, and the third one to the reste of the world.

Each char may be 'w' (read and write access) 'r' (read only access) and 'n' (no access).

The allowed values are:

  • www (equivalent to public)
  • wwr
  • wwn (equivalent to protected)
  • wrr
  • wrn
  • wnn (equivalent to private)
  • rrr (equivalent to public final)
  • rrn (equivalent to protected final)
  • rnn (equivalent to private final)

Depending vars

Sometimes in java you want to maintain some (destination) variables as values derived from other (source) variables.

The code to achieve this is often heavy. You have to check any possible change of the source variables, and recompute the destination vars in all these places, with the risk to forget one.

If the variable are proteced or public, you have to create a complex set of getters() and setters() with sometimes subtle dependencies.

This could be transferred to the langage compiler.

It is then sggested to introduce in the code a new modfier link:

For instance

int x;
int y;
int productxy link:(x*y);
int funcxy link:(f(x,y);

It is then the compiler and virtual machine responsibility to update destination vars whenever they are called.

Primitive type simplification

In java we have float and double.

In java we have byte, short, int, long. These are implicitely insigned (or not).

Given the fact that current processor handle long and double as fast (or faster) than other types, it is suggested

  • to remove float type (and rename "double" "real")
  • to replace all discrete type with only the int type (with the 64 bits of the previous 'long' type)
  • to add min: and max: modifiers in the variable declaration, for instance
  • to add the init: modifier with a syntax similar to the min: and max: modifiers. 
int ix min:0 max:100 init:20;
int iy min:-128 max:127;
int iz min=0 max=256;
real rr min:-Math.PI max:Math.PI;

Simplified min max conditional assign

Often in java, code contains

if (x<minx) minx=x;

This could be rewritten in a more compact way

minx =<= x;

When the new minimum candidate (x) is a heavy function, it is necessary for efficiency reason to write something like

var x = function(xx);  if (x<minx) minx=x;

And of course, the rewriting would be simply

minx =<= function(xx);

And similarly

if (x>maxx) maxx=x;

could be rewritten

maxx =>=x;

As a side effect, the generated code could be more efficient (? to be checked with processor instructon set ?).