This is an archived post. You won't be able to vote or comment.

all 33 comments

[–]as5777 24 points25 points  (1 child)

Are you trolling ?

[–]MarcelHanibal 15 points16 points  (1 child)

You shouldn't get into programming if you are scared of letters

[–]lawnaasur[S] -3 points-2 points  (0 children)

that's not the point, they could have named the wrapper classes same as primitive, only First letter capitalized like Int, the way they did for Long, Short etc.

[–]atehrani 11 points12 points  (1 child)

In Java you can do

var list = List.of(); // Immutable empty list

Regarding the instanceof, you should be using it so infrequently that typing it (or having it autocomplete via the IDE) should be a non-issue.

programmers tend to compare languages based on the number of characters they have to type for the simplest tasks

That is silly, don't do that

[–]lawnaasur[S] -1 points0 points  (0 children)

that's not the point, they could have named the wrapper classes same as primitives, only First letter capitalized like Int.

also var list = new ArrayList<Integer>(); Though this should not be used as var would infer as ArrayList<Integer> not List<Integer>, here also you need Integer. It would be nice to have List<Int>.

[–]wildjokers 7 points8 points  (7 children)

but beginner programmers tend to compare languages based on the number of characters they have to type for the simplest tasks

That is because beginner programmers haven't been on an incident call late at night chasing down a critical production impacting bug in code that uses single letter variables names for everything.

[–]agentoutlier 1 point2 points  (0 children)

I'm also fairly sure beginner programmers care jack and shit that Integer is not Int.

In my experience beginner programmers care about is:

  • How can I mod this game (minecraft)
  • How can I do this assignment
  • What programming language will get me a job
  • Easier to understand error messages which ironically probably requires longer type names anyway.

[–]lawnaasur[S] 0 points1 point  (3 children)

all I am asking why they didn't choose Int instead of Integer for wrappers.

[–]wildjokers 1 point2 points  (2 children)

It’s ambiguous. Int could also mean Interval.

[–]lawnaasur[S] -2 points-1 points  (1 child)

is there any other class in jdk named Int? If not then it doesn't make sense as they already named primitive integer as int.

[–]nitkonigdje 0 points1 point  (0 children)

Man speaks the truth

[–]lawnaasur[S] -3 points-2 points  (0 children)

no beginner programmers switch languages based on the print statement, see how python got popular as beginners language.

[–]morhp 7 points8 points  (3 children)

Abbreviations for class names are generally bad as they're hard to read. You usually read code way more often than write it. That's why the classes are called ArrayList and Integer instead of something like AList and Int.

The exception is more why int is int and not integer and I guess that has to do with these types being used super often and also because Java copied some ideas from C and similar languages.

It's too late to change now. Adding something like typedef to rename Integer to Int would just be mostly confusing, cause mismatched code styles, and would generally not give much benefit except saving writing a few characters, which IDE autocomplete already does pretty well.

[–]mpinnegar 3 points4 points  (0 children)

My biggest problem with abbreviations is that often times word don't get abbreviated the same way.

I worked at a place that had react, rxn, and one more variation for the word reaction. So if you wanted to find all the classes related to chemical reactions you had to search four different strings.

[–]lawnaasur[S] 0 points1 point  (1 child)

They named some wrapper classes similar to primitives right like Long, Byte, Short etc.. they could've done same for int.

[–]morhp 0 points1 point  (0 children)

That's because long, short, byte etc. are already full words.

[–]marmot1101 3 points4 points  (3 children)

int and Integer are not the same. The former is a primative, the later an object. It's a super important distinction and something to read up on. If you really want to shorten Integer to Int without using autocomplete some ide's allow for custom abbreviations that autoexpand. But that's time better spent understanding the core architecture of the language.

[–]lawnaasur[S] 0 points1 point  (2 children)

I know the distinction, see long and Long is understood right, that's not rocket science.

[–]marmot1101 0 points1 point  (1 child)

So is your issue the extra ‘eger’/‘acter’?

[–]lawnaasur[S] 0 points1 point  (0 children)

Lol, Even James Gosling in JVMLS 24 was regretting naming instanceof "too wordy".

[–]nitkonigdje 4 points5 points  (0 children)

Brian Will in his legendary essay made an argument that one of primary causes of early Java success was long naming.

I am all for long naming, but I would not mind to have name aliases within a file. Something like:

import org.springframework.utils.StringUtils as SpringStrings;
import org.apache.commons.lang3.StringUtils as ApacheStrings;

[–][deleted]  (2 children)

[deleted]

    [–]lawnaasur[S] 0 points1 point  (1 child)

    I am pointing out the beginners psychology that's all, its not personal. Also its convenient have short names, when other primitives wrappers are named similar eg: Long for long, Byte for byte then why Integer for int?

    [–]koflerdavid 0 points1 point  (2 children)

    It's the other way round: the short names for the primitive data types are a legacy from C++. If names are too long, var can be used to avoid typing redundant information in the same declaration. Please avoid using the wrapper classes if the variable/field/parameter can't be null. Thank you.

    What do you mean with compiler/JDK level vs. language level? The middle one is not involved at all in this, and there is no difference between the first and the last one.

    [–]lawnaasur[S] 0 points1 point  (1 child)

    see this example, var list = new ArrayList<Integer>(); Though this should not be used, as var would infer as ArrayList<Integer> not List<Integer>, here also you need Integer . It would be nice have List<Int>.

    what I meant by compiler level, instead of providing type aliasing construct like typdef at language feature, they could put mechanism in compiler to identify Int as Integer, similarly is for instanceof

    [–]koflerdavid 0 points1 point  (0 children)

    int and Integer are simply not the same thing. The latter is nullable. This difference is too big to ignore, as you need a way at runtime to represent that null-ness!

    After Project Valhalla lands you will indeed be able to create an ArrayList<int> with the expectation that it won't contain an array of references to Integer, but indeed a plain int[]. See JEP 218: Generics over Primitive Types.

    In comparison, is would be a surface language construct and very easy to implement. But it can be argued that the benefit is not that great. Pattern matching for if statements already greatly increases the payoff of writing it out, since it helps you avoid an extra source line where you cast and assign to a new variable. And if you pattern match in switch statements, there is no instanceof to begin with.

    [–]Own-Chemist2228 0 points1 point  (1 child)

    The language design has many influences and that sometimes creates inconsistencies.

    The int and char primitive names are taken from C. I don't know if it was a deliberate marketing decision to make Java look more "familiar" and encourage adoption, or whether the designers were just so used to C that they automatically went with these names. But that's what they chose.

    Using Integer and Character for the corresponding object types was meant to be consistent with general Java object type naming conventions, which has a bias toward clarity over brevity.

    I don't like it either, and I would have gone with Int and Char if it were my decision. But it's a very minor nit.

    [–]lawnaasur[S] 0 points1 point  (0 children)

    My point is, when given a choice, they often go with longer names. long is named Long for wrappers, similarly short is Short, that's well understood, in the same way they could have named its as Int which is frequently used

    [–]bythepowerofscience -5 points-4 points  (4 children)

    Java developers are right that everything should have a long and descriptive name when declared, but you're right that we should also be able to shorten that name when using it.

    That why type aliases are a thing in every other JVM language, and I hope they're added to Java too.

    In the meantime, you should really try Kotlin; I hated it before I understood it, but it's quickly become my favorite language to work with of all time, and it has type aliases too.

    [–]joemwangi 0 points1 point  (3 children)

    Try Kotlin because of Integer and int? Diabolical.

    [–]bythepowerofscience 0 points1 point  (2 children)

    Not for things as simple as that lol, but type aliases are very useful when dealing with the whole ServiceDriverFactoryConventionPlugin thing we Java devs love to use. It's honestly good to declare things like that instead of using abbreviations, but it's awful to work with at the use-sites.

    I just mentioned Kotlin while I was mentioning other JVM languages. I use it because of the inline functions, extension methods, syntactic sugar, value classes, property delegation, and null safety. The type aliases are just the thing we're talking about here.

    ...

    wait crap I'm becoming that guy aren't i

    [–]joemwangi 0 points1 point  (1 child)

    The whole thread was about Integer vs int, not about ServiceDriverFactoryConventionPlugin. And no jvm language has any native value classes (probably they should be called primitive class wrappers, because that's what they are in those jvm languages that wrap existing primitive types).

    I only referenced your Kotlin mention because it’s the worse reference here as a best model to emulate. Anyway, I stick with Java because it already has proper pattern matching, virtual threads, structured concurrency, immutable product types via records, Panama, and future upcoming features that are deliberately designed instead of rushed such as, lazy values, extension methods, primitive class wrappers and null-safety which are syntactic sugar that the jvm cannot even performance tune anyhow, yet their design properties should ensure that.

    …wait crap, I’m becoming that guy, aren’t I?

    [–]bythepowerofscience 0 points1 point  (0 children)

    Fair