oblac / jodd

Jodd! Lightweight. Java. Zero dependencies. Use what you like.
https://jodd.org
BSD 2-Clause "Simplified" License
4.06k stars 724 forks source link

'_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on #376

Closed titanseason closed 7 years ago

titanseason commented 7 years ago

When I use DbSqlBuilder._() method, Eclipse (J2EE) tells me '_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on.

Any plan to change this method name?

igr commented 7 years ago

yes! :))) I just try to find small english word that would serve as concatenation... any ideas?

I believe sql make most sense as it is raw sql. wdyt?

neroux commented 7 years ago

Out of that list I'd vote for add().

However (and there is always a but, isnt there ;-) ) _() is a convenience method for append() and with two very similarly named methods (add/append) doing the identical thing it might become eventually confusing/redundant. As those aliases/shortcuts should usually be as short a possible, the dollar sign (as used in Jerry too) might be a good solution.

Alternatively - and not without potential drawbacks - a Unicode character such as fullwidth low line (_) might be an option (Java unfortunately does not accept fullwidth plus ()). Of course that could create typing - though autocomplete might come to rescue here - and display issues, apart from confused users. I wanted to have it mentioned though :).

igr commented 7 years ago

Good catch @neroux , I forgot there is append which does the same :) In that sense, having another shorter-named method that does the same is... meh :) Then maybe We can simply have one method and not the shortcut (i.e. append -> add).

Wow, unicode character!!! This is mindblowing @neroux!!! Reminds me to:

double Δt = lastPollTime - pollTime;
double α = 1 - Math.exp(-Δt / τ);
average += α * (x - average);

I took _ because its visually small and this append/add is used a lot, so its much cleaner to read. But you are absolutely right; the shortcut must be as short as possible, hence proposal is:

  1. Rename append to add (its shorter)
  2. Use alternative shortcut, one of:
    int _, ‿, ⁀, ⁔, ︳, ︴, ﹍, ﹎, ﹏, _;

Moreover: the following

for (int i = Character.MIN_CODE_POINT; i <= Character.MAX_CODE_POINT; i++)
    if (Character.isJavaIdentifierStart(i) && !Character.isAlphabetic(i))
        System.out.print((char) i + " ");
}

prints

$ _ ¢ £ ¤ ¥ ؋ ৲ ৳ ৻ ૱ ௹ ฿ ៛ ‿ ⁀ ⁔ ₠ ₡ ₢ ₣ ₤ ₥ ₦ ₧ ₨ ₩ ₪ ₫ € ₭ ₮ ₯ ₰ ₱ ₲ ₳ ₴ ₵ ₶ ₷ ₸ ₹ ꠸ ﷼ ︳ ︴ ﹍ ﹎ ﹏ ﹩ $ _ ¢ £ ¥ ₩
igr commented 7 years ago

Now thinking, _ will be probably used in some future version of Java, similar like it is used e.g. in Go language; so having anything similar might not be good idea....

neroux commented 7 years ago

At the moment they do not seem to have big plans for the underscore -> http://git.net/ml/lambda-development-java/2013-07/msg00350.html however yes, the fullwidth low line is visually almost identical to the underscore and that might raise some confusion.

What would you think about $? Its short (even by actual byte count), a popular alias, already used by Jerry, and according to http://mail.openjdk.java.net/pipermail/lambda-dev/2013-August/010676.html safe to use (until they change their mind ;) ).

igr commented 7 years ago

The issue with $ might be that it is used inside of these sql templates a lot. So you might have something like:

...$(" and $table.id=")...

which might be kind of confusion as well, right?

neroux commented 7 years ago

I understand what you mean. I guess in some cases it could confuse some people but generally I'd assume it should be clear what is a command and what data, particularly with syntax highlighting.

My main concern with Unicode characters is about their "typeability" (though that might mitigated by aforementioned autocomplete) and possibly encoding issues.

igr commented 7 years ago

hey man, you are right! in fact, i just realized that example i gave above can't happens. so $ might be nice shortcut.

The template is where $ appears, and those two can't never happen together.

For Jerry it ways easy, since this is what JQuery is using ;) Cool!

neroux commented 7 years ago

Just in time :). With Java 1.9 (currently due in July) _ does not yield a warning anymore but straightforward an error

https://blogs.oracle.com/sundararajan/entry/underscore_is_a_keyword_in

igr commented 7 years ago

Awesome!!!