27

In Java 7, a new feature was added to Java that allows underscores to be placed within numeric literals in order to improve the readability of them. However, the Java code highlighting on SO is not properly treating numeric literals with underscores as numeric literals.

Right now, Java numeric literals show up as red to stand out from what surrounds it. However, when an underscore is used in such a numeric literal, only the part to the left of the first underscore is highlighted as red; the rest of the number is just black. Whenever this new feature is used in SO code, it should be the entire numeric literal that is highlighted, not just the first part of it.

Since the author of Prettify does not seem to update the project that often, this is a request for someone to upload a patch to fix it. Once that is done, I'll change this request to one that asks SE to update to the newer revision.

Example: https://stackoverflow.com/a/26102093

Screenshot: Underscore issue example

17
  • 9
    Related: What is syntax highlighting and how does it work? tl;dr: StackExchange uses Google Prettify. When someone fixes it in Google Prettify, it'll be fixed here.
    – vcsjones
    Commented Sep 30, 2014 at 16:51
  • Reported it here to track it. Will report there when I get a chance.
    – gparyani
    Commented Sep 30, 2014 at 18:04
  • 7
    Relevant issue on Prettify's issue tracker: code.google.com/p/google-code-prettify/issues/detail?id=353
    – gparyani
    Commented Sep 30, 2014 at 19:10
  • 8
    Hahaha. Numeric literals? For C#, half of features don't work (and if they do, they're working wrong) and no one gives a damn. Even something as simple as XML highlighting fails in deeply nested files.
    – Athari
    Commented Sep 30, 2014 at 20:58
  • 3
    What an odd feature...
    – canon
    Commented Sep 30, 2014 at 21:28
  • 2
    @canon, I wish it were more common. First saw it when using Ada in 1991. adacore.com/adaanswers/gems/ada-gem-7 And I know Eiffel supports numeric literals with underscores. docs.eiffel.com/book/method/… Commented Sep 30, 2014 at 21:53
  • 1
    @Athari You should report those issues like damryfbfnetsi did here, and you may find those problems resolved in the near future. Commented Sep 30, 2014 at 22:17
  • 1
    @ShannonSeverance: It's gaining on, Rust has it too for example. Commented Oct 1, 2014 at 6:52
  • 1
    @MatthieuM. Ruby also has it. Its use is recommended by a very popular Ruby style guide. Commented Oct 1, 2014 at 7:18
  • 5
    @AndrewGrimm Why someone would want to write 1_000_000 instead of 1E6 is beyond my understanding.
    – Roland
    Commented Oct 1, 2014 at 13:06
  • 1
    @Roland it'd look too similar to IE6! Commented Oct 1, 2014 at 13:08
  • 2
    It would make more sense for 0x3B9A_CA00 although I don't know if that's valid in Java (0x3B9A'CA00 is valid in C++14)
    – MSalters
    Commented Oct 1, 2014 at 13:08
  • @MSalters It's valid code.
    – gparyani
    Commented Oct 1, 2014 at 14:28
  • @Roland I do. I'm visual; For example, I have trouble reading digital clocks and far prefer analog (the shape of the hands rather than the specific numbers is how I tell time), and numbers in general are the same way. I can see at a glance that the first one is 1 million, but with the second one I have to do some quick math to figure it out. It's trivial math, but it is enough to break the flow.
    – Izkata
    Commented Oct 1, 2014 at 15:16
  • 1
    @MSalters Looking at the examples in the docs linked in the question, that appears to have been the intent behind adding the feature
    – Izkata
    Commented Oct 1, 2014 at 15:18

1 Answer 1

5

As of 9/24/2020, the Stack Exchange network (including Stack Overflow) has switched from Prettify to highlight.js, per this announcement. This change of renderer fixed this issue.

The following demonstrates the new, working rendering:

public void myMethod() {
  int number = 123_456;
  int number2 = 123;
}

Here is a side-by-side image comparison of the two syntax highlighters:

highlight.js & Prettify comparison

0

Not the answer you're looking for? Browse other questions tagged .